Is there a better way to add a simple property (such as boolean, string, or integer) to a path statement?
I tried using a Python Script for a robot behavior and my boolean checkbox appears. However, I have to recompile my code after every new path statement. I just wanted to see if I could execute this code on the creation of every new path statement automatically? I tried creating a command, but that didn’t seem to work either. I know my code isn’t the cleanest. I’m just starting out in Python, so any suggestions would be welcome.
from vcScript import *
from vcApplication import *
app = getApplication()
comp = getComponent()
executor = comp.findBehaviour("Executor")
routine = executor.Program.MainRoutine
statement = routine.Statements[-1]
currentLen = len(routine.Statements)-1
if statement.Type == VC_STATEMENT_PTPMOTION:
if currentLen != len(routine.Statements):
statement.createProperty(VC_BOOLEAN, "checkbox")
If you want this behaviour to be active all the time, then I recommend implementing it as a command.
The .NET API might have more sophisticated tools for such. Since we are now talking about python, you could try using the vcScope.OnStatementAdded event. When a new statement is added to your robot program, this event will trigger and you could then add a new property to that statement in the event handler.
Thank you Este. I tried adding a “command” under my commands for adding a property. It seems like the python script is not being read when I open up the program editor. I can add the script under the robot as a behavior, but not as a command. I’m not sure how to get the command to execute.