Is it possible to let a script execute when I load my simulation in Visual Components?
Currently I always have to open my script and execute it manually.
I could put the code in the “OnRun” event handler but then I would have to explicitly start the simulation and it would be executed at every run.
OK, so you have a component with a script, and when you load that component into the 3D world, the script does not execute when you run the simulation. Instead, you have to go to the script, recompile it, and then it works. Right?
- Unfortunately, that is a known issue. Are you importing any modules in your script besides vcScript?
I just found the “OnFinalize” event.
Why didn’t I see that earlier?
“Are you importing any modules in your script besides vcScript?”
Yes I use the Robot2 library from vcHelpers.
Anyway I will try it now with the “OnFinalize” event.
That should be the correct event right?
Yes, that can workaround the issue. There was a change made a few versions ago in which the main application auto-compiles scripts when loading. That potentially causes problems when the scripts are parsed and then compiled, but references to objects that do not yet exist in the layout/component can throw exceptions and make the script not work. Only after the component is loaded/finalized would the script function properly.
Case in point, if you are using vcHelpers.Robot2, then use the OnFinalize event to workaround some issues in declaring variables.