# Tree Component Selected Path Value

**URL:** <https://forum.inductiveautomation.com/t/tree-component-selected-path-value/94264>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [August 6, 2024, 9:42pm UTC](https://forum.inductiveautomation.com/t/tree-component-selected-path-value/94264 "2024-08-06T21:42:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dee\_Duncan](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dee_duncan/32/31786_2.png) [@Dee\_Duncan](https://forum.inductiveautomation.com/u/Dee_Duncan)\
**Post date:** [August 6, 2024, 9:42pm UTC](https://forum.inductiveautomation.com/t/tree-component-selected-path-value/94264/1 "2024-08-06T21:42:57Z")

</div>

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.  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/2/e2a67dcc7145acd4a70ede274876534bbfa37d7e.png)  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/4/9475e8c9bcd44906e224609a10e67f20b1529eac.png)

---

<div class="post-metadata">

**Author:** ![Matthew\_Dominguez](https://avatars.discourse-cdn.com/v4/letter/m/ba9def/32.png) [@Matthew\_Dominguez](https://forum.inductiveautomation.com/u/Matthew_Dominguez)\
**Post date:** [August 6, 2024, 10:05pm UTC](https://forum.inductiveautomation.com/t/tree-component-selected-path-value/94264/2 "2024-08-06T22:05:55Z")

</div>

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](https://www.docs.inductiveautomation.com/docs/8.1/platform/tags/tag-properties):

> 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:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/e/aea4ecc5a6e618be5b2f8dfe63df4bebf397de5e.png)

The `value` object holds the actual string representation of the node.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [August 6, 2024, 10:08pm UTC](https://forum.inductiveautomation.com/t/tree-component-selected-path-value/94264/3 "2024-08-06T22:08:02Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Dee\_Duncan](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dee_duncan/32/31786_2.png) [@Dee\_Duncan](https://forum.inductiveautomation.com/u/Dee_Duncan)\
**Post date:** [August 6, 2024, 10:10pm UTC](https://forum.inductiveautomation.com/t/tree-component-selected-path-value/94264/4 "2024-08-06T22:10:32Z")

</div>

It does not look like it is the selection path, it is the value of the selected item

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/3/e371df82a95b40e849ec2e4ca92a9797af4f41d2.png)

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [August 6, 2024, 10:32pm UTC](https://forum.inductiveautomation.com/t/tree-component-selected-path-value/94264/5 "2024-08-06T22:32:25Z")

</div>

Try this:

 ![Items path](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/c/ecb999db790de79437fad4092e04f510985ceb79.png)

> **Script**
>
> ```python
> 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.

---

<div class="post-metadata">

**Author:** ![Dee\_Duncan](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dee_duncan/32/31786_2.png) [@Dee\_Duncan](https://forum.inductiveautomation.com/u/Dee_Duncan)\
**Post date:** [August 7, 2024, 1:40pm UTC](https://forum.inductiveautomation.com/t/tree-component-selected-path-value/94264/6 "2024-08-07T13:40:36Z")

</div>

That worked perfectly, thank you!
