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

**URL:** <https://forum.inductiveautomation.com/t/autogenerate-views-inside-the-perspective-view-folder-structure-self-aware-scada/63204>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [August 19, 2022, 2:42pm UTC](https://forum.inductiveautomation.com/t/autogenerate-views-inside-the-perspective-view-folder-structure-self-aware-scada/63204 "2022-08-19T14:42:50Z")\
**Posts on this page:** 14\
**Page:** 2

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [October 11, 2022, 8:43pm UTC](https://forum.inductiveautomation.com/t/autogenerate-views-inside-the-perspective-view-folder-structure-self-aware-scada/63204/21 "2022-10-11T20:43:24Z")

</div>

Instead of `addProperty`, you just use `add(name, element)`: [JsonObject - gson 2.9.1 javadoc](https://javadoc.io/doc/com.google.code.gson/gson/latest/com.google.gson/com/google/gson/JsonObject.html)

---

<div class="post-metadata">

**Author:** ![Nino\_Hernandez](https://avatars.discourse-cdn.com/v4/letter/n/96bed5/32.png) [@Nino\_Hernandez](https://forum.inductiveautomation.com/u/Nino_Hernandez)\
**Post date:** [October 11, 2022, 8:52pm UTC](https://forum.inductiveautomation.com/t/autogenerate-views-inside-the-perspective-view-folder-structure-self-aware-scada/63204/22 "2022-10-11T20:52:09Z")

</div>

@paul-griffith Thank you!

---

<div class="post-metadata">

**Author:** ![Nino\_Hernandez](https://avatars.discourse-cdn.com/v4/letter/n/96bed5/32.png) [@Nino\_Hernandez](https://forum.inductiveautomation.com/u/Nino_Hernandez)\
**Post date:** [October 11, 2022, 9:40pm UTC](https://forum.inductiveautomation.com/t/autogenerate-views-inside-the-perspective-view-folder-structure-self-aware-scada/63204/23 "2022-10-11T21:40:47Z")

</div>

@paul-griffith 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?

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/3/13880b8afe12f724d161fa147bf84f8f1d3cd603.png)

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [October 11, 2022, 9:50pm UTC](https://forum.inductiveautomation.com/t/autogenerate-views-inside-the-perspective-view-folder-structure-self-aware-scada/63204/24 "2022-10-11T21:50:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Nino\_Hernandez](https://avatars.discourse-cdn.com/v4/letter/n/96bed5/32.png) [@Nino\_Hernandez](https://forum.inductiveautomation.com/u/Nino_Hernandez)\
**Post date:** [October 12, 2022, 2:07pm UTC](https://forum.inductiveautomation.com/t/autogenerate-views-inside-the-perspective-view-folder-structure-self-aware-scada/63204/25 "2022-10-12T14:07:52Z")

</div>

@paul-griffith 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!

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/a/aaecb84f06db46efa03d9c1603e2ecca9ed076f4.png)

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [October 12, 2022, 2:38pm UTC](https://forum.inductiveautomation.com/t/autogenerate-views-inside-the-perspective-view-folder-structure-self-aware-scada/63204/26 "2022-10-12T14:38:07Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Nino\_Hernandez](https://avatars.discourse-cdn.com/v4/letter/n/96bed5/32.png) [@Nino\_Hernandez](https://forum.inductiveautomation.com/u/Nino_Hernandez)\
**Post date:** [October 17, 2022, 10:39pm UTC](https://forum.inductiveautomation.com/t/autogenerate-views-inside-the-perspective-view-folder-structure-self-aware-scada/63204/27 "2022-10-17T22:39:47Z")

</div>

@paul-griffith 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)

```auto
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'`

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [October 17, 2022, 11:06pm UTC](https://forum.inductiveautomation.com/t/autogenerate-views-inside-the-perspective-view-folder-structure-self-aware-scada/63204/28 "2022-10-17T23:06:10Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Nino\_Hernandez](https://avatars.discourse-cdn.com/v4/letter/n/96bed5/32.png) [@Nino\_Hernandez](https://forum.inductiveautomation.com/u/Nino_Hernandez)\
**Post date:** [October 20, 2022, 9:27pm UTC](https://forum.inductiveautomation.com/t/autogenerate-views-inside-the-perspective-view-folder-structure-self-aware-scada/63204/29 "2022-10-20T21:27:24Z")

</div>

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

Thank you!

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/c/0c39f4317ae4eba4dadf96ad790ea7cf7dde1b3b.png)

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [October 20, 2022, 9:30pm UTC](https://forum.inductiveautomation.com/t/autogenerate-views-inside-the-perspective-view-folder-structure-self-aware-scada/63204/30 "2022-10-20T21:30:39Z")

</div>

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.)

---

<div class="post-metadata">

**Author:** ![Nino\_Hernandez](https://avatars.discourse-cdn.com/v4/letter/n/96bed5/32.png) [@Nino\_Hernandez](https://forum.inductiveautomation.com/u/Nino_Hernandez)\
**Post date:** [October 20, 2022, 9:51pm UTC](https://forum.inductiveautomation.com/t/autogenerate-views-inside-the-perspective-view-folder-structure-self-aware-scada/63204/31 "2022-10-20T21:51:34Z")

</div>

@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?

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/9/e9d7ceec67aaf8a7325a25154dd4575c98aead5e.png)

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [October 20, 2022, 9:53pm UTC](https://forum.inductiveautomation.com/t/autogenerate-views-inside-the-perspective-view-folder-structure-self-aware-scada/63204/32 "2022-10-20T21:53:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [October 20, 2022, 9:59pm UTC](https://forum.inductiveautomation.com/t/autogenerate-views-inside-the-perspective-view-folder-structure-self-aware-scada/63204/33 "2022-10-20T21:59:44Z")

</div>

> [@pturmel](#):
>
> You have to get one somewhere, usually indirectly through the gateway context.

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

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [October 20, 2022, 10:32pm UTC](https://forum.inductiveautomation.com/t/autogenerate-views-inside-the-perspective-view-folder-structure-self-aware-scada/63204/34 "2022-10-20T22:32:53Z")

</div>

`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)](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`.

[Previous page](https://forum.inductiveautomation.com/t/autogenerate-views-inside-the-perspective-view-folder-structure-self-aware-scada/63204.md?page=1)
