Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to retrieve two targets with the same name?
#1
How can two targets with the same name be retrieved as separate items via the API?

I know I can retrieve a target item via its name 'tar01':


Code:
item = RDK.Item('tar01',ITEM_TYPE_TARGET)


But suppose I have two different targets in the station tree with the same name, 'tar01', which could be linked to a different robot in the same station. How can I retrieve both as separate items?

Best regards,

Maarten
#2
Having multiple targets with the same name is not a good premise.
You are kind of asking for trouble.

But anyway.

You can retrieve all the items in your station with ItemList. https://robodk.com/doc/en/PythonAPI/robo...k.ItemList
Then you can iterate through the items and look for all the ITEM_TYPE_TARGET is name "Your_Name".

You can then retrieve the robot linked to the target with ".getLink()" https://robodk.com/doc/en/PythonAPI/robo...em.getLink

Jeremy
Find useful information about RoboDK and its features by visiting our Online Documentation and by watching tutorials on our Youtube Channel


#3
Thanks Jeremy, using ItemList() will work for me!

I understand it's recommended to avoid two targets with the same name, but it is a plausible situation I can see occurring e.g. when copy-pasting in a station. In fact I could now use ItemList() to check for double use of the same name for any item and issue a warning or automatically apply some changes.

Thanks again,

Maarten
  




Users browsing this thread:
1 Guest(s)