Command Not Recognized During Teaching in Program

Just wondering if anyone can help me understand why my command is not recognized while I’m programming path statements. This code works as a Python robot behavior, but not as a “command”. I would like to run this code while I’m creating a new PTP statement to add a checkbox. 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.

Here is the code I used…

app = getApplication()   

def my_event_handler(statement):
  if statement.Type == VC_STATEMENT_PTPMOTION: 
      statement.createProperty(VC_BOOLEAN, "checkbox")

if app.TeachContext != None and \
            app.TeachContext.ActiveRobot != None:
            robotdata = getSelectedRobotsData()
            executor = robotdata[0]
            routine = executor.Program.MainRoutine
            routine.OnStatementAdded = my_event_handler

With Python Behavior

Without Python Behavior

Hi @clagos

You need to ensure that you also register the addon so that the application knows it exists. Just adding a script to the My Commands folder is not enough. For this, you will need to create init.py file.

I made a quick test. Please see the attached file.
More information on this is available in the help documentation under Creating a Python Add-on.
Example Addon.zip (919 Bytes)

Thank you Este! I do have the init.py file, but my launcher didn’t work. I think my issue I was having was leaving out the selection handler that you added. Your code worked and I appreciate your help!

image

1 Like