# 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:** 20\
**Page:** 1

<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:** [August 19, 2022, 2:42pm UTC](https://forum.inductiveautomation.com/t/autogenerate-views-inside-the-perspective-view-folder-structure-self-aware-scada/63204/1 "2022-08-19T14:42:50Z")

</div>

I’m trying to solve the problem of manually building out Main Views when I have a data model that encompasses all of the information necessary to auto generate said Main Views.

Outlined below is information describing the background of the problem I’m trying to solve with the Ideal Solution. In this context I’m using the idea of ‘Self Aware SCADA’ to have the ability to auto generate views from a dataset within a defined data model.

Design Purpose:

- Auto generate views (inside the Perspective Views Folder Structure) dynamically from a given dataset
- Automate the Manual build process of the Main View (referenced in Step 2 below).

Current Main View Build Process:

- Step 1 - Add Main View tags to the data model which has a 1 to 1 relationship defined between udts and Templated Views
- Step 2 - Manually buildout the Main View with the appropriate embedded Templated View configurations. Then set the folder tag path for tags to be populated on the embedded Templated Views configured inside the Main View.
- Step 3 - Main View Build is complete.

Solution Requirements:

- Autogenerate any type of view and configuration inside the Perspective Views Folder Structure.
- I don’t want to write to the perspective view file structure externally. This would require manually enabling security on folders.

Ideal Solution:

- Create a Project Library Script that imports and uses the same java classes that are doing the work when manually creating views in the designer.

Is the Ideal Solution that I’m proposing feasible and how would I get started?

Any information or suggestions for alternative solutions would be greatly appreciated. Thank you!

---

<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:** [August 19, 2022, 5:52pm UTC](https://forum.inductiveautomation.com/t/autogenerate-views-inside-the-perspective-view-folder-structure-self-aware-scada/63204/2 "2022-08-19T17:52:06Z")

</div>

I can offer some tips, but be aware that everything you do here is outside the realm of supported territory, so you will have to do a lot of the legwork yourself.

To start, you’ll need to get to the project.

```auto
from com.inductiveautomation.ignition.designer import IgnitionDesigner

context = IgnitionDesigner.getFrame().context

```

Will get you a [`DesignerContext`](https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.19/com/inductiveautomation/ignition/designer/model/DesignerContext.html).  
DesignerContext has a method `getProject()`, which gives you a [`DesignableProject`](https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.19/com/inductiveautomation/ignition/designer/project/DesignableProject.html).

DesignableProject has a _ton_ of utility methods. You will need to learn how our `ProjectResource` class works and how it stores data, and how resources are keyed by type and location.

For the actual resource, you will want to manually construct a [`ViewConfig`](https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.19/com/inductiveautomation/perspective/common/config/ViewConfig.html) instance with the appropriate children.

Once you have a view config, GSON-serialize it appropriately, store it with the correct resource data key in your ProjectResource, and then you’ll have new resources showing up in your designer. You’ll probably have to save in the designer, then reopen the project for the rest of Perspective to pick them up properly.

---

<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:** [August 19, 2022, 8:17pm UTC](https://forum.inductiveautomation.com/t/autogenerate-views-inside-the-perspective-view-folder-structure-self-aware-scada/63204/3 "2022-08-19T20:17:19Z")

</div>

@PGriffith Is there a method available for saving the new resources or is saving manually in the designer the only option?

This is great thank you for the help!

---

<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:** [August 19, 2022, 8:27pm UTC](https://forum.inductiveautomation.com/t/autogenerate-views-inside-the-perspective-view-folder-structure-self-aware-scada/63204/4 "2022-08-19T20:27:42Z")

</div>

You could programmatically invoke the Save or Save All ‘actions’ in the designer, but there’s no exposed API for it. I’m not sure of any other approach that gets around the requirement to avoid direct filesystem manipulation on the gateway.

---

<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:** [August 25, 2022, 5:54pm UTC](https://forum.inductiveautomation.com/t/autogenerate-views-inside-the-perspective-view-folder-structure-self-aware-scada/63204/5 "2022-08-25T17:54:58Z")

</div>

@paul-griffith When I try to serialize the ViewConfig created with the ViewConfig.StandardGsonAdapter.serialize() method. The TypeError returned expects 4 arguments but in the documentation below there is only 3.

Do you know if the documentation is missing the 4th argument or what I’m getting wrong here?

Thank you for the help!

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/1/71b0aa2b8137b7bb59829aeeb281c907e335cf43.png)  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/d/dd423609e1c8d90d46aad17cd87b095bde6ac564.png)

[https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.19/com/inductiveautomation/perspective/common/config/ViewConfig.StandardGsonAdapter.html](https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.19/com/inductiveautomation/perspective/common/config/ViewConfig.StandardGsonAdapter.html)

[https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.19/com/inductiveautomation/perspective/common/config/ViewConfig.html](https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.19/com/inductiveautomation/perspective/common/config/ViewConfig.html)

---

<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:** [August 25, 2022, 6:06pm UTC](https://forum.inductiveautomation.com/t/autogenerate-views-inside-the-perspective-view-folder-structure-self-aware-scada/63204/6 "2022-08-25T18:06:21Z")

</div>

`serialize` is an instance method, so you’d have to construct the adapter first:  
`ViewConfig.StandardGsonAdapter().serialize(src, type, context)`

But the better way to use GSON would be to create a GSON instance (conveniently, we have a helper method for just that):

```auto
from com.inductiveautomation.perspective.common import PerspectiveModule

gson = PerspectiveModule.createPerspectiveCompatibleGson()
gson.toJson(view)

```

---

<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:** [August 31, 2022, 2:03pm UTC](https://forum.inductiveautomation.com/t/autogenerate-views-inside-the-perspective-view-folder-structure-self-aware-scada/63204/7 "2022-08-31T14:03:19Z")

</div>

@paul-griffith Could you please give me an example of how to store the gson serialized view to the ProjectResource? I’m having trouble determining which classes/methods to use and how to use them appropriately.

Thank you for the help!

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

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [August 31, 2022, 2:48pm UTC](https://forum.inductiveautomation.com/t/autogenerate-views-inside-the-perspective-view-folder-structure-self-aware-scada/63204/8 "2022-08-31T14:48:19Z")

</div>

Here is an other option, its creating a view.json

> [@Editing or Creating a Perspective View via Script](https://forum.inductiveautomation.com/t/editing-or-creating-a-perspective-view-via-script/50511):
>
> In case this helps anyone, here’s how you can modify (or create) a Perspective View (or any non-binary resource really) via script. You can call this from any gateway scope, including from a Perspective Button action. Note: the gateway only checks for file updates to resources every 5mins, so you won’t see changes in your client until then, but they will come through automatically. projectName = '' # e.g. 'AwesomeProject' viewPath = '' # e.g. 'Testing/View to Modify' from com.inductiveautomat…

---

<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:** [August 31, 2022, 3:15pm UTC](https://forum.inductiveautomation.com/t/autogenerate-views-inside-the-perspective-view-folder-structure-self-aware-scada/63204/9 "2022-08-31T15:15:46Z")

</div>

If you’re creating a resource from whole cloth, then you would just create a new builder:  
`ProjectResource.newBuilder().setProjectName(project).setResourcePath(resourcePath).putData(ViewConfig.RESOURCE_FILENAME, serializedView).build()`

Modifying an existing resource is usually easier, but I thought you were going to always be creating new resources.

---

<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:** [August 31, 2022, 3:23pm UTC](https://forum.inductiveautomation.com/t/autogenerate-views-inside-the-perspective-view-folder-structure-self-aware-scada/63204/10 "2022-08-31T15:23:16Z")

</div>

@victordcq Thanks for the recommendation. I’ve tested this solution and it works great but required me to disable security on folders in order to add new views. I’m trying to provide users the ability to add assets and then create the views for those assets from the browser in perspective. I’m hoping using the native java classes/methods will give a more seamless approach to accomplishing this task.

---

<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:** [August 31, 2022, 4:18pm UTC](https://forum.inductiveautomation.com/t/autogenerate-views-inside-the-perspective-view-folder-structure-self-aware-scada/63204/11 "2022-08-31T16:18:38Z")

</div>

@paul-griffith I want to add new views to an existing project under a specific folder location. For example in the screenshot below the new views should get created in the ‘SCADA’ folder. With all that in mind are my sequence of steps correct? (assuming my arguments are valid)

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

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

Thanks for your patience, I’m still trying to learn the terminology, purpose of these classes and how they work together.

---

<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:** [August 31, 2022, 4:23pm UTC](https://forum.inductiveautomation.com/t/autogenerate-views-inside-the-perspective-view-folder-structure-self-aware-scada/63204/12 "2022-08-31T16:23:18Z")

</div>

You need to create an instance of `com.inductiveautomation.ignition.common.project.resource.ResourcePath`, via the two-arg constructor: `ResourcePath(com.inductiveautomation.ignition.common.project.resource.ResourceType, java.lang.String)`

So `resourcePath = ResourcePath(ViewConfig.RESOURCE_TYPE, "SCADA/whateverNameYouWant")`  
Where `ViewConfig` is `com.inductiveautomation.perspective.common.config.ViewConfig`.

Your project name can be dynamic with `system.project.getProjectName()`.

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [September 1, 2022, 6:22am UTC](https://forum.inductiveautomation.com/t/autogenerate-views-inside-the-perspective-view-folder-structure-self-aware-scada/63204/13 "2022-09-01T06:22:02Z")

</div>

> [@Nino\_Hernandez](#):
>
> required me to disable security on folders in order to add new views.

hm as what are you running the gateway service? if you run it as admin or whatever it should create the files with the same rights

---

<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:** [September 12, 2022, 6:30pm UTC](https://forum.inductiveautomation.com/t/autogenerate-views-inside-the-perspective-view-folder-structure-self-aware-scada/63204/14 "2022-09-12T18:30:11Z")

</div>

@victordcq That seems right because when I executed from the script console I don’t think I was running as admin.

---

<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:** [September 12, 2022, 7:26pm UTC](https://forum.inductiveautomation.com/t/autogenerate-views-inside-the-perspective-view-folder-structure-self-aware-scada/63204/15 "2022-09-12T19:26:55Z")

</div>

@paul-griffith How would I invoke the “Save or Save All ‘actions’ in the designer”?

Currently I am able to create new views in the designer with a script using the classes and methods you’ve suggested. After manually saving the project updates in the designer the new views are displayed in perspective. I’m trying to automate the saving step of this process.

Also would and approach using the ‘updateProject’ method below work or something similar?

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/0/00af8459fb0214a34fbe190d60a2b3f109b54a3a.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:** [September 12, 2022, 8:35pm UTC](https://forum.inductiveautomation.com/t/autogenerate-views-inside-the-perspective-view-folder-structure-self-aware-scada/63204/16 "2022-09-12T20:35:38Z")

</div>

No. `updateProject` is the opposite direction; it’s pulling changes from the gateway into the current Designer session. Like I said earlier - there’s no direct way to invoke the save/save all actions.

IgnitionDesigner has a private method `handleSave`. With reflection, you can invoke this method despite it’s “private” status. It takes the following arguments:

```auto
boolean saveAs,
String newName,
boolean commitOnly,
boolean skipReOpen,
boolean showDialog

```

Whatever you do here is _totally_ unsupported and subject to change between Ignition versions. This private method could start taking a new argument in the next Ignition release, and you would only know about it once your code stops working.

---

<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 5, 2022, 2:10pm UTC](https://forum.inductiveautomation.com/t/autogenerate-views-inside-the-perspective-view-folder-structure-self-aware-scada/63204/17 "2022-10-05T14:10:04Z")

</div>

@paul-griffith could you please give me and example of how to invoke the "handleSave" method correctly with jython reflection? I've tried multiple variations and have been unsuccessful. With my latest attempt I can't figure out if I'm calling handleSave incorrectly or there is additional requirements that I'm missing.

Thank you for the help!

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/1/0175a50815d14b8d61a7e01aa6d945f94ffec9b8.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 5, 2022, 2:17pm UTC](https://forum.inductiveautomation.com/t/autogenerate-views-inside-the-perspective-view-folder-structure-self-aware-scada/63204/18 "2022-10-05T14:17:46Z")

</div>

If you install [Ignition Extensions](https://forum.inductiveautomation.com/t/ignition-extensions-convenience-utilities-for-advanced-users/64615) it adds a `system.project.save()` method. You can also look into the code to see how I'm calling it via reflection.

---

<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 5, 2022, 2:21pm UTC](https://forum.inductiveautomation.com/t/autogenerate-views-inside-the-perspective-view-folder-structure-self-aware-scada/63204/19 "2022-10-05T14:21:41Z")

</div>

@paul-griffith This is awesome 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, 8:41pm UTC](https://forum.inductiveautomation.com/t/autogenerate-views-inside-the-perspective-view-folder-structure-self-aware-scada/63204/20 "2022-10-11T20:41:57Z")

</div>

@paul-griffith How do I assign JsonObjects to other JsonObjects?

In the example below I'm trying to set the anchor property to the rotate property for the position argument in the ComponentConfig() object but unable to with addProperty().

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

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