Animating an Object to Execute a Script
The Pick Action Configuration Wizard allows you to create three types of script animations:
- Call Specific Function—When the Mimic object is selected, a function in the Mimic script is executed. This type of animation can only be used if the required function has no arguments. If arguments are needed, you need to use an Execute Code Fragment animation.
- Execute Code Fragment—When the Mimic object is selected, VB script that is defined in the animation runs. The animation can contain a complete VB script or can call functions in the Mimic script, including functions that require arguments.
- Execute Code Fragment on Top Level Mimic—Designed for use on embedded Mimics, this type of animation allows you to call a function in the script for the top-level Mimic. It can be used even if scripting is disabled on the embedded Mimic.
However, you can also create these script animations manually, by creating animations for the PickType and PickParam properties.
For a Call Specific Function animation, you need to configure the animations as:
- PickType—19
- PickParam—The name of a function in the Mimic’s script, entered as a string, that is, enclosed in single quotation marks.
Example:
- PickType—19
- PickParam—'MsgBox("Close Valve if Value > 50")'
This animation sets a Mimic object so that, when selected, a message box is displayed. The message box contains the message : Close Valve if Value > 50.
If you need the animation to call a function that has arguments, you need to use PickType 17 (see below).
For an Execute Code Fragment animation, you need to configure the animations as:
- PickType—17
- PickParam—This has to be VB script entered directly as a string for the PickParam value. You can enter the entire script to be executed as the PickParam value, or you can use VB script to call a function in the Mimic script.
Example:
A simple Mimic script is created to provide access to the Print settings. It is:
Public Function PrintMimic
Mimic.Print
End Function
A rectangle is added to the Mimic and animated so that, when selected, it calls the PrintMimic function. The animations to add this functionality to the rectangle are:
- PickType—17
- PickParam—'PrintMimic'
For an Execute Code Fragment on Top Level Mimic animation, you need to configure the animations as:
- PickType—20
- PickParam—VB script that calls a function in the script of the top-level Mimic, entered as a string value. If you have several embedded Mimics that call the same function, using an Execute Code Fragment on Top Level Mimic animation has performance benefits. This is because it is more efficient to run a single script for a top level Mimic than it is to run individual scripts for each embedded Mimic.
Example:
A top-level Mimic contains a script that has a ‘VerifyControl’ function which requires 1 argument (the name of a point).
A Mimic is created to be a ‘faceplate’ symbol for a device. It contains a graphic for the device and a text box which will show the name of a point. The point name will change, depending on which point is associated with the symbol, and so a parameter named PointName is created to allow for this.
The following animations are created for the text box:
- PickType—20
- PickParam—'VerifyControl "' + "Parameter:PointName"+ '"'
Scripting is disabled on the ‘faceplate’ Mimic.
The ‘faceplate’ Mimic is embedded on the top-level Mimic four times. The embedded Mimics are then configured so that each embedded Mimic is associated with a different point (by using the Auto Configure feature).
When the text box is selected on any of the embedded Mimics, the VerifyControl function in the top-level Mimic script is called. The arguments for the function, in this case, the point name, are taken from the VB script in the embedded Mimics’ PickParam values (the Parameter part of the animation value).
The embedded Mimics are able to call a function in the top level Mimic, even though they have scripting disabled. This is because scripting only needs to be enabled on the Mimic on which the script runs. There are also performance benefits to calling functions in this way, as ClearSCADA only needs to run one script instead of five (one for the top-level Mimic and one for each embedded Mimic).