Get multiple components with same name

Hey there experts!

I am trying to unify the logic of many conveyors of my simulation that do the exact same thing, so instead of having e.g. 100 conveyors, each one with its own script, I have the logic gathered in one script only. To do so, I suppose I have to get each of the conveyors with a for loop, and same thing for the properties/behaviours of each component.
However, I’m still quite new to VC python programming so I don’t know how to write it.

I was trying something like this:

from vcScript import *
import vcMatrix

app = getApplication()
sim = app.Simulation
for i in range(100):
props[i]=comp.getProperty(‘Physics::Physics Type’)

Thanks in advance.

for component in app.Components:
  if "Conveyor" in component.Name:
    do something
1 Like

Hi @chungmin,

Thanks for your answer, I see how that would work. Now then, to access properties and behaviours of each of those components how could I do? For example, for the path behaviour of each component: paths[i]=blocks.findBehaviour(‘PhysicsPath’)

Thanks once again.

No need to find out every behavior or property for all component, because they are all conveyor, simply findbehavior(sameBehaviorName) or getProperty(samePropertyName)

But I do need to be stop or activate the path of a specific conveyor when the corresponding signal triggers. Therefore, I should find the behaviours and properties right?

Ok, now I see your point.
You should let every conveyor monitors their own sensor.
Check this video.

Yeah I guess that’s simpler. I did it that way but since there are many conveyors and I’m simulating with physics, the performance is downgraded a lot. That’s why I thought that maybe by having the logic in one script instead of 200, the performance would improve.

Cool, interesting, could you upload the file you have done? Would like to see what makes it slow.

Thanks for your offering @chungmin but I’m afraid I’m not allowed to upload anything. I’m certain that the performance is due to various factors like using physics, a heavy CAD model (+5M triangles), these scripts…