System.Perspective function use within Project Scripts

I’ve written a project script and it works fine until it hits a part where I open a popup using the system.perspective script. I’ve noticed intellisense won’t auto-complete system.perspective.
I’m wondering if that means that it’s not allowed. If that’s the case, is there another way to open an error pop up that a gateway script would allow?
Thanks in advance.

The autocompletion within project scripts is the ‘designer’ scope, but that doesn’t mean system.perspective functions won’t work; just that you have to be sure to call them appropriately.

We have a pending ticket to add a dropdown to project scripts to allow you to manually select what scope is appropriate.

1 Like

Oh okay, I follow. I think my syntax might be off. Is there an additional import I need to do?
I’m running system.perspective.openPopup(‘Popup’, ‘Page/Error_PopUp’) from within the project script.
I’m seeing:
AttributeError: ‘com.inductiveautomation.ignition.designer.gui.tool’ object has no attribute ‘perspective’

You have to be calling from a Perspective context; the library is just Python code that isn’t really validated (beyond syntax) until it’s called.

How are you invoking this popup action?

If you’re trying to write a generic ‘popup an error’ function for use in both Vision and Perspective, that’s doable, but a little more involved.

The project script is triggered using a tag event script (value changed) That tag value changes either with input from a barcode scanner or a text box in a perspective view.
I have try/catches in the project script and I’m trying to get those to open the error popup whenever something fails.

You’re probably going to have to restructure things a bit.

Basically, once you’re in a tag event script (as in, configured specifically on a tag, rather than a tag change script), you’ve “lost” the context of the Vision or Perspective window/view you were in.

I would recommend a somewhat different pattern.
Instead of writing to the tag, and then checking for some error condition, you should have your ‘validation’ logic in the project library, and have your barcode scan/text box simply invoke that shared project script. You can use the technique(s) described in this thread to throw a generic error back to either context.

That way you can ‘guarantee’ whatever value makes it onto the tag is validated, and simplify the logic in your tag event script (I would also recommend putting that code into a project script, as a general practice).