This lesson is part of the Perspective Components and Bindings course. You can browse the rest of the lessons below.


Autoplay Off
Take topic challenge

Supplemental Videos


Learn how to configure a basic script action in Perspective.

Video recorded using: Ignition 8.0


(open in window)

[00:00] The most comprehensive action in Perspective is the Script Action which allows us to harness the full power of Ignition's scripting platform. As such, Script Actions provide additional flexibility when other Perspective actions don't quite accomplish what we need. In this lesson, we're going to walk through configuring a very basic Script Action. You can find more information about specific uses for Script Actions in our user manual. I've created a simple view to help us out here. On this view I have an Icon component, and I have a Label component that I've called Counter. My goal is just that when I click on my Icon it will increment the value on my Label. So to configure this, I'll need a Script Action. So I'll select my Icon Component, right click, and click Configure Events. I'm going to select an onClick event, and I'm going to click the plus icon to add an Action, and I'll need a Script Action. So every Script Action is provided two objects as parameters. Self is a reference to the component, the event is on, and can be used to reference other components or properties in your Script. Event is a reference to an underlying object associated with the event. The event object has many useful properties. You can find more in the User Manual about the event objects associated with each event type. We're going to use the self object to build a path to the text property on our Label so we can increment it. I already have the script that we'll need so I'm just going to paste it in. It's pretty simple. Just self.getSibling to get another component in the same container as our current component, and then I have to specify its name. I've called it "Counter". And then the path to the property that I want is simply .props.text. And then += 1 just adds 1 to its current value. So to see this in action I'm going to click OK, and I'm going to enter Preview Mode, and then I just click on my Icon, and it increments the value on my counter. So now I'd like to add one more piece of functionality to our script. I'm going to turn off Preview Mode. I'm going to right-click our Icon Component again. I'm going to go back into our Events dialog, and now I want to make it so that if the users holds the Shift key while they click on the icon, it increments by five rather than one. Configuring this might sound complicated, but it's actually pretty easy in Perspective. I just need to add a little bit of extra logic to our existing script. So I'll start by adding a line at the beginning that simply says if event.shiftKey == True: and then I'll paste the previous line again, and this time I want to increment by five rather than one, so I'll replace the one with a five. And then I'll say else, so if the Shift key was not pressed, we will just increment by one. So that's all it takes. I'm just going to come down and press OK now, and I go back into Preview Mode. I'm just going to click normally once or twice. Now I'm going to hold down the Shift key while I click, and as we can see, it increments by five instead of one.

You are editing this transcript.

Make any corrections to improve this transcript. We'll review any changes before posting them.


Share this video