How to restart the simulation

I want to stop the simulation at the red light, and restart the simulation the simulation at green light.
But i do not know why it no work? Could somebody give me a hand? Show in the picture and Vcam file.
Thanks in advance!

Stop and Restartsimulation.vcmx (59.0 KB)

Why would you want to start and stop the whole simulation? I think your approach to whatever problem you are trying to solve is wrong.

Because i am working on automation equipment simulation. So when the light turn red,i want to stop the simulation, and when the light turn green,i want to restart the simulation.
I am trying to make that happen.Could you give me some suggestion?Thanks in advanve.


I think you have to handle all in the OnRun-Method.


I’ve tried, but it’s still doesn’t work


what is your target as @TSy asked? → Maybe you need to use the .Net-Api because Python-script is more to handle things during the simulation…


I want to connect the boolsignal with real equiment.
OK, thank you very much!

The API allows you to start, stop, continue and reset the simulation. So there is a way to make an add-on that can do batches and experiments.

.NET API has a simulation service is meant for app development. Python API has simulation, property and signal events and is meant for component scripting and add-ons with some limitations.

in vcScript, OnRun is the main loop, so you can do time consuming calls there. OnStart and OnStop are not meant for while loops. You need to avoid recursions and conflicting logic in the script. You can use property change event or signal change event to trigger something, such as start, stop and resume of simulation using HMI feedback, e.g. operator presses button.

So after stopping the simulation in 3D world, you want some listener for green light value change in the component to reset the simulation to zero time and then start the simulation again? From your script, it looks like you want to resume/continue the simulation not reset it.

And one thing to note is the suspendRun() and resumeRun() calls in vcScript, which can start and stop the OnRun() execution loop for that Python Script. That can be used, for example, to stop machine during simulation without stopping everything else including the simulation.

Note that signals only work when simulation is running, so you won’t receive any signal events when simulation is reset or paused.

Also note that the Connectivity feature only reads and writes values when simulation is running, not when it is paused or reset.

So unless you are using your own communication implementation and properties instead of signals, starting and stopping the simulation is likely just not going to work. You’ll need to implement any pausing, resuming and resetting logic within your component such that the simulation itself can keep running.

Thank you very much!
I appreciate it!

Thank you very much!

And because the whole simulation have many VCScript, so if use suspendRun() and resumeRun() Event. Can’t meet my needs.
I will try and thank you!