# How to restart the simulation

**URL:** <https://forum.visualcomponents.com/t/how-to-restart-the-simulation/2747>\
**Category:** Python Programming\
**Created:** [July 25, 2021, 10:10am UTC](https://forum.visualcomponents.com/t/how-to-restart-the-simulation/2747 "2021-07-25T10:10:03Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![mamba](https://forum.visualcomponents.com/letter_avatar_proxy/v4/letter/m/49beb7/32.png) [@mamba](https://forum.visualcomponents.com/u/mamba)\
**Post date:** [July 25, 2021, 10:10am UTC](https://forum.visualcomponents.com/t/how-to-restart-the-simulation/2747/1 "2021-07-25T10:10:03Z")

</div>

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!  
 ![image](https://forum.visualcomponents.com/uploads/default/original/2X/9/9d00b842df4aa2c5136750fd54031ac23d53ffb1.png)

 ![image](https://forum.visualcomponents.com/uploads/default/original/2X/9/9488341a197dee3d55e8bab7d84da1ee39cc375f.png)  
[Stop and Restartsimulation.vcmx](https://forum.visualcomponents.com/uploads/short-url/x2yKfn1WLMVBtnJiS9l26cog7ad.vcmx) (59.0 KB)

---

<div class="post-metadata">

**Author:** ![TSy](https://forum.visualcomponents.com/user_avatar/forum.visualcomponents.com/tsy/32/761_2.png) [@TSy](https://forum.visualcomponents.com/u/TSy)\
**Post date:** [July 25, 2021, 12:13pm UTC](https://forum.visualcomponents.com/t/how-to-restart-the-simulation/2747/2 "2021-07-25T12:13:53Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mamba](https://forum.visualcomponents.com/letter_avatar_proxy/v4/letter/m/49beb7/32.png) [@mamba](https://forum.visualcomponents.com/u/mamba)\
**Post date:** [July 25, 2021, 12:47pm UTC](https://forum.visualcomponents.com/t/how-to-restart-the-simulation/2747/3 "2021-07-25T12:47:05Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![captain\_feature](https://forum.visualcomponents.com/user_avatar/forum.visualcomponents.com/captain_feature/32/5547_2.png) [@captain\_feature](https://forum.visualcomponents.com/u/captain_feature)\
**Post date:** [July 25, 2021, 12:59pm UTC](https://forum.visualcomponents.com/t/how-to-restart-the-simulation/2747/4 "2021-07-25T12:59:36Z")

</div>

> [@mamba](#):
>
> Could you give me some suggestion

Hello,

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

Regards  
Feature

---

<div class="post-metadata">

**Author:** ![mamba](https://forum.visualcomponents.com/letter_avatar_proxy/v4/letter/m/49beb7/32.png) [@mamba](https://forum.visualcomponents.com/u/mamba)\
**Post date:** [July 25, 2021, 1:23pm UTC](https://forum.visualcomponents.com/t/how-to-restart-the-simulation/2747/5 "2021-07-25T13:23:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![captain\_feature](https://forum.visualcomponents.com/user_avatar/forum.visualcomponents.com/captain_feature/32/5547_2.png) [@captain\_feature](https://forum.visualcomponents.com/u/captain_feature)\
**Post date:** [July 26, 2021, 7:31am UTC](https://forum.visualcomponents.com/t/how-to-restart-the-simulation/2747/6 "2021-07-26T07:31:15Z")

</div>

> [@mamba](#):
>
> I’ve tried, but it’s still doesn’t work

Hy,

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…

Regards  
Feature

---

<div class="post-metadata">

**Author:** ![mamba](https://forum.visualcomponents.com/letter_avatar_proxy/v4/letter/m/49beb7/32.png) [@mamba](https://forum.visualcomponents.com/u/mamba)\
**Post date:** [July 26, 2021, 10:18am UTC](https://forum.visualcomponents.com/t/how-to-restart-the-simulation/2747/7 "2021-07-26T10:18:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![WilliamSmith](https://forum.visualcomponents.com/user_avatar/forum.visualcomponents.com/williamsmith/32/5471_2.png) [@WilliamSmith](https://forum.visualcomponents.com/u/WilliamSmith)\
**Post date:** [July 26, 2021, 11:10am UTC](https://forum.visualcomponents.com/t/how-to-restart-the-simulation/2747/8 "2021-07-26T11:10:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![TSy](https://forum.visualcomponents.com/user_avatar/forum.visualcomponents.com/tsy/32/761_2.png) [@TSy](https://forum.visualcomponents.com/u/TSy)\
**Post date:** [July 26, 2021, 1:39pm UTC](https://forum.visualcomponents.com/t/how-to-restart-the-simulation/2747/9 "2021-07-26T13:39:41Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mamba](https://forum.visualcomponents.com/letter_avatar_proxy/v4/letter/m/49beb7/32.png) [@mamba](https://forum.visualcomponents.com/u/mamba)\
**Post date:** [July 27, 2021, 2:11am UTC](https://forum.visualcomponents.com/t/how-to-restart-the-simulation/2747/10 "2021-07-27T02:11:51Z")

</div>

Thank you very much!  
I appreciate it！

---

<div class="post-metadata">

**Author:** ![mamba](https://forum.visualcomponents.com/letter_avatar_proxy/v4/letter/m/49beb7/32.png) [@mamba](https://forum.visualcomponents.com/u/mamba)\
**Post date:** [July 27, 2021, 2:12am UTC](https://forum.visualcomponents.com/t/how-to-restart-the-simulation/2747/11 "2021-07-27T02:12:14Z")

</div>

Thank you very much!

---

<div class="post-metadata">

**Author:** ![mamba](https://forum.visualcomponents.com/letter_avatar_proxy/v4/letter/m/49beb7/32.png) [@mamba](https://forum.visualcomponents.com/u/mamba)\
**Post date:** [July 27, 2021, 2:48am UTC](https://forum.visualcomponents.com/t/how-to-restart-the-simulation/2747/12 "2021-07-27T02:48:54Z")

</div>

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！
