Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched.
Close
I have one given project, which keeps 3 applications for 3 different plc-types. ( I have no influence to this project structure, so I can not change it)
For downloading them by script I am guessing I have to change the active application. How can I get to the application to set active?
Or how can I change the active application at all?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2012-12-12
Originally created by: M.Schaber
Hi,
Projects have a property active_application, which you can use to query or set the active application.
Is there an easy way to detect the right application via parents property? Something like app.parent.parent ?
print("findApplicationResult.Count ", findApplicationResult.Count)forfarinfindApplicationResult:
  appPlcFound=far.parent.parent.find("PLC_A", False)
  print("appPlcFound.Count ", appPlcFound.Count)
  ifappPlcFound.Count>0:
    print("appPlcFound")
    proj.active_application=appPlcFound[1]
    break
Does not work, appPlcFound.Count = 0 three times. I am also not so much into Python so I am just guessing and trying...
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2012-12-12
Originally created by: M.Schaber
Hi, ALoeffler,
There are several possibilities to solve your problem: The first one is to search from the device upwards:
forfarinfindApplicationResult:
  iffar.parent.parent.get_name()=='PLC_A':
    # dosomethinghere...
In your code, the problem was the following line:
Zitat:
   appPlcFound=far.parent.parent.find("PLC_A",False)
Here, you're going down 2 steps from the application object (far.parent.parent points to the device in your project), and then you search for a child of that device with the name "PLC_A" non-recursively, which none exists.
Note that the find() methods always return a list of objects, because each search could return more than one result.
HTH,
Markus
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thank you Markus!
Your first solution runs perfect.
Now the next problem is knocking on the door To create the gateway and set the device active.
But if I need help I'll open a new thread with a fitting topic.
Alfred
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have one given project, which keeps 3 applications for 3 different plc-types. ( I have no influence to this project structure, so I can not change it)
For downloading them by script I am guessing I have to change the active application. How can I get to the application to set active?
Or how can I change the active application at all?
Originally created by: M.Schaber
Hi,
Projects have a property active_application, which you can use to query or set the active application.
Hi, thanks for this quick answer!
Unfortunatelly I found 3 appplication objects. The given project structure:
Project-PLC_A--SPS-Logik---Application-PLC_B--SPS-Logik---Application-PLC_C--SPS-Logik---Application
Is there an easy way to detect the right application via parents property? Something like app.parent.parent ?
Does not work, appPlcFound.Count = 0 three times. I am also not so much into Python so I am just guessing and trying...
Originally created by: M.Schaber
Hi, ALoeffler,
There are several possibilities to solve your problem: The first one is to search from the device upwards:
The second one is to search the application by path:
A third way is to check the name of the parent:
In your code, the problem was the following line:
Here, you're going down 2 steps from the application object (far.parent.parent points to the device in your project), and then you search for a child of that device with the name "PLC_A" non-recursively, which none exists.
Note that the find() methods always return a list of objects, because each search could return more than one result.
HTH,
Markus
Thank you Markus!
Your first solution runs perfect.
Now the next problem is knocking on the door To create the gateway and set the device active.
But if I need help I'll open a new thread with a fitting topic.
Alfred