### Object Traversal Examples Source: https://docs.inductiveautomation.com/docs/8.1/ignition-modules/perspective/scripting-in-perspective/perspective-component-methods Examples demonstrating how to navigate the component hierarchy within a View to access properties of other components. ```APIDOC ## Object Traversal Examples ### Scripting Example: Get Component Properties from a Button Script (Top Level) ```python # this example code exists on the 'Button 1' in the above hierarchy. # get to the view that the button is in view = self.view # get the text from 'Text Field 1' text1 = self.getSibling('Text Field 1').props.text # get the text from 'Text Field 2' text2 = self.getSibling('Container 2').getChild('Text Field 2').props.text # get the text from 'Text Field 3' text3 = self.getSibling('Container 3').getChild('Text Field 3').props.text # get the text from 'Text Field 4'. Either of these will work the same. text4 = self.getSibling('Container 3').getChild('Container 4/Text Field 4').props.text text4 = self.getSibling('Container 3').getChild('Container 4').getChild('Text Field 4').props.text ``` ### Scripting Example: Get Component Properties from a Button Script (Nested) ```python # this example code exists on the 'Button 4' in the above hierarchy. # get to the view that the button is in view = self.view # get the text from 'Text Field 1' text1 = self.parent.parent.getSibling('Text Field 1').props.text # get the text from 'Text Field 2' text2 = self.parent.parent.getSibling('Container 2').getChild('Text Field 2').props.text # get the text from 'Text Field 3' text3 = self.parent.getSibling('Text Field 3').props.text # get the text from 'Text Field 4' text4 = self.getSibling('Text Field 4').props.text ``` ``` -------------------------------- ### Indirect Tag Path Example Source: https://docs.inductiveautomation.com/docs/8.1/ignition-modules/perspective/working-with-perspective-components/bindings-in-perspective/tag-bindings-in-perspective This example shows how to use an indirection parameter `{intParameter}` to dynamically build a tag path. ```text [default]MyPlant/EastArea/Valves/Valve{intParameter}/FlowRate ``` -------------------------------- ### Get Component Properties from Button Script (Absolute) Source: https://docs.inductiveautomation.com/docs/8.1/ignition-modules/perspective/scripting-in-perspective/perspective-component-methods Example script on 'Button 4' to access properties of other components using parent, getSibling, and getChild, demonstrating traversal up and across the component hierarchy. ```python # this example code exists on the 'Button 4' in the above hierarchy. # get to the view that the button is in view = self.view # get the text from 'Text Field 1' text1 = self.parent.parent.getSibling('Text Field 1').props.text # get the text from 'Text Field 2' text2 = self.parent.parent.getSibling('Container 2').getChild('Text Field 2').props.text # get the text from 'Text Field 3' text3 = self.parent.getSibling('Text Field 3').props.text # get the text from 'Text Field 4' text4 = self.getSibling('Text Field 4').props.text ``` -------------------------------- ### Motor Tag Paths Example Source: https://docs.inductiveautomation.com/docs/8.1/ignition-modules/perspective/working-with-perspective-components/bindings-in-perspective/tag-bindings-in-perspective These are examples of tag paths for different motors, demonstrating the need for indirect binding. ```text Motors/Motor 1 /a mps ``` ```text Motors/Motor 2 /a mps ``` ```text Motors/Motor 3 /a mps ``` ```text Motors/Motor 4 /a mps ``` -------------------------------- ### Get Component Properties from Button Script (Relative) Source: https://docs.inductiveautomation.com/docs/8.1/ignition-modules/perspective/scripting-in-perspective/perspective-component-methods Example script on 'Button 1' to access properties of other components within the same view using getSibling and getChild. ```python # this example code exists on the 'Button 1' in the above hierarchy. # get to the view that the button is in view = self.view # get the text from 'Text Field 1' text1 = self.getSibling('Text Field 1').props.text # get the text from 'Text Field 2' text2 = self.getSibling('Container 2').getChild('Text Field 2').props.text # get the text from 'Text Field 3' text3 = self.getSibling('Container 3').getChild('Text Field 3').props.text # get the text from 'Text Field 4'. Either of these will work the same. text4 = self.getSibling('Container 3').getChild('Container 4/Text Field 4').props.text text4 = self.getSibling('Container 3').getChild('Container 4').getChild('Text Field 4').props.text ``` -------------------------------- ### Example Style Properties Source: https://docs.inductiveautomation.com/docs/8.1/ignition-modules/perspective/styles Illustrates common style properties that can be set for text elements within the Style Editor. ```css color: #800080 font-family: times font-size: 19px font-weight: bold text-align: center ``` -------------------------------- ### Direct Tag Path Example Source: https://docs.inductiveautomation.com/docs/8.1/ignition-modules/perspective/working-with-perspective-components/bindings-in-perspective/tag-bindings-in-perspective This is a standard tag path used for direct binding. ```text [default]MyPlant/EastArea/Valves/Valve4/FlowRate ``` -------------------------------- ### Startup Session Event Script Source: https://docs.inductiveautomation.com/docs/8.1/ignition-modules/perspective/scripting-in-perspective/perspective-session-events-scripts This script runs on session startup. It creates a dictionary of query parameters using the session ID and then executes a named query to record the session's start time in the database. ```python # This script will record the time when the Session is opened. # Create the parameters queryParams = {'sessionID':session.props.id} # Run the query system.db.runNamedQuery('My Project', 'Startup Query', queryParams) ``` -------------------------------- ### Call Custom Method with String Arguments Source: https://docs.inductiveautomation.com/docs/8.1/ignition-modules/perspective/scripting-in-perspective/perspective-component-methods An example of calling a custom method with specific string arguments, illustrating how to pass data to your user-defined functions. ```python self.myMethod("Hi!","This is a test") ``` -------------------------------- ### Expression to Color Mapping Source: https://docs.inductiveautomation.com/docs/8.1/ignition-modules/perspective/working-with-perspective-components/bindings-in-perspective/transforms/map-transform Maps expression inputs to color outputs, useful for dynamically setting background colors. This example uses bitwise operations within expressions and includes a fallback to black. ```text getBit(15, 0) "#FF0000" getBit(15, 1) "#00FF00" getBit(15, 2) "#0000FF" Fallback "#000000" ``` -------------------------------- ### Insert Session Start Time Source: https://docs.inductiveautomation.com/docs/8.1/ignition-modules/perspective/scripting-in-perspective/perspective-session-events-scripts This query inserts a new record into the 'sessions' table with the session ID and the current timestamp when a session starts. ```sql INSERT INTO sessions (session_id, start_time) VALUES (:SessionID, CURRENT_TIMESTAMP) ``` -------------------------------- ### Configure Multi-Line Tooltips Source: https://docs.inductiveautomation.com/docs/8.1/ignition-modules/perspective/working-with-perspective-components/perspective-component-properties To enable multi-line tooltips, set 'white-space: pre' in the tooltip style and concatenate text with '\n'. This example shows how to combine strings for a multi-line tooltip. ```javascript "First Thing" + "\n" + "Another Thing" ``` -------------------------------- ### Getting Project Information Source: https://docs.inductiveautomation.com/docs/8.1/ignition-modules/perspective/scripting-in-perspective/perspective-component-methods Retrieves metadata about the current project, including its name, description, last modified details, and configuration for views and pages. This method was introduced in version 8.1.4. ```Python self.session.getProjectInfo() ``` -------------------------------- ### Python - Asynchronous Message Sending Example Source: https://docs.inductiveautomation.com/docs/8.1/ignition-modules/perspective/scripting-in-perspective/component-message-handlers Demonstrates the asynchronous nature of system.perspective.sendMessage. The script that sends the message continues execution immediately, without waiting for the message handler to complete. The 'running' print statement will likely execute before the 'my-handler' message is fully processed. ```python system.perspective.sendMessage('my-handler') system.perspective.print('running') ``` -------------------------------- ### Example Pipe JSON Structure Source: https://docs.inductiveautomation.com/docs/8.1/ignition-modules/perspective/working-with-perspective-components/perspective-pipes This JSON structure defines a pipe with its origin, connections, and appearance properties. Use this as a reference for creating or manipulating pipe data. ```json [ { "name": "pipe", "appearance": "auto", "flanges": true, "lineVariant": "solid", "start": "none", "end": "none", "fill": "", "stroke": "", "width": 10, "origin": { "x": 258, "y": 168, "connections": [ { "x": 258, "y": 236, "connections": [ { "x": 307, "y": 236, "connections": [ { "x": 360, "y": 236 }, { "x": 307, "y": 168 } ] } ] } ] } } ] ``` -------------------------------- ### Absolute Path Reference Source: https://docs.inductiveautomation.com/docs/8.1/ignition-modules/perspective/working-with-perspective-components/bindings-in-perspective/binding-property-path-reference Use the '/' operator to define an absolute path starting from the top of the view hierarchy. Sequential slashes allow movement into nested containers. ```javascript // Absolute path. Sequential slashes allow // for movement into a container /root/LabelA.position.x /root/Sub_Container1/ButtonA.position.y ``` -------------------------------- ### Numeric Range to Expression Mapping Source: https://docs.inductiveautomation.com/docs/8.1/ignition-modules/perspective/working-with-perspective-components/bindings-in-perspective/transforms/map-transform Maps numeric ranges to expression outputs, allowing for dynamic value generation based on input ranges. This example maps input ranges to different parts of the current time. ```text [0,10] minute(now()) [10,20] hour(now()) [20,30] second(now()) Fallback "Invalid Time Part" ``` -------------------------------- ### Example Bluetooth Advertising Data Structure Source: https://docs.inductiveautomation.com/docs/8.1/ignition-modules/perspective/scripting-in-perspective/perspective-session-events-scripts This JSON structure represents the data received from Bluetooth advertising, including details like RSSI, timestamp, manufacturer data, and specific beacon formats (Eddystone, iBeacon, AltBeacon). ```json { "values": [ { "rssi":-48, "timestamp":1570147485167, "manufacturerData":{ "companyId":6, "dataBase64Encoded":"AQkgAl_edccdnHClMvecMCiM--aAkLHAPibd" } }, { "rssi":-48, "timestamp":1570147486012, "serviceUUIDs":[ "FEAA" ], "serviceData":{ "uuid":"FEAA", "dataBase64Encoded":"AOyqqqqqqqqqqqqqAAAAAAAA" }, "eddystoneUID":{ "txPower":-20, "namespaceID":"AAAAAAAAAAAAAAAAAAAA", "instanceID":"000000000000" } }, { "rssi":-54, "timestamp":1570147485919, "manufacturerData":{ "companyId":76, "dataBase64Encoded":"AhV88isfQjVLY4VnXXfYqpTyAAAAAL8=" }, "iBeacon":{ "uuid":"7CF22B1F-4235-4B63-8567-5D77D8AA94F2", "major":0, "minor":0, "txPower":-65 } }, { "rssi":-54, "timestamp":1570147485987, "manufacturerData":{ "companyId":65535, "dataBase64Encoded":"vqwSNFZ4EjQSNBI0EjRWeJASAAAAAOwA" }, "AltBeacon":{ "manufacturerId":65535, "uuid":"12345678-1234-1234-1234-123456789012", "instance":"00000000", "txPower":-20, "manufacturerReserved":"00" } } ] } ``` -------------------------------- ### Navigate with URL Query Parameters using system.perspective.navigate Source: https://docs.inductiveautomation.com/docs/8.1/ignition-modules/perspective/pages-in-perspective Use system.perspective.navigate to direct users to a Perspective page with query parameters. The URL should include a '?' followed by key-value pairs. This method is for navigation calls, not for page navigation within a session. ```python system.perspective.navigate(url="http://localhost:8088/data/perspective/client/MyProject/view?=") ``` -------------------------------- ### Getting a Sibling Component Source: https://docs.inductiveautomation.com/docs/8.1/ignition-modules/perspective/scripting-in-perspective/perspective-component-methods Retrieves a reference to a component located in the same container as the source component. This is equivalent to navigating to the parent and then getting a child by name. ```Python self.getSibling('Label') ``` -------------------------------- ### Call a Custom Method Source: https://docs.inductiveautomation.com/docs/8.1/ignition-modules/perspective/scripting-in-perspective/perspective-component-methods Demonstrates the syntax for calling a custom method that has been configured on a component, passing the required parameters. ```python self.myMethod(param1,param2) ``` -------------------------------- ### Getting All Page Objects in Session Source: https://docs.inductiveautomation.com/docs/8.1/ignition-modules/perspective/scripting-in-perspective/perspective-component-methods Returns a list containing all page objects currently active within the session. ```Python self.session.getPages() ``` -------------------------------- ### Access Page Path in Perspective Source: https://docs.inductiveautomation.com/docs/8.1/ignition-modules/perspective/scripting-in-perspective/perspective-session-events-scripts Get the URL path of the current page. Access page properties using `.props.`. ```python # Provides a path to the page. pagePath = page.props.path ``` -------------------------------- ### Accessing Session Information Source: https://docs.inductiveautomation.com/docs/8.1/ignition-modules/perspective/scripting-in-perspective/perspective-component-methods Get the current Perspective Session object and access its properties, including custom properties and gateway address. ```python session = view.session sesName = session.gateway.address sesProp = session.custom.propertyName ``` -------------------------------- ### Getting Session Information Source: https://docs.inductiveautomation.com/docs/8.1/ignition-modules/perspective/scripting-in-perspective/perspective-component-methods Retrieves session information as a PyJsonObjectAdapter, similar to a Python dictionary. This object contains keys detailed on the system.perspective.getSessionInfo page. ```Python self.session.getInfo()["pageIds"] ``` -------------------------------- ### Dropdown Options for Theme Selection Source: https://docs.inductiveautomation.com/docs/8.1/ignition-modules/perspective/styles/perspective-built-in-themes/changing-the-theme-from-a-session Use this JSON to configure the options for a dropdown component, allowing users to select between 'light' and 'dark' themes. ```json [ { "value": "light", "label": "light" }, { "value": "dark", "label": "dark" } ] ``` -------------------------------- ### Calling a Custom Component Method Source: https://docs.inductiveautomation.com/docs/8.1/ignition-modules/perspective/scripting-in-perspective/perspective-component-methods Demonstrates how to call a custom method defined on a component object. Ensure the method and its parameters are correctly defined on the component. ```Python output = self.myMethod(param1,param2) ``` -------------------------------- ### Open Parameterized Popup with Scripting Source: https://docs.inductiveautomation.com/docs/8.1/ignition-modules/perspective/views-in-perspective/popup-views Use system.perspective.openPopup to programmatically open a popup view and pass parameter values. Ensure the popup identifier matches the one used to open it if you intend to close it later. ```python system.perspective.openPopup("messageBox",'Popups/MessageBox', params = {'message':self.getSibling("TextField").props.text}) ``` -------------------------------- ### Implement Custom Method Logic Source: https://docs.inductiveautomation.com/docs/8.1/ignition-modules/perspective/scripting-in-perspective/perspective-component-methods This code defines the implementation for a custom method. It shows how to assign values to component properties and custom properties using the provided parameters. ```python self.props.text = myParam1 self.custom.myProp = myParam2 ``` -------------------------------- ### Getting a Specific Page by ID Source: https://docs.inductiveautomation.com/docs/8.1/ignition-modules/perspective/scripting-in-perspective/perspective-component-methods Retrieves a specific page object from the session using its unique string ID. Page IDs can be obtained using the .getInfo() method. ```Python self.session.getPage("2b2eb647") ``` -------------------------------- ### Session Objects Methods Source: https://docs.inductiveautomation.com/docs/8.1/ignition-modules/perspective/scripting-in-perspective/perspective-component-methods Methods for interacting with the current Perspective Session. ```APIDOC ## .close() ## .close(message) ### Description When called will close the session. Optionally accepts a string message which will be displayed after the session closes. ### Method Method ### Parameters #### Path Parameters - **message** (string) - Optional - A message to display after the session closes. ### Example ```python session = self.getSession() session.close("The session has now closed") ``` ## .getInfo() ### Description Returns a PyJsonObjectAdapter object, which is functionally similar to a Python Dictionary. The object contain the same keys described on the system.perspective.getSessionInfo page. ### Method Method ### Example ```python self.session.getInfo()["pageIds"] ``` ## .getPages() ### Description Returns a list of page objects. ### Method Method ### Example ```python self.session.getPages() ``` ## .getPage(ID) ### Description Returns the page associated with the given string ID parameter, if it exists. Page ID values can be determined with the `.getInfo()` method. ### Method Method ### Parameters #### Path Parameters - **ID** (string) - Required - The ID of the page to retrieve. ### Example ```python self.session.getPage("2b2eb647") ``` ## .getProjectInfo() ### Description Returns a dictionary of project meta data, including name, title, description, lastModified, lastModifiedBy, views, and pageConfigs. ### Method Method ### Example ```python self.session.getProjectInfo() ``` ``` -------------------------------- ### Getting a Specific Child Component Source: https://docs.inductiveautomation.com/docs/8.1/ignition-modules/perspective/scripting-in-perspective/perspective-component-methods Finds a child component by its name or a path within the hierarchy. Returns None if the component is not found. This method allows for deep traversal in a single call. ```Python self.getChild('Label_0') ``` ```Python self.getChild('Container/Label_0') ``` -------------------------------- ### Object Traversal - Component/Container Methods Source: https://docs.inductiveautomation.com/docs/8.1/ignition-modules/perspective/scripting-in-perspective/perspective-component-methods Methods and properties for navigating the component hierarchy within a Perspective View. ```APIDOC ## .children ### Description Returns all of the component's children. ### Method Property ### Example ```python self.children ``` ## .getChildren() ### Description Functionally similar to ".children" above. ### Method Method ### Example ```python self.getChildren() ``` ## .parent ### Description Calling this property will move up the component hierarchy, accessing the parent container of the preceding object. Root containers will return the view, and views/sessions will return None. ### Method Property ### Example ```python self.parent ``` ## .getParent() ### Description Functionally similar to ".parent" above. ### Method Method ### Example ```python self.getParent() ``` ## .getChild(string) ### Description Method that looks for a child component of a given name. Returns None if not found. String can either be the name of a child object, or a path to an object delimited by a forward slash, allowing you to move through multiple items in the hierarchy in a single call. ### Method Method ### Parameters #### Path Parameters - **string** (string) - Required - The name or path of the child component to find. ### Example ```python self.getChild('Label_0') self.getChild('Container/Label_0') ``` ## .getSibling(string) ### Description Returns a reference to an object in the same container that the source component is located in. Similar to calling self.parent.getChild('component'). ### Method Method ### Parameters #### Path Parameters - **string** (string) - Required - The name of the sibling component to find. ### Example ```python self.getSibling('Label') ``` ## .view ### Description Calling this from anywhere within a view will return the parent view of the object. ### Method Property ### Example ```python self.view ``` ## .getView() ### Description A method that will return the view, similar to ".view" above. ### Method Method ### Example ```python self.getView() ``` ## .page ### Description Returns a page object associated with the page the current component is on. `.close()` can be called on the page object, and can accept a message string as a parameter. ### Method Property ### Example ```python page = self.page pageID = page.props.pageId pagePath = page.props.path ``` ## .getPage() ### Description A method that will return the page, similar to ".page" above. ### Method Method ### Example ```python self.getPage() ``` ## .session ### Description Returns the current Perspective Session you are in. From this object you can get any of the existing properties of the Session, including custom properties. ### Method Property ### Example ```python session = self.session sesName = session.props.gateway.address sesProp = session.custom.propertyName ``` ## .getSession() ### Description A method that will return the session, similar to ".session" above. ### Method Method ### Example ```python self.getSession() ``` ``` -------------------------------- ### Request Component Focus Source: https://docs.inductiveautomation.com/docs/8.1/ignition-modules/perspective/scripting-in-perspective/perspective-component-methods Allows a component to request focus, directing keyboard input. Only effective on focusable components like input fields. ```python self.focus() ``` -------------------------------- ### Integer to String Value Mapping Source: https://docs.inductiveautomation.com/docs/8.1/ignition-modules/perspective/working-with-perspective-components/bindings-in-perspective/transforms/map-transform Maps specific integer input values to string output values, often used for status text displays. The example shows mapping 0 to 'OFF'. ```text 0 "OFF" ``` -------------------------------- ### Numeric Range to Integer Value Mapping Source: https://docs.inductiveautomation.com/docs/8.1/ignition-modules/perspective/working-with-perspective-components/bindings-in-perspective/transforms/map-transform Maps numeric ranges to integer values. The example demonstrates how exclusive and inclusive range boundaries affect the mapping, and how a fallback value is used when no range matches. ```text (0,25] 0 (25,40] 1 [40,50] 2 Fallback 99 ``` -------------------------------- ### Using CSS Length Units Source: https://docs.inductiveautomation.com/docs/8.1/ignition-modules/perspective/styles Demonstrates how to specify CSS lengths using units other than pixels, such as points (pt). ```css 35pt ``` -------------------------------- ### Parent Container Reference Source: https://docs.inductiveautomation.com/docs/8.1/ignition-modules/perspective/working-with-perspective-components/bindings-in-perspective/binding-property-path-reference The '../' operator provides a shorthand to reference the immediate parent container. Multiple operators can be used to move up multiple levels. ```javascript // From ButtonA, we can use this operator // quickly move to a sibling component ../ButtonB.position.x ``` ```javascript // Moving up multiple parent containers // ../../LabelA.position.x // Also moves up: each additional dot is // another parent container .../LabelA.position.x ``` -------------------------------- ### Request Print with Default Target and Title Source: https://docs.inductiveautomation.com/docs/8.1/ignition-modules/perspective/scripting-in-perspective/perspective-component-methods Initiates a print request for the component. If no target is specified, the component itself is used as the default. A title can be provided for the saved file. ```python self.requestPrint() self.requestPrint('component', 'MyTitle') ``` -------------------------------- ### Import Base Theme in Custom CSS Source: https://docs.inductiveautomation.com/docs/8.1/ignition-modules/perspective/styles/creating-and-using-custom-perspective-themes Import properties from an existing theme to use as a base for your custom theme. This reduces the need to rewrite styles and minimizes potential issues. ```css @import "./light/index.css"; ``` -------------------------------- ### Numeric Range to String Mapping with Omitted Values Source: https://docs.inductiveautomation.com/docs/8.1/ignition-modules/perspective/working-with-perspective-components/bindings-in-perspective/transforms/map-transform Maps numeric ranges to string values, using omitted start or end values to define open-ended ranges. A fallback value is provided for inputs outside the defined ranges. ```text (,25] "Below 25" (25,) "Above 25" Fallback "Invalid Value" ``` -------------------------------- ### Create Custom Icon Repository with SVG Source: https://docs.inductiveautomation.com/docs/8.1/ignition-modules/perspective/working-with-perspective-components/images-and-icons-in-perspective Define custom icons in an SVG file to be used in Perspective. Save this file in the specified Ignition data directory and restart the Designer. ```xml ``` -------------------------------- ### Apply Theme Colors to Component Styles Source: https://docs.inductiveautomation.com/docs/8.1/ignition-modules/perspective/styles/perspective-built-in-themes Use theme colors for component styling by providing the CSS variable name directly to the appropriate style properties on the component's style object. This example shows how to change the background and text color of a button. ```json { "backgroundColor": "var(--primary-color)", "color": "var(--text-on-primary)" } ```