Perspective: Check page open and bind to background colour

Is that any possible method to check whether a specific page are open/active in perspective session that can bind to a variable/tag or style binding to change a background colour of a icon dynamically? If so, please guide me as well. Thank you.

You can bind to the page property
image

page.props.path is the relative URL (e.g. /area/page)
page.props.pageId is the page's main View's viewPath

Alternatively, to view a complete list of all Views open in a session, you can get that from system.perspective.getSessionInfo. That'll get you a list of all open sessions and the info for all of them. You just need to find the current session... which is easier said than done. For some reason, the sessionId (8 character HEX) doesn't match the format of the session.props.id (massive long HEX)
@cmallonee maybe?

Thx for the suggestion, the 'pageID ' in page property will only display the page ID which will not show whether the page is active or open.
I had browse through the system.perspective.getSessionInfo and found there is a 'pageIds' which I may use to check the page Id that are currently active, but can you guide me how to implement it to the component property binding to change the background colour whenever only the page is active?
Sorry that I am new for scripting in Ignition.

You can't manage this via documented scripting functions. The problem you're going to run into is that system.perspective.getSessionInfo() will return a list of sessions but you can only access a count of pages and the id of each page - but nothing about the path of the Page or the Primary View in use.

No it's not. I have to assume you declared this while using the Designer - but this is ONLY true in the Designer because we have to mock-up a fake page id since no page exists. At runtime, each page gets a unique 8-digit identifier.
Screen Shot 2022-10-20 at 8.51.49 AM

I'd need to see how you're obtaining this session id, because I can't think of anywhere we would supply an 8-digit placeholder for the session id.

Two options here:

  • Bind against page.props.path, and have a dictionary of Page paths you've setup yourself (sans any slashes).
  • Bind against page.props.primaryView and have a dictionary of View paths you've setup yourself (sans any slashes).

I recommend the path route because your post explicitly called out Page and not View:

Custom property (on root) with dictionary of supported paths:
Screen Shot 2022-10-20 at 9.02.47 AM

Binding and transform:

Result:
Screen Shot 2022-10-20 at 9.01.33 AM

2 Likes

First, thank you for the suggestion, I work with this example, the result is not as I expected. Let say I create an embedded view as below with the three icons and this embedded view will drop into each of the page represent by 'maintenance', 'motorpage' and 'cylinderpage'. Each icon represent with each page.
2

Inside the root of embedded view, I already define the custom property
1

Running with the script in the example above will result all icons turn green at the same time.
5

May I know how can I modify the script that bind to the color property of the icon so that let say first icon represent 'maintenance', when only the 'maintenance' page is active, the first icon will turn green else will turn black?

Hmm... I was expecting you to have one Icon which needed to change color.

If you're going to have multiple icons, where only one of them is "green" based on the page, then you're better served just using the following expression binding on Icon.props.color:

if(this.page.props.path="/motorpage", "#47ff47", "#000000")

Then copy this binding to the other sibling icons, replacing the path which should result in the icon becoming green. You don't need to strip out the slashes going this route.