# Programmatically expand nodes in tag browse tree

**URL:** <https://forum.inductiveautomation.com/t/programmatically-expand-nodes-in-tag-browse-tree/73169>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [May 2, 2023, 9:53pm UTC](https://forum.inductiveautomation.com/t/programmatically-expand-nodes-in-tag-browse-tree/73169 "2023-05-02T21:53:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sala\_Tiemann](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@Sala\_Tiemann](https://forum.inductiveautomation.com/u/Sala_Tiemann)\
**Post date:** [May 2, 2023, 9:53pm UTC](https://forum.inductiveautomation.com/t/programmatically-expand-nodes-in-tag-browse-tree/73169/1 "2023-05-02T21:53:14Z")

</div>

Hello, I'm working with a tag browse tree in Perspective and I was wondering if there was a way to programmatically expand the nodes without needing a user to click on a folder. I.e. is there a way to identify a node by name or path and then write `node.expand()` in an event script such that the node's children are visible? Thank you!

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [May 3, 2023, 12:59am UTC](https://forum.inductiveautomation.com/t/programmatically-expand-nodes-in-tag-browse-tree/73169/2 "2023-05-03T00:59:46Z")

</div>

Yes; identifying and programatically expanding nodes is possible.

Here is an example script that programatically opens all Item nodes and subNodes named Child 1 when the parents are named Item:

```auto
def runAction(self, event):
	nodes = self.getSibling("Tree").props.items
	def expandNodes(node):
		if 'Item' in node.label and len(node.label) == 6:
			node.expanded = True
		elif node.label == 'Child 1':
			node.expanded = True
		for subNode in node.items:
			expandNodes(subNode)
	for node in nodes:
		expandNodes(node)

```

**Before button press:**  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/e/3e3dd70e06419d9e93ef2d749ae1212855e48765.png)

**After button press:**  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/e/feb353c6945b115af211dcb314d6131ba5128b3c.png)

Every sub prop has a label and string data that can identify it, and the setting the expanded bool to True will expand the node.

---

<div class="post-metadata">

**Author:** ![Sala\_Tiemann](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@Sala\_Tiemann](https://forum.inductiveautomation.com/u/Sala_Tiemann)\
**Post date:** [May 26, 2023, 6:35pm UTC](https://forum.inductiveautomation.com/t/programmatically-expand-nodes-in-tag-browse-tree/73169/3 "2023-05-26T18:35:17Z")

</div>

Hi @justinedwards.jle , thanks so much for your response!

I'm trying to implement your solution in my project and have run into a few things. First, it appears that `self.props.items` is an instance method on the tag browse tree and writing `nodes = self.props.items()` will return the object

> [(u'root', {u'path': u'[default]import'}), (u'selection', {u'mode': u'multiple', u'values': [u'[default]import/flow indicators']}), (u'display', {u'refreshIcon': {u'path': u'material/search', u'visible': False, u'style': {u'classes': u''}}}), (u'style', {u'marginRight': -2L, u'classes': u''})]

I'm not sure the exact class of object this is but is not a list of nodes but rather the properties of the tag browse tree. Do you know of an alternate method of retrieving the list of nodes? Also, how do you know that node objects have the property `expanded`? I'm trying to find documentation on it but I can't, so if you have any links or information that would be super helpful!

Thank you again!

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [May 27, 2023, 9:33am UTC](https://forum.inductiveautomation.com/t/programmatically-expand-nodes-in-tag-browse-tree/73169/4 "2023-05-27T09:33:48Z")

</div>

I believe Justin mixed things up and thought you were using a simple tree, not a tag browse tree.

The `items` method has nothing to do with the actual items in the tree, it's an equivalent of the `dict`'s `items` method that returns its keys and values.

I'm not sure you can actually access an 'expanded' property of the tag browse tree's nodes...

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [May 27, 2023, 10:10am UTC](https://forum.inductiveautomation.com/t/programmatically-expand-nodes-in-tag-browse-tree/73169/5 "2023-05-27T10:10:17Z")

</div>

> [@pascal.fragnoud](#):
>
> Justin mixed things up and thought you were using a simple tree, not a tag browse tree.

Confirmed 👍

---

<div class="post-metadata">

**Author:** ![Sala\_Tiemann](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@Sala\_Tiemann](https://forum.inductiveautomation.com/u/Sala_Tiemann)\
**Post date:** [May 30, 2023, 5:41pm UTC](https://forum.inductiveautomation.com/t/programmatically-expand-nodes-in-tag-browse-tree/73169/6 "2023-05-30T17:41:53Z")

</div>

No worries, I will investigate if using a simple tree works in my implementation! Thanks for your help!
