When using a perspective tree component, the selected value comes in as '0/0/0'. Rather than the index path, is there a way to get the string path instead? For example '0/0/0' is the equivalent of 'Item 1/Child1/Grandchild1'. I want to do this because i am trying to build tag paths.
Is the string value not in the value
object within the selectionData
array? It should be right below the itemPath
, just below where your screenshot is cut off.
Per the Ignition Docs for the selectionData:
Array of objects containing the data and index path for all currently selected nodes.
- itemPath: Index path. Value is numeric.
- value: The value of the 'data' property for the selected node. Value is string.
This is what it looks like in my designer:
The value
object holds the actual string representation of the node.
OP wants a string in the form,
Item 1/Child 1/Grandchild 2
for selection.0 : 0/0/1
.
i.e., Join all the values down to the selected node with a '/'.
I suspect it will need a script transform and some recursion.
Try this:
Script
def transform(self, value, quality, timestamp):
indexes = value.selection.split('/')
itemPath = []
currentItems = value.items
for i in indexes:
i = int(i)
itemPath.append(currentItems[i].label)
currentItems = currentItems[i].items
return '/'.join(itemPath)
One of the Python guys should be able to reduce this to a couple of lines but this should give you something to work with in the meantime.
That worked perfectly, thank you!