Button property in custom process loose focus

I want to use a button in a custom process. This button works fine directly after the process is created. But if I add a second process or save and load a layout with the process, the button is not working anymore.

So I declare a global variable to store the button property.

When the process is created a method is assigned to the event
btnProp = stat.createProperty(VC_BUTTON, “Generate Path”)
btnProp.OnChanged = UpdatePath

def UpdatePath():

How to keep the button event always active?

Perhaps I need to add something in the process handler script for the robot?


You need to have a script in the component with something similar to the following:

comp = getComponent()

def UpdatePath(arg):
  pass #My code here

btnProp = comp.getProperty("Generate Path")
btnProp.OnChanged = UpdatePath

This should ensure that the event handler is connected to the button on changed event any time the component is loaded.


But the button property (btnProp) is linked to a statement not a component, where in the process handler can I get the statement?
It will look something like this:

Def OnSomeEvent(stat):

btnProp=stat.getProperty(“Generate Path”)
btnProp.OnChanged = UpdatePath


Try this code:

class BindArg:
    def __init__(self, met, arg1):
        self.method = met
        self.argument1 = arg1
    def OnInvoke(self, arg2):
        self.method(self.argument1, arg2)

def  OnGeneratePath(stat,prop):
     print(' generate path clicked')

prop_list = []

def  test(stat):
    global  prop_list
    prop1= stat.createProperty(VC_BUTTON, 'Generate Path)
    prop1.OnChanged = BindArg(OnGeneratePath, stat).OnInvoke

You can do like this also using OnStatementModified, which is fired when pressing the button:


def OnStatementModified(stat):
global btnProp

if btnProp==None:
  btnProp=stat.getProperty("Generate Path")
  if btnProp != None:
    btnProp.OnChanged = UpdatePath