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

LESSON LIST

Autoplay Off
Take topic challenge

LESSON

Script Transform

Description

Script Transforms take the results of a binding and exposes them to a Python script, allowing you to further manipulate the result of the binding.

Video recorded using: Ignition 8.0

Transcript

(open in window)

[00:00] In this lesson, we'll take a look at the Script Transform. So here, I have a Label. This Label has its text property bound to this temperature Memory Tag. I'd like to apply a Script Transform just to talk about what it can do. Let's click on the binding icon here. And we see I'm using a Tag binding, I'll add a transform, and we've selected the Script Transform. Now the Script Transform will go and run a Python script, meaning you can do quite a bit. Now, in most cases, the Script Transform probably shouldn't be your go-to transform. The other transforms can do quite a bit, and have very simple interfaces. Technically, the Script Transform can do the same thing that those other transforms can do, but you have to write the code. Regardless, let's take a look. So, I'll add one. And you can see we get a little interface to start typing some Python code. Now, the Script Transform is ultimately part of a function definition here, so you want to keep this gutter clear, or have everything indented over. Additionally, you generally want to return something here. The whole point of using a Script Transform is to take the value from the binding or the prior transform, do something with it, and then return something. So, I'm going to make a little bit of room here. And how about just a real simplistic example, move this down a bit, and maybe we can just test to see if our value's past a certain point. You can see that we do have a built-in value object that's defined up above, as well as quality and timestamp. And, of course, the self argument which gives us a reference to the component this transform is on. So, how about in this case, we'll check to see if the value is greater than 100, if it is, we'll return the string "Too hot", otherwise just return whatever the value is. So, we'll hit OK. And you can see, we're showing the same value that's on my tag on the component. I try to change the value here. You can see it's suddenly "Too hot". Now if we head back to the interface there, to kind of wrap up this little lesson here, this transform's almost like a property change script, if you think about it. As long as this view's open, whenever the binding updates, we'll call our script. So, we can do a whole bunch of stuff from here.

You are editing this transcript.

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