I am trying to generate a valid tag path for the tagPaths parameter of system.tag.readBlocking function. The tag path I want to use is [Default]AI_LT1.
The path does work If I generate the string in the following way
path = "[Default]AI_LT1"
result = system.tag.readBlocking(path)
However, if I tended to generate the same path by combining one variable that contains a pre-defined value with a string component, the path is invalid then. There is the example code:
In this case, tag_trimmed is equal to [Default] and will display [Default]AI_LT1 if print (path). However, it fails to read the proper tag content as what I type in the path = ''[Default]AI_LT1" directly.
I tried some initial troubleshooting by using str (path) or .encode('utf-8') to return a string or unicode datatype but no luck.
Can you show us the text contained in self.props.selection.active.data[0]['displayPath'] ? It is a little hard to follow what you are trying to achieve here.
Add print type(tag_trimmed) to see if it is actually the type that you are expecting. Also try print type(path) to confirm its a string.
system.tag.readBlocking expects a list of tag paths. It allows you to pass a single string to avoid breaking projects from older versions that got upgraded. It might not like something about how you are constructing the string, so try using result = system.tag.readBlocking([path])
Also consider using java's string formatting to generate the path, ie: path = "%sAI_LT1" % tag_trimmed
Thanks for the rely!Tthe text contained in `self.props.selection.active.data[0]['displayPath'] is a PyUnicode with text [Default] - Alarm/Hi/Alarm:/alm:Alarm. After trimming, tag_trimmed is then equal to [Default].
Hello Ryan, thanks for the reply! the data type of path was PyUnicode. I tried use str(path) which supposes to return a PyString data type but still doesn't work. I will try the rest methods you mentioned later the.
By applying either of your solutions @David_Stone@ryan.white and removing the space in between, the path is working properly now. Really appreciate the help!