Symbol Scripting
Previous Topic  Next Topic 


With ControlDraw you can animate the diagrams by giving objects and connections dynamic properties

Objects can be programmed in VBScript to calculate their outputs from their inputs.

You can trace the flows of material through a Process Diagram, data flows through a logic diagram etc


A CD2 object can support a number of variables:

IO Variables are the inputs and outputs of the object

Any Input that is derived from an object's output that in turn gets it's values from preceding objects is read only. It may be written during the execution of the expression, however it will be subsequently overwritten by the preceding objects output.

The outputs are related to the inputs by the expression you enter

You can also use local variables within the objects expression. these are not saved between executions of the object expression. If you need to save a variable make it an output or declare it with a Dim statement at the start of the script

And you can use the tagnames of objects on the diagram the symbol is on by enclosing them in {braces}- these are listed in the menu

You can make a CD object that can drive the other objects on a page to a defined state number from a Matrix. The Expression editor includes a button to make the states of a symbol the same as the rows in a matrix.

You can then within a symbols script set the states all of the symbols corresponding to the columns of a matrix to the state given in Row n by using the command.


Note - the signal type does nothing in scripts, all variables are set as variant type.

he Simulation language is Microsoft Visual Basic Scripting.

There is Script Editor a button to open the formula in a Script editor. ControlDraw  includes the freeware Koan VBScript editor, but you can use any other editor by selecting it from the utilities form.

Using the Script editor provides:

Visual Basic syntax colouring for (.VBS)


Find / Replace

Undo / Redo

Note that after you enter the Script Editor, you must shut it down to return to ControlDraw

The Link and States Wizard makes it easy to create common types of dynamics

Global tab :

Here you can declare variables and enter code so that Variables can be created that apply to all symbols.

You can even set objects so that you could for example manipulate Excel from within ControlDraw

In the Globals Tab you can include Dim statements to create Global Variables (these apply across more than one page) and also Functions and Subroutines that you can call from your Symbol Script. See the Dynamics demo for examples.

See also What Happens in Run Mode

You can drag various expressions and functions into the script. This includes

Case:- Creates a SELECT CASE with a  Case for each of the symbols States

TheValue: - The value of the symbol

Outs = AND Ins :- Sets all outputs to the logic AND of all inputs

Outs = OR Ins  :- Sets all outputs to the logical OR of all inputs

Outs = Max Ins :- Sets the outputs to the logic  max of the input

MatrixRow  :-  Sets the symbols to the states given in the row number of the matrix for the page

Error handler : Adds Error handling code and a message if there is an error

CDVariable- Predefined ControlDraw Global Variables

FirstRun - true only on first run of page

Tag On Page - the value of a symbol on the diagram

Auto Script select

You can also set objects to automatically generate code for some simple functions