Stop Simulation after collision detection

Hello,

I needed a help regarding creating python add-on in which the simulation should stop as soon as collision is detected. Currently, the collision is detected successfully but it does not stop the simulation. Also, the tolerance does not seem to work in the ‘detector.testAllCollisions()’. Following is the part of the code. I highly appreciate your help.

detector = sim.newCollisionDetector()

#Don’t include the cube as the object
detector.NodeListA = [(comp, VC_NODELIST_INCLUDE, VC_NODELIST_TREE)]
detector.NodeListB = [(block, VC_NODELIST_INCLUDE, VC_NODELIST_TREE)]

insideHit = detector.testAllCollisions(2.0)

print(insideHit)

def OnRun():

if insideHit:
app.stopSimulation()
print(‘Collision Detected’)

Why do you check for the collision outside OnRun, but then expect the simulation to stop immediately once the it’s started?

I tested your code, and after moving the testAllCollisions to be inside OnRun, it works.

I have to create a command on the action panel and not add the script to the component behaviour. I have created a action panel to create the block and then activate detector in the simulation. It’s like the same in the Kuka-Sim Add-on for restricting spaces. Can you help me with the necessary code…