Activating Button Property using python API

hi…
I am trying to access the button property of an Robot transport controller component using the python API.To be precise I want to activate it using the python API but unable to do so.

Any help is appreciated

image

You can try read its value as integer and assign a different value. So if the value is 0 assign 1 and vice versa.

hi…I did it as you told but still I am unable to activate the button

Hi,

Could you elaborate a bit further on this one? Do you want to “click” the button, but instead of physically clicking it, you would like to click it using python API?

br,
Lefa

Hi…yes that is exactly what i wanted to do.Instead of clicking the button manually I want to do it using the python API

Hi,

Well, you can definitely do that, but you would then somewhat do… redundant work and also somewhat miss the point of events. The button is practically tied to an event like this:

...
comp = getComponent()
button = comp.getProperty('MyButton')


def button_event(parameter):
    print "button pressed!"


button.OnChanged = button_event  #tying a button click event to a custom function

As you can notice, the event is a normal function that just happens when someone presses the button, nothing prevents you from calling the said button though with, let’s say OnReset or OnRun

def OnReset():
    print "someone pressed reset!"
    button_event(button)

def OnRun():
    print "Simulation is now running"
    button_event(button)
    print "button event, manually called"

Regardless what do you want to do, was this what you asked?

br,
Lefa

1 Like

Hi Lefa,

Thankyou very much for the detailed explanation.

I actually wanted to connect the interfaces between a mobile transport controller and AGVs by accessing the interface option in the home tab with the help of python API but i was not able to do so.

Then I decided to try an alternative of connecting the resources with the controller by directly accessing the buttons “Connect All Resources” and “Connect All Idle And Charging Locations”. using the pythonAPI which I failed to do. Thus I placed my query in the forum.

Right now, since it is an eCatalog component with built-*in behaviours.Is there a way to execute those functions associated with the buttons to get the desired result.

thankyou and regards,
Raghu

Hi,

This makes more sense now, please check the attached layout.
The code is inside Block Geo (not Block Geo #2) and what happens here is that the first block will search for another block and then its interface. Then we can use the interface methods to connect. Do keep in mind that the GUI doesn’t update on the fly while you connect and disconnect via the Python API, meaning that if you have the interface editor open and your python API disconnects the interface while it is open, you do not actually see it updating and you have to close the interface editor and reopen.

Accessing the interfaces tab itself is via .NET API as far as I understand, but if you just want to connect or disconnect interfaces to each other, I would recommend to use Python API.

br,
Lefa
iface_python_api.vcmx (32.2 KB)

1 Like

Thank you very much.It works