Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

LIMITATIONS ON ITEM.SETNAME() AND ITEM.SETVALUE()

#1
I have an application where it would be useful to store custom information with RoboDK's target objects. (The information is related to the state of the broader machine when it reaches a certain target.) This way, the information would persist across saves of the .rdk workstation rather than becoming unlinked from the robolink.Item handles associated with those targets when my robolink.Robolink() connection closes.

To this end, I have two questions:
1. Is the robolink.Item.setValue() method in active use right now? Or might I be able to co-opt it? If it's user-available, does it work like a Python dict? (Or would you be able to share other additional documentation for the function of .setValue()?)
2. What is the character limit for robolink.Item.Name()? (As a plan-B, I can dump the data I want into a string and store it in the target name.)

As a workaround, it's possible to store the target handle / target data link as pickled data in a file, but it makes it tricky and somewhat indeterminate if targets get modified in the workstation without Python's knowledge.
#2
You can store custom binary data by using item.setParam("parameter", bytevalue), and you can retrieve it by using item.getParam("parameter").

This feature was added for this purpose and at RoboDK we use it internally to create apps and new products.

Example:
Code:
mydata = b'custom byte array'
item.setParam("MyData", mydata) # Save binary data

# ... you can save, close your RDK file and open it again

mydata = item.getParam("MyData")
# mydata = b'custom byte array'
When you have custom data stored in items you can see what's stored by right clicking on the station and selecting Station Parameters (you'll see it at the bottom of the Constant parameters section). You can only read and edit this data by using the API. This data can be deleted if you select Clear all in this menu.

item.setParam has a different behavior when the second parameter is a string. More information here:
https://robodk.com/doc/en/PythonAPI/robo...m.getParam
#3
Thanks, Albert. That's exactly what I was looking for.
  




Users browsing this thread:
1 Guest(s)