# Access a view's child components using viewPath

**URL:** <https://forum.inductiveautomation.com/t/access-a-views-child-components-using-viewpath/84882>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [January 29, 2024, 11:33am UTC](https://forum.inductiveautomation.com/t/access-a-views-child-components-using-viewpath/84882 "2024-01-29T11:33:20Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![liam1](https://avatars.discourse-cdn.com/v4/letter/l/e68b1a/32.png) [@liam1](https://forum.inductiveautomation.com/u/liam1)\
**Post date:** [January 29, 2024, 11:33am UTC](https://forum.inductiveautomation.com/t/access-a-views-child-components-using-viewpath/84882/1 "2024-01-29T11:33:20Z")

</div>

Hi all,

I'm looking to develop a feature for filtering and highlighting assets, allowing users to easily search and locate them on a screen displaying a list of all assets.

The feature involves a screen where a 'viewPath' parameter is input, linking to an embedded view. I plan to use scripting to fetch the view objects using this 'viewPath', enabling access to all components within the embedded view. This approach will separate the code, allowing any generic view to be used.

It's similar to employing `self.parent.getChildren()` in a view to obtain all page components.

My question is: do I need to manually read the view's JSON file from the file system, or is there an existing system function that can perform this task?

---

<div class="post-metadata">

**Author:** ![liam1](https://avatars.discourse-cdn.com/v4/letter/l/e68b1a/32.png) [@liam1](https://forum.inductiveautomation.com/u/liam1)\
**Post date:** [January 29, 2024, 12:20pm UTC](https://forum.inductiveautomation.com/t/access-a-views-child-components-using-viewpath/84882/2 "2024-01-29T12:20:51Z")

</div>

Okay so after playing around , I ended up using using this.

```auto
viewPath=''

filePath = 'C:\Program Files\Inductive Automation\Ignition\data\projects\<ProjectName>\com.inductiveautomation.perspective\\views\{}'.format(viewPath.replace('/','\\'))
pageData=system.util.jsonDecode(system.file.readFileAsString(filePath))
return pageData

```

---

<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:** [January 29, 2024, 12:23pm UTC](https://forum.inductiveautomation.com/t/access-a-views-child-components-using-viewpath/84882/3 "2024-01-29T12:23:29Z")

</div>

This seems a bit dodgy. I'd be inclined to have the asset information in a database and generate the views from that, if possible.

---

<div class="post-metadata">

**Author:** ![liam1](https://avatars.discourse-cdn.com/v4/letter/l/e68b1a/32.png) [@liam1](https://forum.inductiveautomation.com/u/liam1)\
**Post date:** [January 29, 2024, 12:37pm UTC](https://forum.inductiveautomation.com/t/access-a-views-child-components-using-viewpath/84882/4 "2024-01-29T12:37:32Z")

</div>

Here is how it turned out.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [January 29, 2024, 4:54pm UTC](https://forum.inductiveautomation.com/t/access-a-views-child-components-using-viewpath/84882/5 "2024-01-29T16:54:33Z")

</div>

If you're going to do this, at least avoid the insane performance hit of calling into the local filesystem each time.

You could install [Ignition Extensions](https://forum.inductiveautomation.com/t/ignition-extensions-convenience-utilities-for-advanced-users/64615) (or search on this forum for access to the IgnitionGateway class, then retrieve the ProjectManager from it).

Once you've got a ProjectManager, you can [ask it for a given project by name](https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.36/com/inductiveautomation/ignition/gateway/project/ProjectManagerBase.html#getProject(java.lang.String)), which you can then ask for a specific resource [by ResourcePath](https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.36/com/inductiveautomation/ignition/common/project/RuntimeProject.html#getResource(com.inductiveautomation.ignition.common.project.resource.ResourcePath)). You then ask the resource for its data [under the `view.json` key](https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.36/com/inductiveautomation/ignition/common/project/resource/ProjectResource.html#getData(java.lang.String)).

This will all work off the in-memory representation of the project and should be dramatically faster than reading from the filesystem each time.

There's possibly also a better way to do this without the raw project resource involved at all, but it's also possible such a thing isn't actually exposed to you in scripting.

---

<div class="post-metadata">

**Author:** ![liam1](https://avatars.discourse-cdn.com/v4/letter/l/e68b1a/32.png) [@liam1](https://forum.inductiveautomation.com/u/liam1)\
**Post date:** [January 30, 2024, 6:56am UTC](https://forum.inductiveautomation.com/t/access-a-views-child-components-using-viewpath/84882/6 "2024-01-30T06:56:48Z")

</div>

Okay I tried what you suggested but got stuck, I there is no data returned on the resourceData Class Object.

```auto
from com.inductiveautomation.ignition.common.project.resource import ResourcePath,ResourceType
rtype=ResourceType('com.inductiveautomation.perspective','views')
resourcePathObject=ResourcePath(rtype,'1_Templates/3_UI/Alarms/highlight')
resourceData =system.project.getProject().getResource(resourcePathObject)
print resourceData.get().getData()

```

---

<div class="post-metadata">

**Author:** ![liam1](https://avatars.discourse-cdn.com/v4/letter/l/e68b1a/32.png) [@liam1](https://forum.inductiveautomation.com/u/liam1)\
**Post date:** [January 30, 2024, 7:10am UTC](https://forum.inductiveautomation.com/t/access-a-views-child-components-using-viewpath/84882/7 "2024-01-30T07:10:19Z")

</div>

Okay finally figured it out

```auto
	from com.inductiveautomation.ignition.common.project.resource import ResourcePath,ResourceType
	rtype=ResourceType('com.inductiveautomation.perspective','views')
	resourcePathObject=ResourcePath(rtype,value)
	resourceData =system.project.getProject().getResource(resourcePathObject)
	jsonString=resourceData.get().getData('view.json').tostring()
	return system.util.jsonDecode(jsonString)

```
