Show a popup in perspective on all clients if a value changes

Hi all Thanks. Actually i want open the Emergency pop-up when my integer value equal to 4. As I mentioned earlier I couldn’t make it work with my OPC address. So wrote the Script on OPC integer tag to control the memory Boolean address.

if currentValue.value==4:
		system.tag.writeBlocking(["[.]../../prcd_potr_002/New Tag1"],[True])
	else:
		system.tag.writeBlocking(["[.]../../prcd_potr_002/New Tag1"],[False])

Below is memory address code

popupId = "O2Alarm"
	viewPath = "EquipmentView/Emergency_Stop1"  # insert your view path here
	logger = system.util.getLogger("POPUP")
	sessions = system.perspective.getSessionInfo()
	for session in sessions:
		for pageId in session.pageIds:
			logger.info("{0} | {1}".format(session.id, pageId))
	
			if currentValue and currentValue.value:  # I added an additional safety check for first time use here
				system.perspective.openPopup(popupId, viewPath, sessionId=session.id, pageId=pageId)
				logger.info("openPopup complete")
			else:
				# note no viewPath arg
				system.perspective.closePopup(popupId, sessionId=session.id, pageId=pageId)

Actually the session I mentioned in earlier conversation is about Designer Sessions. we are three people parallelly working for same project.
In browser session it’s working fine i tried it with multiple sessions.

Anything that requires a page context in Perspective will not work in the Designer. This list of features which do not work in the Designer includes - but is not limited to - Docked View actions/scripts, Popup actions/scripts, and Navigation actions/scripts.

This is because the Designer “session” does not contain a Page in the traditional sense. We “mock-up” some data for the relevant properties (like self.page.props.id), but while you’re in the Designer you are only ever looking at a View.

3 Likes

Just a quick aside about a little bit of code.
This won't change anything in the functionality, but I'd suggest writing it like this:

open_popup = currentValue.value == 4
system.tag.writeBlocking(["[.]../../prcd_potr_002/New Tag1"], [open_popup])

Everytime you're using an if/else statement to define if something is True or False, remember the condition is itself already a boolean.
It's all about the readability - while removing the if/else might reduce branching, I'm sure the interpreter is already smart enough to do this itself. So if you find the if/else version clearer or more readable, then keep using it.

No, it's not. Code simplicity matters for performance.

3 Likes

Really ? Is that just Jython, or is Cpython not smart enough either ?

Python3 might be smart enough. Jython uses the same source to .pyc bytecode compiler as CPython2. Last I looked, it wasn’t smart enough.

I don’t think Python, Jython, or Java for that matter really do any optimizations in the compiler. Python for simplicity, Java because it relies on the JVM to do runtime optimizations of code. As someone who frequently has to debug or reverse engineer things, I really appreciate it :slight_smile:

In my case, I found that if I had a designer open, the popup would not open on any session at all. (On Ignition Edge designer 8.1.22, if that is relevant). I just made a slight adjustment to the code to get it running on my end, even when a designer is open:

def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):
	popupId = "SomeUniqueValue"
	viewPath = "PopupViews/SmallPopup"  # insert your view path here
	logger = system.util.getLogger("POPUP")
	sessions = system.perspective.getSessionInfo()
	for session in sessions:
		for pageId in session.pageIds:
			logger.info("{0} | {1}".format(session.id, pageId))
			if session.userAgent != "<designer>":
				if currentValue.value:
					system.perspective.openPopup(popupId, viewPath, sessionId=session.id, pageId=pageId)
				else:
					# note no viewPath arg
					system.perspective.closePopup(popupId, sessionId=session.id, pageId=pageId)
3 Likes

If I had to take a guess, I'd say that since the designer can't open a popup, trying to do so raises an error and aborts the rest of the code. If the designer is the first one to be processed, nothing else get processed, and the sessions don't get their popups.

Now let's wait for Phil or Paul to tell me how wrong I am :smiley:

Huh. No clue.

fyi, I found, at least while trying to use this on a session custom prop on change script, that I needed to use this to get the session's id field:

session.info.id

instead of just

session.id