PythonScript control robot


I use PythonScript to control a robot, the simulation works well.But when i reopen the layout it’s report errors as shown in the following figure.

At moment, I run Simulation the robot doesn’t work. But after I recompile the PythonScript_2 of the GenericRobot, the robot work Normal.

Anybody know why?

TestRobotPythonScriptinclude.vcmx (1.04 MB)

The getrobot gets called while the layout is still being loaded. Move the getrobot line inside the OnRun and it’ll work.

When the layout is loaded the components and their behaviours are being populated the scripts will get compiled at the moment they are populated. The script might be populated during the loading process before some other important object and that is why it is not a good idea to have certain things on the ‘global scope’ in the script.


I see.

Thank you very much.