Detach component from path and attach it again

Hello,

I’m writing a Python Script to control a bucket conveyor where every bucket is independent.

After some testing I managed to detach the bucket from my path and attach it to the 3D world, but I cannot attach it back to my path and I don’t know what I’m doing wrong.

from vcScript import *
comp = getComponent()
app = getApplication()
sim = getSimulation()
toppath = comp.getBehaviour(“TopPath”)
sensor = comp.findBehaviour(“ComponentPathSensor”)
world_container = sim.World.getBehavioursByType(VC_CONTAINER)[0]
bucket = comp.ChildComponents[0]

def OnRun():

toppath.grab(bucket)
while app.Simulation.IsRunning == True:
triggerCondition(lambda: sensor.BoolSignal.Value==True)
part=sensor.ComponentSignal.Value
world_container.grab(part)
sim.update()
delay(1)
toppath.grab(bucket)
sim.update()

I did not wanted do use part.stopMovement() and path.Enabled because the ideal would be to use just one path and sometimes I need to stop just a bucket while the rest is moving and down the line I would have to stop many at a time.

Hello!
I think it might be a problem with your while loop, the fact that when you go back to the conveyor belt again from the 3D world, it’s still on the sensor, that is, when you grab it again, it triggers the “world_container .grab(part)”. Hope that solves your problem, have a nice day!

Hello Bad,

Indeed it was a problem with my loop. Thank you very much for the help!

1 Like

Hello!
Im currently running into the same headache, when attaching to the path, it retriggers my component sensor attaching it back to the container. how did you resolve this? :slight_smile:

Sorry, maybe I’m seeing this a bit late, this problem, is not quite the same in every simulation, it could be a problem with the logic of the capture, it could be the multiple triggering of the capture signal, all of these are not the same, if your problem still exists, you could be more specific, it’s just not that easy to fix it if you simply say so.