I have a UDT that I'm reading all members of via system.tag.readBlocking().
I have a handful of tags with custom number properties that I've added ("i", "j").
When I read the entire UDT I don't have access to these properties. I am reading about 20 of these UDTs at a time. What's the best/most efficient way to go about getting these custom property values for each UDT?
First thing that comes to mind is to add a string member to the UDT that just contains the UDT's full path and use that to create the path to all of the custom properties and use a call to system.tag.readBlocking() to get these values for each UDT.
What do you mean by 'reading all members of'? How are you constructing the list of paths that comprise the UDT already?
I don't know if it will include the custom properties, but try reading path/to/tag.jsonValues - it'll return a document that describes all the sub-members of the UDT and their values.
I have the path to the UDT instance and I use system.tag.readBlocking() to read all of the tag values within the instance. I get a dictionary of values that I then parse out in Python. However, I also need the values of the custom props.
The only path in that list is the path to the root node of the UDT instance. I could but that would break my use of the function that I'm using to return a specific subset of the UDT instance values.
In any case,
Luckily, I had already built a function getIJmemberPaths() in my scripting library, so I can just use that and then combine them into a dict. Might not be the most efficient, but at least I'm only calling readBlocking once and the function is already built.
def getIJmemberVals(path):
'''
Get a dictionary of values for UDT IK=J members for the supplied UDT instance
Args:
path (string) : path to the UDT instance root node
Returns:
{path:val} (dict) : dictionary of paths and values for UDT IJ members
'''
ijPaths = getIJmemberPaths(path)
ijVals = [qv.value for qv in system.tag.readBlocking(ijPaths)]
return {ijPath.rsplit('/',1)[-1] : ijVal for ijPath, ijVal in zip(ijPaths, ijVals) if ijVal != -1}
So, is this function returning a hardcoded list? I feel like we're talking past each other. Where, in code, is "list of paths under UDT at $path" defined?
There's probably some internal node you can read that returns all the custom properties under a given path, but a quick search through the highly abstract tag code didn't reveal it to me. I would say the simplest, most pragmatic thing to do would be to add optional parameter(s) to your getIJmemberVals function that allows you to pass in 'extra' member paths to read, so you can just call getIJmemberVals("path/to/tag", customProperties = ["i", "j"]) or something similar.