Description

Learn how to customize the behavior of advanced components using extension functions. This video uses a right-click menu on the Power Table component as an example.

Video recorded using: Ignition 7.7

Transcript

(open in window)

[00:00] A number of components in the Vision module use something called an extension function. An extension function, is a type of scripting function that is left up to you, the user, to implement. So for example, the power table here makes extensive use of extension functions. You can see here, under the components scripting tree, there's a large list of extension functions here. It's impossible to describe what extension functions are for because each component uses them for different purposes. But they're used to give you, the user, the proper place to put a script for a very specific purpose. And the way that they're programmed, is by you click on the extension function and you enable it, and then you'll see that there's already a fair amount of code here. And the most important thing to realize is that what you're doing when you implement an extension function, is you're implementing the implementation of a function that's already been defined. So the component itself has defined this function, called onPoppupTrigger, and a whole slew of arguments here, and then it uses a triple coded string here, this is a very standard python way of adding documentation to a function, it's called a Docstring. So, you can read what the extension function is all about, by reading the Docstrings. So here you can see, that onPopupTrigger is called when the user right clicks on a table cell. And there's even a little example script that you can uncomment, here, to give you a bit of a head start in implementing these things. So, in this case we're defining a new function inside of this function, that will open up a message box, and we're adding that thing into a popup menu, and we're showing the popup menu. So you can see that this thing works just fine. And the important thing to realize is why is this an extension function? You have to imagine the amount of work you would have had to do, if this extension function wasn't here to achieve the same functionality. So, if you were to try piece together something like this using a MouseHandler, there would be a massive amount of work to do to, for example, translate the mouse coordinates to the coordinates of a cell. And you would have to compensate for any kind of sorting, or rearranging that the user had done. A whole bunch of work that would make implementing something as simple as a popup trigger way too hard. And so this lets the component do all that work for you, and then just call your implementation at the correct time. So you put the implementation in it, but the component decides when to call. So, just to give you a little bit more flavor of other components that use extension functions for totally different purposes. The easy chart component, has an extension function that allows you to provide extra configuration onto the chart itself. Or the alarm status component, allows you to write an extension function, even though there's a number of properties that let you define which alarms in your system you want to display, at some point properties never give you the ultimate level of flexibility that scripting can give you. And so there's an extension function for filtering which alarms are shown. So, this function's going to get called for each alarm that the alarm status table pulls out of the gateway. And then whether or not your script returns true or false, determines whether or not that alarm is displayed inside the table. So you can see there's a really wide aray of purposes that extension functions serve. Just remember, that to teach yourself what any given extension function is for, just read the Docstring. They're self-documenting which is really nice.

You are editing this transcript.

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

close

Share this video