This section is designed to familiarize you with some of the basics of Python scripting in Perspective. Perspective scripting is particularly powerful, and can be used to control and fine-tune many aspects of project design.

For a more general view of scripting in Ignition, and an introduction to Python, see Scripting in our Ignition Platform section.

Perspective Scripting Fundamentals

Though Perspective uses the same basic platform (Jython) as other scripting environments in Ignition, interfacing with some unique features in Perspective might make it feel like a new scripting experience. Here are some key details that might be important to Perspective script writers.

Scopes

Perspective does not have a "client" scope, because unlike Vision, Perspective does not have clients. All Perspective scripting is run on the Gateway, although session-specific functions (like navigation) will only affect a single session. Critically, this means that:

  • Client-scoped scripting functions (like system.file, system.gui, and system.nav functions) will not work in Perspective.
  • Other scripting functions, like system.util.getLogger(), will run in a Gateway context.


 


 

Perspective Data Types

Component properties in Perspective are structured as JSON. However, interacting with them does not require any kind of specialized knowledge. Critically, every property in Perspective is one of three types:

TypeDescriptionExample
ValueA value is a simple piece of data, usually a number or string. Assigning a value to a value property is just like assigning a value to an ordinary Python variable.


self.props.text = "My Text"
self.props.startAngle = 5


Object

An object is structured like a Python Dictionary, holding any number of key:value pairs. If you want to pass an object to an object property, you'll need to use the Python Dictionary type.

Note that a Perspective Object could contain different kinds of sub datatypes. One of its keys could map to another object, or to an array.


motorObject = {"motorNum":1,"motorState":"Running"}
self.custom.myObject = {"operationNum":15,"motorObject":motorObject}


Array

An array is structured like a Python List. Unlike an object, where each element in the data type has an associated key, in an array, each element only has a position.

Note that a Perspective Array could contain different kinds of sub datatypes. Arrays can contain objects and other arrays.


rowObject1 = {"city":"Folsom","country":"United States","population":77271}
rowObject2 = {"city":"Helsinki","country":"Finland","population":625591}
self.props.data = [rowObject1,rowObject2]




Object Traversal

In scripting, we can use component properties and methods to access related components, and view and session info. See Perspective Component Methods for details.


Scripting Transforms

Any property binding can make use of a Script Transform to apply any python script to the output value of the binding. For more information, see Transforms and Script Transforms.