Autogenerate Views inside the Perspective View Folder Structure (Self Aware SCADA)

Instead of addProperty, you just use add(name, element): JsonObject - gson 2.9.1 javadoc

1 Like

@PGriffith Thank you!

@PGriffith I'm receiving the import error below when trying to call a script that contains the Java Classes being used to build the views inside the designer from an onClick event inside a view.

However the same script runs without errors when calling from the script console.

Would this be caused by a scope limitation on the java classes?

Yes. The script console is running inside the local designer scope.
Any scripting in Perspective (even inside the designer in Perspective) is actually running on the gateway. The gateway and the designer have totally different classes available to them. Generally you'll see this in their package names; e.g. com.inductiveautomation.perspective.gateway or com.inductiveautomation.perspective.designer. Classes you can use in both locations will have common in their package name.

2 Likes

@PGriffith I used the system.project.getProject() function you created instead of importing IgnitionDesigner and works great thanks again!

Now when I call the same script I mentioned earlier from an onClick event inside a view I'm getting 'ImportError: No module named perspective'. It occurs on all of the com.inductiveautomation.perspective.common imports. I'm assuming since it has common in the name it is not a scope issue.

Any thoughts on the cause and how to resolve this issue?

Thank you!

In the designer, every module shares a single 'classloader' - this is a Java/JVM mechanism. It means that all of the modules can look at each other's code at runtime, essentially.

In the gateway (including Perspective, as mentioned above) you don't have arbitrary access to other modules. With the exception of scripting functions that manually link in specific pieces of a module's functionality, you don't have any direct access.

What you can do instead, especially since you already have Ignition Extensions installed, is something like:
eventConfigClass = system.util.getContext().getModuleManager().resolveClass("com.inductiveautomation.perspective.common.config.EventConfig"), and so on for the different classes you want to load.

4 Likes

@PGriffith I am able to use 'createOrModify()' from the script console but when I execute from a perspective view in the designer I'm getting the AttributeError below.

Is this because system.project.getProject() is a DesignableProject when used in the script console and a RuntimeProject when used on a perspective view? (I'm referencing the Ignition Extensions summary)

designableProject = system.project.getProject()
designableProject.createOrModify(newView)

Caused by: org.python.core.PyException: AttributeError: 'com.inductiveautomation.ignition.common.project.Ru' object has no attribute 'createOrModify'

Yes. On the gateway you can only make direct modifications as resource operations; it's a different API to how you would interact with the designer. It's possible, but would require some rework of the script. Start with ProjectManager.push and ChangeOperations as your research targets.

1 Like

@PGriffith the push() TypeError expects 2 arguments but I only see one in the documentation. Do you know what I'm missing?

Thank you!

Looks like you are trying call it statically. You need an instance of ProjectManagerBase, not the class. (The instance becomes the self first argument that the error is referring to.)

2 Likes

@pturmel thank you for the help!

I'm getting the 'No visible constructors' TypeError on both instances (ChangeOperation() and ProjectManagerBase()).

Am I calling them correctly?

You won't be able to construct that. You have to get one somewhere, usually indirectly through the gateway context.

1 Like

This is the part I struggle most with! probably because most of it is undocumented :slight_smile:

ChangeOperation has various static methods to construct:
https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.21/com/inductiveautomation/ignition/common/project/ChangeOperation.html#newCreateOp(com.inductiveautomation.ignition.common.project.resource.ProjectResource)

A ProjectManager can be retrieved from GatewayContext.