# Automatically creating Perspective Navigation

**URL:** <https://forum.inductiveautomation.com/t/automatically-creating-perspective-navigation/24338>\
**Category:** Ignition Early Access\
**Tags:** python, ignition80, scripting\
**Created:** [April 23, 2019, 7:48pm UTC](https://forum.inductiveautomation.com/t/automatically-creating-perspective-navigation/24338 "2019-04-23T19:48:03Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matthew.gaitan](https://avatars.discourse-cdn.com/v4/letter/m/59ef9b/32.png) [@Matthew.gaitan](https://forum.inductiveautomation.com/u/Matthew.gaitan)\
**Post date:** [April 23, 2019, 7:48pm UTC](https://forum.inductiveautomation.com/t/automatically-creating-perspective-navigation/24338/1 "2019-04-23T19:48:03Z")

</div>

Hi there,

Been having a lot of fun playing around with Ignition 8 and the new Perspective module!

I’ve been working on automatically creating all of the navigation based on the current folder structure setup in the project. If I add a new Folder or View, I want that to automatically be created in my NavTree and linked properly in the Page Configuration.

I have it working, but find myself wondering if there are some built in functions that can make it easier and more intuitive.

Currently, I’m using the python os library to determine which files and folders are present on the gateway under the perspective views folder and using that information I’m creating a item dict and writing that to a tag that is linked to via an expression binding on the NavTree.

I am then building a json string and writing it to the page-config json file to link up the navigation.

I have 2 questions:

1. Is it possible to, using some undocumented function, get a list of all perspective views (including their path) in the current project? Akin to system.gui.getWindowNames() in Vision?
2. Is it possible to programatically alter the Page Configuration without modifying the page-config/config.json stored on the filesystem?

Thanks for your time!

---

<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:** [April 23, 2019, 8:10pm UTC](https://forum.inductiveautomation.com/t/automatically-creating-perspective-navigation/24338/2 "2019-04-23T20:10:56Z")

</div>

No to both questions - but we do have plans to add similar “reflective” operations to Perspective as there are in vision, ie system.perspective.getMountedViews (or something like that). Exactly what that looks like, we’re not sure yet.

Once that’s possible, you should be able to use a binding on a navigation component to construct your views - no hacking into the resource directory required.

---

<div class="post-metadata">

**Author:** ![Matthew.gaitan](https://avatars.discourse-cdn.com/v4/letter/m/59ef9b/32.png) [@Matthew.gaitan](https://forum.inductiveautomation.com/u/Matthew.gaitan)\
**Post date:** [April 23, 2019, 8:14pm UTC](https://forum.inductiveautomation.com/t/automatically-creating-perspective-navigation/24338/3 "2019-04-23T20:14:17Z")

</div>

Awesome, glad to hear you’re planning on adding those features.

I will use my current code and wait patiently for these features to be added 😃

Thank you for the reply!

---

<div class="post-metadata">

**Author:** ![iamthebull](https://avatars.discourse-cdn.com/v4/letter/i/58f4c7/32.png) [@iamthebull](https://forum.inductiveautomation.com/u/iamthebull)\
**Post date:** [December 4, 2020, 11:06pm UTC](https://forum.inductiveautomation.com/t/automatically-creating-perspective-navigation/24338/4 "2020-12-04T23:06:29Z")

</div>

Any idea on when this will be added?

---

<div class="post-metadata">

**Author:** ![mwillenbring1](https://avatars.discourse-cdn.com/v4/letter/m/fbc32d/32.png) [@mwillenbring1](https://forum.inductiveautomation.com/u/mwillenbring1)\
**Post date:** [January 28, 2021, 3:34am UTC](https://forum.inductiveautomation.com/t/automatically-creating-perspective-navigation/24338/5 "2021-01-28T03:34:13Z")

</div>

I want to 2nd this idea! any word on when the above mentioned feature set may be added?

---

<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 28, 2021, 4:54pm UTC](https://forum.inductiveautomation.com/t/automatically-creating-perspective-navigation/24338/6 "2021-01-28T16:54:13Z")

</div>

No timeline, but I did just do what I could to escalate the existing ticket.

---

<div class="post-metadata">

**Author:** ![Carl.Gould](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/carl.gould/32/7262_2.png) [@Carl.Gould](https://forum.inductiveautomation.com/u/Carl.Gould)\
**Post date:** [February 18, 2021, 5:17pm UTC](https://forum.inductiveautomation.com/t/automatically-creating-perspective-navigation/24338/7 "2021-02-18T17:17:38Z")

</div>

Ok, here’s my take on how to tackle this. Rather than add a scripting function, instead, I’d like to inject information about the current project into session props. I’m thinking an object at `session.props.project` that would be shaped like this:

```json
{
  name: string,
  title: string,
  description: string,
  lastModified: date,
  lastModifiedBy: string,
  views: array< { path: string} >,
  pageConfigs: array< { url: string, primaryView: string } >
}

```

It’s a bit odd to have “views” be an array of objects with only one attribute in them, but I figure that way it’ll be more flexible in the future if we want to add more information in about each view.

Thoughts?

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [February 18, 2021, 5:54pm UTC](https://forum.inductiveautomation.com/t/automatically-creating-perspective-navigation/24338/8 "2021-02-18T17:54:53Z")

</div>

Would this poll, or it it static on Session Startup? Who gets listed under lastModifiedBy if I delete a View folder on the file system without going through the Designer? This is all read-only (system-level security), correct? I can’t write a new pageConfig entry on-the-fly?

---

<div class="post-metadata">

**Author:** ![Matthew.gaitan](https://avatars.discourse-cdn.com/v4/letter/m/59ef9b/32.png) [@Matthew.gaitan](https://forum.inductiveautomation.com/u/Matthew.gaitan)\
**Post date:** [February 18, 2021, 6:14pm UTC](https://forum.inductiveautomation.com/t/automatically-creating-perspective-navigation/24338/9 "2021-02-18T18:14:15Z")

</div>

I’d be fine with that, really any mechanism inside Ignition to get the list of views that exist within a project works for me.

I currently have a script that runs whenever I save a project that checks the file system to find any newly added / removed views in project and stores them in a tag.

Having it built in means one less custom script I need to manage!

---

<div class="post-metadata">

**Author:** ![Carl.Gould](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/carl.gould/32/7262_2.png) [@Carl.Gould](https://forum.inductiveautomation.com/u/Carl.Gould)\
**Post date:** [February 18, 2021, 6:46pm UTC](https://forum.inductiveautomation.com/t/automatically-creating-perspective-navigation/24338/10 "2021-02-18T18:46:48Z")

</div>

> Would this poll, or it it static on Session Startup?

It would be updated on-demand as the project is changed.

> Who gets listed under lastModifiedBy if I delete a View folder on the file system without going through the Designer?

"external"

> This is all read-only (system-level security), correct?

Yes

> I can’t write a new pageConfig entry on-the-fly?

No

---

<div class="post-metadata">

**Author:** ![Carl.Gould](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/carl.gould/32/7262_2.png) [@Carl.Gould](https://forum.inductiveautomation.com/u/Carl.Gould)\
**Post date:** [February 22, 2021, 4:32pm UTC](https://forum.inductiveautomation.com/t/automatically-creating-perspective-navigation/24338/11 "2021-02-22T16:32:39Z")

</div>

We ended up implementing this as a scripting call after all. The json shape I indicated above will be returned from `session.getProjectInfo()` and `system.perspective.getProjectInfo()` as of 8.1.4

---

<div class="post-metadata">

**Author:** ![matthew.gollasch](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/matthew.gollasch/32/26382_2.png) [@matthew.gollasch](https://forum.inductiveautomation.com/u/matthew.gollasch)\
**Post date:** [December 21, 2021, 1:24am UTC](https://forum.inductiveautomation.com/t/automatically-creating-perspective-navigation/24338/12 "2021-12-21T01:24:17Z")

</div>

I’d like to use this getProjectInfo() function to retrieve the pageConfigs and automatically construct my Menu Tree navigation. However, there are a few drawbacks/limitations that have prevented me:

- My project uses different icons in the Menu Tree for different pages. There doesn’t seem to be any way to define parameters like this in the Page Configuration that can then be retrieved by getProjectInfo().  
(viewParams can be configured for individual docked views, but not for individual primary views. Furthermore, the getProjectInfo() function doesn’t return the details of the docked views configured for each primary view.)

- There seems to be no way to re-order pages in a Page Configuration. If I want to reorder items in my automatically generated Menu Tree navigation, I need to rebuild the Page Configuration from scratch.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [December 21, 2021, 4:44pm UTC](https://forum.inductiveautomation.com/t/automatically-creating-perspective-navigation/24338/13 "2021-12-21T16:44:24Z")

</div>

> [@matthew.gollasch](#):
>
> There doesn’t seem to be any way to define parameters like this in the Page Configuration that can then be retrieved by getProjectInfo()

Correct, there is no way to configure icons as part of the page definition, because pages don't have icons - they're entirely a concept of the Menu Tree. What you could do is provide logic to determine icons within your script. this would require you to maintain a dictionary system of page:icon listings.

The following script is for very basic structures. It could get very complicated depending on the nesting of your pages within the menu tree.

```auto
configs = system.perspective.getProjectInfo().pageConfigs
tree_items = []
icon_map = {
    "Home": "material/home",
    "Time": "material/access_time",
}
for config in configs:
    item = {}
    item['target'] = config.url
    item['label'] = config.primaryView.split("/")[-1]
    # default icon to navigation icon if no special icon is mapped
    item['navIcon']['path'] = icon_map.get(item['label'], "material/navigate")
    tree_items.append(item)
# I'm not sure where this is being called from, but you need to eventually set the value of the menu tree
self.getSibling('Menu Tree').props.items = tree_items

```

> [@matthew.gollasch](#):
>
> There seems to be no way to re-order pages in a Page Configuration. If I want to reorder items in my automatically generated Menu Tree navigation, I need to rebuild the Page Configuration from scratch.

You're already in a script, so you could order the configurations however you choose. You could sort them alpha (which I think is the default anyway), or you could build your own ordering algorithm.

```auto
# sort by the displayed label instead
# This could probably be done purely on self.props.items without needing to copy it
items = self.props.items.copy()
sorted(items, key=lambda item: item['label'])
self.props.items = items

```

---

<div class="post-metadata">

**Author:** ![riccardo.giampaolo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/riccardo.giampaolo/32/20852_2.png) [@riccardo.giampaolo](https://forum.inductiveautomation.com/u/riccardo.giampaolo)\
**Post date:** [May 27, 2022, 1:25pm UTC](https://forum.inductiveautomation.com/t/automatically-creating-perspective-navigation/24338/14 "2022-05-27T13:25:47Z")

</div>

Hello, weighing in to follow on the original request from @Matthew.gaitan, particularly point 2.

Being able to recover the view configuration is a great help, but is there a builtin function to create Perspective routing (e.g. /page routes to /view) without manipulating the config.json file?

I was looking at the [ProjectResourceBuilder](https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.16/com/inductiveautomation/ignition/common/project/resource/ProjectResourceBuilder.html#build()) class, but I’m not entirely sure this would be the way to go.

Thank you.
