# Editing or Creating a Perspective View via Script

**URL:** <https://forum.inductiveautomation.com/t/editing-or-creating-a-perspective-view-via-script/50511>\
**Category:** Ignition\
**Created:** [September 1, 2021, 1:25pm UTC](https://forum.inductiveautomation.com/t/editing-or-creating-a-perspective-view-via-script/50511 "2021-09-01T13:25:59Z")\
**Posts on this page:** 5\
**Page:** 1

<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:** [September 1, 2021, 1:25pm UTC](https://forum.inductiveautomation.com/t/editing-or-creating-a-perspective-view-via-script/50511/1 "2021-09-01T13:25:59Z")

</div>

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.

```auto
projectName = '' # e.g. 'AwesomeProject'
viewPath = '' # e.g. 'Testing/View to Modify'

from com.inductiveautomation.ignition.gateway import IgnitionGateway
context = IgnitionGateway.get()
projectParentFolder = str(context.systemManager.dataDir.absoluteFile).replace('\\','/') + '/projects'	
projectFolder = projectParentFolder + '/' + projectName
viewFolder = projectFolder + '/com.inductiveautomation.perspective/views/' + viewPath
viewJsonFile = viewFolder + '/view.json'

# read the view resource file as a string
viewJsonStr = system.file.readFileAsString(viewJsonFile)
# convert it to Python objects (lists and dicts)
viewJsonObj = system.util.jsonDecode(viewJsonStr)

##### make edits to the view. #####
# change the text of a Label component on the page
viewJsonObj['root']['children'][0]['props']['text'] = self.getSibling("TextField").props.text

# add a tag binding to the label's display property
propConfig = {
				"position.display":
				{
					"binding":
					{
						"config":
						{
							"fallbackDelay": 2.5,
							"mode": "direct",
							"tagPath": "[default]Test/Flow PV"
						},
						"type": "tag"
					}
				}
			}

labelObj = viewJsonObj['root']['children'][0]
if 'propConfig' in labelObj.keys():
	labelObj.update(propConfig)
else:
	labelObj['propConfig'] = propConfig

##########

viewJsonStr = system.util.jsonEncode(viewJsonObj)
system.file.writeFile(viewJsonFile, viewJsonStr)

```

---

<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, 2021, 1:28pm UTC](https://forum.inductiveautomation.com/t/editing-or-creating-a-perspective-view-via-script/50511/2 "2021-09-01T13:28:50Z")

</div>

ive used something similar to read data from all the project files, but i didnt think to write to it aswell, could be usefull to add in a bunch of bindings

---

<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:** [September 1, 2021, 1:32pm UTC](https://forum.inductiveautomation.com/t/editing-or-creating-a-perspective-view-via-script/50511/3 "2021-09-01T13:32:07Z")

</div>

Yeah, I did something to walk through all of the CSS files and then pull out all CSS variables and display them in a flex repeater as a crude style sheet. Definitely handy to be able to write binding config especially if you have a large number for example bindings on SVG elements, Map component layer Views (e.g. passing the current map zoom level to the Views), etc.

---

<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, 2021, 1:41pm UTC](https://forum.inductiveautomation.com/t/editing-or-creating-a-perspective-view-via-script/50511/4 "2021-09-01T13:41:50Z")

</div>

i used it to read the props.text of all components in all the views to fill up my translation manager xd

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [September 1, 2021, 1:45pm UTC](https://forum.inductiveautomation.com/t/editing-or-creating-a-perspective-view-via-script/50511/5 "2021-09-01T13:45:57Z")

</div>

Not bad, I think I’ll do that.
