Change every view on tag change/ Fire alarming

I'm wondering if anyone else has come across the desire to do this, but basically, I'd like one tag to change every view in my project to show a separate view that will have a red background with a label informing everyone to evacuate. I'd also like a second instance that would make a blue background to indicate an ammonia leak and to go to the muster point.

My expression/scripting experience is limited, but I'm willing to work through that, but if someone has experience or some idea on how to best accomplish this, I'd appreciate it

This is a feature I have heard being talked about more recently, it is doable but requires scripting. This can be done currently in Perspective using message handlers.

You can setup a Message Handler on the Perspective Session events which likely works for your case. You could take a similar approach on a resource that is perpetually open, for example a navigation view that is permanently docked. Message Handlers can exist almost anywhere such as a Root Container, and will wait and listen for a message to be sent with a matching handler name. When a message is received the handler will trigger the script. In your case you would want the handler script to open a popup or navigate to a view.

You would then need to setup a "trigger" for the message. In your case, based on I assume tag data. So on potentially a Gateway Event > Tag Change Script, you would then need to add logic to trigger the message send function on all Perspective sessions.

It may look something like this (in addition to logic to only trigger when needed usually an if statement):

# Gets a list of currently running sessions of this project
	runningSessions=system.perspective.getSessionInfo(projectFilter="myProject")

# gets all the designers
	sessions = system.util.getSessionInfo(projectFilter="myProject")
	designerIds = []
	for row in sessions:
		if row["isDesigner"]:
			designerIds.append(row["clientId"])
          
	# Loops through the list of sessions   
	for s in runningSessions:
      
		# if the session is not a designer, send a message (opening a popup, etc)
		if s["id"] not in designerIds:
			for pageID in s["pageIds"]:
				system.perspective.sendMessage(messageType=?, payload=?, [scope="S"], [sessionId=s["id"]], [pageId=PageID])
1 Like

Wow ok. This is definitely at the limits of my skillset, but I'll use your code and try to figure it out. IT would be great if this was a built in feature

I would use a tag binding in every project's session properties, and a propertyChange event on that. Push both the popup view and the script to run from the propertyChange to the root of your project inheritance tree, if not a single-project environment.

The script would loop through the pages of the session (conveniently available in a session script) firing system.perspective.openPopup() on each page. This is much simpler than message sending and receiving scripts.

5 Likes

Ah. So you are thinking make a popup window instead of changing the actual page but would effectively replace it, at least from the end users point of view

1 Like

Well, you could also use system.perspective.navigate() with each page, but popups are least disruptive (for when the immediate danger clears).

1 Like

Yeah that makes sense, and could certainly make it large so that its visible.

Thanks Phil, this is a much cleaner approach.

3 Likes

whelp I spent the day working on this and didn't succeed. My scripting is severely lacking

Show what you have tried and we will be glad to advise of errors or places where perhaps there is a better practice to achieve your goal. Without knowing what you have tried it is hard to suggest what you might need to change.

2 Likes

Something like this (in the property change event):

def valueChanged(self, previousValue, currentValue, origin, missedEvents):
	if currentValue.value:
		for page in self.session.pages:
			system.perspective.openPopup(page.id+"_Emergency", "Path/To/Emergency/View",
				showCloseIcon=False, draggable=False, modal=True, pageId=page.id)

The view that you launch will need a "close" button that is enabled when the tag goes false. The popup is given a predictable view ID composed from the page ID so that you can precisely target the close popup operation.

It would probably be good to update the Perspective Session Properties documentation to describe session.page and session.pages.

3 Likes

Tbh, I'm about ready to give up. I've spent most of the time just googling stuff trying to figure it out as my python/jython is introductory at best. I'm able to get by with basic stuff so far and transforms for most of what I've been doing, but I really need to learn this stuff/ do the Gold Course, cuz python is nowhere in my background.