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

LESSON LIST

Autoplay Off
Take topic challenge

Supplemental Videos

Description

Learn how to use a UDT (User Defined Type) as the template's parameter.

Video recorded using: Ignition 8.1

Transcript

(open in window)

[00:00] In this video, we are going to take a look at how we can make a template indirect by using a UDT Parameter. You'll notice I already have a simple Motor template created with a label up at the top, a graphic of a Motor in the middle and an LED display down at the bottom. I want these to represent the name, the HOA value and Amps value of the Motor respectively. You'll notice I've also created a Motor UDT and have created a few Motor instances as well, with each instance containing an Amps and HOA value. I want to use these UDT instances to make the template indirect, by passing in the instance as a parameter to the template, so that the components of the template could then bind directly to the values of the instance. To start, we need to make a new parameter, by right clicking on the background, going down to Customizers and selecting Custom Properties.

[01:10] Here we'll make a new parameter by clicking on the plus button in the upper right. I'll give it a name of Motor, but this time I want to go to the type, and change it down to User Defined, go into my Tags folder. And you'll notice there's an option for my Motor UDT that I've created. I'll go ahead and select that, and hit okay. You'll notice in the property editor for my template, we now have a new property, the Motor parameter that we just created. Now unlike the standard type of parameter, where we could provide a default value, we actually can't provide a default value for a UDT parameter type. This means that when we start to set up our bindings, we won't see any values appear within the template. It won't be until we add an instance of the template to a window, and then pass in a UDT instance into that template instance, where we will see the values in action.

[02:09] With that in mind, let's go ahead and set up our bindings. I'll start with the Label right up at the top. We'll do a binding on the text property, but this time I want to do a property binding because the parameter is going to be an instance of the UDT. I have all of the values of the UDT at my disposal, as well as a few extra values. Here on the property binding, I can find my Motor parameter, and you'll notice it can be expanded. Here I see my Amps and HOA values, which are a part of the UDT, but there's also this Meta folder that I can expand, and I'm going to find the TagName. Since all of my Motor instance tags are named appropriately, I can just bind the Label to this name property. Once we've got that, we can go ahead and hit OK.

[03:04] And again, because we can't set a default value for our parameter, you'll notice the binding makes the Label blank, and that's because there's no value being passed into that parameter at this point. Moving on to our Motor graphic, I'm going to make this square here on the Motor a different color, depending on the value of the HOA. I'll go ahead and set up a binding on the Fill Paint property. And again, we want to do a property binding. Once again, I'm going to find my UDT property, Motor. We'll expand that. And because the HOA is going to be represented on my Motor graphic here, I'm going to set up my binding to the HOA property. Of course because we're setting up a binding on a Fill Paint property, we do need to set up the number to Color Translator down below. I'll go ahead and assign zero to a color of red, one to a color of green, and two to a color of yellow.

[04:10] Once I have that set, I can go ahead and hit OK. And we'll finish off with the binding on the LED display. We'll find the Value property, and set up a binding. Again, it's going to just be a property binding. We'll find that Motor UDT property and expand it, and this time select the Amps property from the list of UDT values. Once we've got that set, we can go ahead and hit OK. Now that all of our bindings are set up, we're ready to use this template on our window. I've already got a Motor display window set up where we can add some template instances. Go ahead and find my template here and just drag a few instances onto the screen. Now because they don't have default values, they don't immediately show up with some good data.

[05:03] I have to first provide a parameter value for them to use. Now because our parameter type is a UDT, the parameter is actually expecting a whole UDT instance to be passed into here. And we can do that with a Tag binding. So I'll go ahead and bind one of these instances to one of my Motor tags. I'll say this one will be bound to Motor five, and maybe this one on the left will be bound to Motor eight. As you can see, once the bindings are set up, it pulls in that whole instance of the Motor into the template, and then all of those bindings to that parameter that we set up can pull in the proper values into the components. Now, one last thing that we can do when using a UDT type of parameter, is enable the Drop Target property. The Drop Target property is something that we set on our parameter.

[06:02] So I'm going to go back to my template, and go back to my parameter by right clicking on the background, and going to Customizers Custom Property. Now you'll notice for our Motor parameter on the right hand side, we've got an option to make this a Drop Target. What this does, is it makes this template with this particular parameter, a Drop Target for the Motor UDT instances that we may drag onto the window. This is very similar to dragging a standard type of tag on the window. Say an integer memory tag, that provides you with a couple of options for components that you can create. In this case, the component that would get created would be an instance of the template. I'll go ahead and enable Drop Target here. And we can demonstrate that in action. Go ahead and hit OK. Go back to our Motor display. And now, rather than dragging an instance of the template onto the screen and binding it to the tag, I'm just going to drag one of my Motor instances directly onto the screen.

[07:08] And when I do that, you'll notice it automatically creates an instance of the template for me. And if I look down at the Motor parameter, we can see that it's already got a binding setup on it. Opening up the binding, I can see that it is bound to Motor three, the UDT instance that I dragged onto the screen. With Drop Target enabled, it makes it really easy to drag and drop additional instances of your UDT onto the screen, to create more instances of your template. It's important to note that this is only one method of making a template indirect. And we go over another method of making a template indirect by using a standard type of parameter and indirect bindings, in another video.

You are editing this transcript.

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