Creating a Dynamo Through Scripting
-
Upload
andres-castillo -
Category
Documents
-
view
216 -
download
0
Transcript of Creating a Dynamo Through Scripting
-
8/10/2019 Creating a Dynamo Through Scripting
1/30
-
8/10/2019 Creating a Dynamo Through Scripting
2/30
2 Creating a Dynamo with VBA
Table of Contents1. CREATING A DYNAMO WITH VBA.............................................................................................................................3
1.1NAMING CONVENTIONS FOR DYNAMO OBJECTS..............................................................................................................3
1.2 CREATING A DYNAMO..........................................................................................................................................................4
1.3 DESIGNING THE DYNAMO USER INTERFACE .....................................................................................................................6
1.4 BUILDING THE DYNAMOS USER INTERFACE....................................................................................................................7
1.4.1 Creating the User Interface .......................................................................................................................................8
1.4.2 Entering the VBA Script...........................................................................................................................................10
1.4.3 Setting up the Public Property Routines ...............................................................................................................11
1.4.4 Setting up the User Interface ...................................................................................................................................15
1.4.5 Changing Dynamo Properties with User Input....................................................................................................16
1.4.6 Making Modifications to the Expression Editor Control ...................................................................................171.5 ADDING A DYNAMO TO A DYNAMO SET..........................................................................................................................21
2. ADVANCED TOPICS..........................................................................................................................................................22
2.1 SETTING INTELLIGENT DEFAULTS FOR DATA SOURCES................................................................................................22
2.2 LETTING USERS SET INPUT AND OUTPUT LIMITS...........................................................................................................23
2.3 VALIDATING A DATA SOURCE AND LAUNCHING THE FIXDYNAMICS QUICK ADD DIALOG..................................252.4 ACCESSING A DYNAMO FROM OUTSIDE ITS FORM.........................................................................................................26
2.5 USING THE GLOBAL COLOR BY FORM IN DYNAMOS.....................................................................................................27
-
8/10/2019 Creating a Dynamo Through Scripting
3/30
Creating a Dynamo with VBA 3
1. Creating a Dynamo with VBAThis document steps you through an example of how to create a dynamo and its
user interface using Visual Basic for Applications scripts. In this example, we
will develop a simple tank dynamo. We will create a user interface for the
dynamo that will allow the user to:
? Change the color of the tanks contents
? Animate the vertical fill percentage of the tanks contents based on adatabase tag
The first section describes the basics for creating dynamos with scripts. The
next section, Advanced Topics, gives instructions for adding functionality to
your dynamo to make it more powerfu l and versatile. Topics in this sectioninclude:
? Naming Conventions for Dynamo Objects
? Creating a Dynamo Object
? Designing the Dynamo User Interface
? Building the Dynamo User Interface
? Adding a Dynamo to a Dynamo Set
1.1 Naming Conventions for Dynamo ObjectsA Dynamo is really an object made from a group of objects. Because you will
be accessing the objects that make up your dynamo in VBA, it is very important
that you adhere to a naming convention for these objects.
The technique described in this document for developing Dynamos allows
multiple instances of the same Dynamo in a picture to use the same forms andscripts. To do this you must make sure that you use partial names of objects that
make up the dynamo when you call the FindLocalObject method (explained in
section Setting up the Public Property Routines) in your scripts. When you refer
to an object by its full name in a VBA script, it is automatically registered in
VBA. If you make reference to that same object again in another code module,
VBA automatically creates another instance of that code module and gives it anincremental number. Therefore, if you dont use a partial name when calling
FindLocalObject in your scripts, each time you drop the same Dynamo in a
picture, VBA will create another instance of the form or code module.
-
8/10/2019 Creating a Dynamo Through Scripting
4/30
4 Creating a Dynamo with VBA
The Dynamos that Intellution supplies provide a good example of naming
conventions for Dynamos. Figure 1 shows the objects that make up theTanksAnim1 Dynamo. Note that all are indexed with a unique number. If you
need to call FindLocalObject for AnimatedTankLevel21 in your Dynamo
scripts, you can use the partial name AnimatedTankLevel.
Figure 1. Objects that make up the TanksAnim1Dynamo
1.2 Creating a Dynamo
First, we will create a simple tank object with 5 rectangles, an oval , and a pie as
show below:
-
8/10/2019 Creating a Dynamo Through Scripting
5/30
Creating a Dynamo with VBA 5
Figure 2. Objects that make up the Tank Dynamo
For this dynamo, we want to allow users to animate the horizontal fill
percentage property of the large rectangle that makes up the tank container
section. Give this rectangle a unique name such as TankMain1. You can name
an object using the property window or the Animations dialog.
For dynamo animations, it is best to use animation object connections rather
than direct connections. When you animate an object with an animation
connection, you connect the object to an animation object which is in turnconnected to the data source. Because we want to animate this rectangles
vertical fill percentage, we will attach a linear animation object to its vertical fill
percentage. Then, when we want to change the data source, all we have to do is
change this animation objects data source. To do this:
[1] Double click on the TankMain1 rectangle. The Animations dialogappears.
[2] Select the Fill tab.
[3] Select the Vertical Fill Percentage check box and enter a dummy tagname in the Data Source field such as: Fix32.node.TankLevel.f_cv.
[4] Click OK and Use Anyway in the Animations dialog.
[5] You will see the new animation object displayed under the selected object
in the System Tree as shown in Figure 3 below. Rename the animation
object to a unique name such as TankAnimationVerticalFill1.
-
8/10/2019 Creating a Dynamo Through Scripting
6/30
6 Creating a Dynamo with VBA
Now, group the objects and name the group. The name you assign to the group
is the dynamos name. For this example, we will name the dynamo BigTank.Look to the system tree. You should see the BigTank group and its members as
shown below.
Figure 3. BigTank Dynamo and its members
1.3 Designing the Dynamo User Interface
It is a good idea to sketch out your ideas on pape r before jumping into the code.
Try your paper designs and decide exactly what you want your form to do. Thiswill ultimately save time in coding in that it will decrease the amount of changes
you need to make due to uncertainties in your design.
In our BigTank dynamo, we only want to allow users to select database tags as
data sources. The design criteria for our example will be that when the user
launches the expression builder with the Expression Editor control, they only see
the Database tab. Knowing this criteria before you start developing your
dynamo is very important.
Design Criteria for BigTank Dynamo:
? The user interface should appear any time a user drags and drops thedynamo from a dynamo set to a picture or from a picture to another
picture. The user interface should also appear when the user doubleclicks on the dynamo thereby overriding the Animations dialog.
-
8/10/2019 Creating a Dynamo Through Scripting
7/30
Creating a Dynamo with VBA 7
? The user interface should allow the user to set a database tag to control
the vertical fill of the tank.
? The user interface should allow the user to change the color of thecontents of the tank. This change should take place in the Configurationenvironment. The color is not to be animated.
1.4 Building the Dynamos User Interface
Once you are confident about your design, you can start developing your
dynamo using FIX Dynamics VBA. We will first address the criteria that the
user interface should appear on a drag-and-drop or a double click. Initiating our
code on the BigTanks Edit event will do the trick. To see how this works,
follow these steps:[1] Right mouse click on the BigTank object. A drop down menu appears.
[2] Select Edit Script. The Visual Basic Editor appears with the cursor
situated in the BigTanks Click event as shown below:
Private Sub BigTank_Click()
|
End Sub
[3] Notice the two drop down list boxes at the top of the code window. Clickthe drop down arrow on the right drop down list box and select Edit.Now BigTanks Edit event appears.
[4] Type code to display a message box under the BigTanks Edit event:
Private Sub BigTank_Edit()
MsgBox "HI"
End Sub
[5] Switch to the Workspace and double click on the BigTank group. The
message box appears.
We will enter script to display the user interface on the Edit event.
-
8/10/2019 Creating a Dynamo Through Scripting
8/30
8 Creating a Dynamo with VBA
1.4.1 Creating the User Interface
For this dynamo, we want to create a form that allows the user to:
? Select a color for the tanks contents
? Select a database tag to control the tanks vertical fill
Fix Dynamics supplies two controls that we can use for these functions: the
Color Button control and the Expression Editor. The Color Button control
launches a color box allowing a user to select a color. The Expression Editor
launches the Expression Builder dialog which allows you to select a data source
from a list of nodes, tags, and fields. See documentation in FIX Dynamics
Electronic Books for Color Button and Expression Editor.
A rough sketch for our form is shown below:
Use the following steps to create the form:
[1] Right mouse click on the BigTank group an select Edit Script from thedrop down menu. The Visual Basic Editor appears.
[2] In VBE, select UserForm from the Insert menu. A new user formappears.
[3] Insert the Expression Editor control, the Color Button control and theappropriate labels as shown below:
-
8/10/2019 Creating a Dynamo Through Scripting
9/30
Creating a Dynamo with VBA 9
If the Expression Editor and Color Button do not appear on the Toolbox
of controls in VBE, select Additional Controls from the VBE Tools
menu. Select Intellution FD Color Controland Intellution FDExpression Editor Control from the Additional Controls dialog.
[4] Assign the User form the name frmBigTankDynamo, assign the OK
button the name cmdOK, and assign the Cancel button the name
cmdCancel.
At this point, there are many different choices you could make that would work.
Intellution suggests you think of your dynamo as a new object with its own
properties that you define. For example, the rectangle object has properties such
as height, width, horizontalfillpercentage, verticalfillpercentage, and rotation
angle. In this example, we are going to assign our BigTank two of its own
properties: TankContentsColor and TankDataSource. TankContentsColor is the
color of the contents, TankDataSource is the database tag that controls the
Tanks vertical fill percentage. We will do this in the dynamos form.
-
8/10/2019 Creating a Dynamo Through Scripting
10/30
10 Creating a Dynamo with VBA
1.4.2 Entering the VBA Script
Because we will be doing most of the work on our dynamo from within the
form, we will have to pass the BigTank group to the form. Once we pass the
BigTank group to the form, it knows which object to apply changes to. Use the
following steps to pass the BigTank group to the form:
[1] Double click on the form to display its code window.
[2] Select General Declarations in the forms code window
[3] Enter:
Public Tank as Object
In the General Declarations section.
This makes the Tank object (the BigTank group) a public object. It can bemanipulated from any location.
Now, we will create a subroutine in the form that will initialize the Tank object
in the form. To do this, type in the following:
Public Sub InitializeDynamo(DynamoName As Object)
Set Tank = DynamoName
End Sub
This is a public subroutine that accepts the dynamo object and sets the public
Tank object equal to that object. Now, go back to the picture code window andreplace the message box text you entered with the following:
Private Sub BigTank_Edit()
-
8/10/2019 Creating a Dynamo Through Scripting
11/30
Creating a Dynamo with VBA 11
Call the Initialize Dynamo subroutine in the
frmBigTankDynamo form to initialize the dynamo objectfor use in the form code.
frmBigTankDynamo.InitializeDynamo BigTank
Display the frmBigTankDynamo form
frmBigTankDynamo.Show
End Sub
Try double clicking on the BigTank group now. Your new form should appear.
Click on the x in the upper right corner to make it disappear.
1.4.3 Setting up the Public Property Routines
Now, we will create the TankDataSource and TankColor property functions.
We will make these functions public so users to get to them from outside the
dynamo. Setting up Public Properties for dynamos provide the following
benefits:
1. It keeps you code modular. If you need to make a change to the dynamos
functionality, you only have to change the code in one place.2. Scripts that are not part of the dynamo can access these public propert ies to
modify the dynamo. The dynamo can be manipulated without any
knowledge of its code or how it was built.
-
8/10/2019 Creating a Dynamo Through Scripting
12/30
12 Creating a Dynamo with VBA
Before we get into the code, we should talk a little about the Global function
FindLocalObject. This function is one of the FIX Dynamics GlobalSubroutines. The following is a topic describing FindLocalObject that you can
find in the FIXVBA.hlp.
FindLocalObjectFinds an object inside a group based on the objects partial name. The groupcould be a Picture, DynamoSet or a Group of shapes.
SyntaxFindLocalObject (StartObject, PartialName)
The FindLocalObject subroutine syntax has these parts:
Part Description
StartObject Object. The name of the Picture or Group were the objectyou are looking for is contained.
PartialName String. A partial name for the object to be found. Forexample, if the objects full name is PipeColorAnim1, youcan pass in PipeColorA, or PipeC.
Return Value Object. The first object in the Group whose name containswhat is entered for PartialName.
RemarksFor example, if, through scripting, you want to get an object inside a Group inorder to animate that particular objects vertical fill, use FindLocalObject with thegroups name and just a partial name of the object to fill.FindLocalObject is typically used for Dynamo sets where dynamos sharecommon names for all of their objects, the only difference being the numeric
ending. Forms and subroutines that call this subroutine make use of the partialname to operate on all similar Dynamos so that all similar Dynamos in a picturecan use the same subroutines and forms. This assumes that the Dynamo builderdefines a naming convention for the objects in the Dynamo.ExampleDim PipeSectObj As Object
Set PipeSectObj = FindLocalObject(Pipe, "PipeColorAnimation")
This subroutine is used extensively in dynamos. You can use it to find an object
inside a group based on the objects partial name. This explains the importance
of naming convention. FindLocalObject has two parameters: StartObject as
Object , PartialName as String
? StartObject - The object in which the desired object is contained.
? PartialName - A partial name for the object to be found.
-
8/10/2019 Creating a Dynamo Through Scripting
13/30
Creating a Dynamo with VBA 13
Now, we will enter the following Property procedure for retrieving the Tanks
data source in the Big Tank Dynamos user form. A Property procedure lets youcreate and manipulate custom properties. For more information on Property
procedures, see Microsofts VBA help.
All of the following code belongs in the Big Tank Dynamos User Form in the
General Declarations sect ion.
Public Property Get TankDataSource() As String
Dim AnimatedTankLevel As Object
Set the object AnimatedTankLevel equal to the returnvalue of FindLocalObject. Notice that we are passing inthe Public object Tank that was set in the
InitializeDynamo subroutine. Tank = BigTank. We are
also passing in the partial name of the Vertical FillAnimation object that we created called
TankAnimatedVerticalFill1. This means thatAnimatedTankLevel is set to the Vertical Fill animation
object.
Set AnimatedTankLevel = FindLocalObject(Tank,"TankAnimatedVerticalFill")
Now, we return the data source of animation object.The first time around, it will be the dummy tag that we
entered when we created the animation object. Afterthat, it will a valid data source that the user enters
in the Expression Editor control.
TankDataSource = AnimatedTankLevel.Source
End Property
Next, we enter the following property procedure for setting the Tanks data
source. Here we use the Let Property procedure because we want to set the
value of the property. The Set Property procedure sets a reference to an object.
See Microsoft VBA documentation for more information on Get, Let, and Set
Procedure properties.
Public Property Let TankDataSource(DataSource As String)
Dim TankDataSource As Object
As with the Get TankDataSource Property procedure, weset an object equal to the tanks animation object.
-
8/10/2019 Creating a Dynamo Through Scripting
14/30
14 Creating a Dynamo with VBA
Set TankDataSource = FindLocalObject(Tank,
"TankAnimatedVerticalFill")
Now we use the SetSource procedure to set theTankDataSource property to the DataSource that gets
passed to this procedure. The data source will be what
the user enters in the Expression Editor. Thisprocedure gets called in the On_OK subroutine that will
be described in the Competing the UI Code section.
TankDataSource.SetSource DataSource
End Property
Next, we will enter Property procedures for the Tanks contents color.
First, the Get Property procedure:
Public Property Get TankContentsColor() As Long
Dim TankCore As Object
Set TankCore = FindLocalObject(Tank, "TankMain")
TankContentsColor = TankCore.ForegroundColor
End Property
Now, the Let Property procedure:
Public Property Let TankContentsColor(Color As Long)
Dim TankCore As Object
Set TankCore = FindLocalObject(Tank, "TankMain")
TankCore.ForegroundColor = ColorButton1.Color
End Property
-
8/10/2019 Creating a Dynamo Through Scripting
15/30
Creating a Dynamo with VBA 15
1.4.4 Setting up the User Interface
The next step is to get the correct values into the User Interface when it is
launched. Because we have already set up the Get Property procedures, this is a
simple task. All we have to do is make calls to these procedures and they will
get us the Tanks data source and color properties then, we put the values in the
appropriate controls. We will want enter data into the user interface when the
user interface is activated. Therefore, this code belongs in the
UserForm_Activate event .
Private Sub UserForm_Activate()
'Initialize the User Interface for BigTank Dynamo
Get the TankDataSource property and put it in theExpression Editor control. The following statement
calls the TankDataSource Property Get procedure wecreated in the previous section.
ExpressionEditor1.EditText = TankDataSource
Get the TankContentsColor property and put it in the
Color Button control. The following statement calls theTankContentsColor Property Get procedure we created in
the previous section.
ColorButton1.Color = TankContentsColor
End Sub
Now, try double clicking on the BigTank group. The following should appear:
-
8/10/2019 Creating a Dynamo Through Scripting
16/30
16 Creating a Dynamo with VBA
The dummy database tag we created for the vertical fill animation object is in
the Expression Editor and the Color Button is now the color of BigTanks mainsection.
1.4.5 Changing Dynamo Properties with User Input
Now, we want what the user enters into our form to affect the BigTank dynamo.
What should happen if the user selects Cancel? For this dynamo, we want its
properties to remain unchanged. Therefore, all we have to when the user clicks
Cancel is to close the form. We want to put the code to unload the form on theCancel buttons Click event as show below:
Private Sub cmdCancel_Click()
Unload Me
End Sub
Try double clicking on BigTank again and then select the Cancel button. The
form should disappear as expected.
We only have the OK button left. The following is what should happen when
the user clicks OK:
? The vertical fill animation objects data source should change to what theuser entered in the Expression Editor.
? The BigTank contents section should change color to match the usersselection.
-
8/10/2019 Creating a Dynamo Through Scripting
17/30
Creating a Dynamo with VBA 17
To accomplish these tasks, we will enter the following code in the OK buttons
Click event:
Private Sub cmdOK_Click()
'Call the Let Property procedure for
TankDataSource to set the TankDataSource property
TankDataSource = ExpressionEditor1.EditText
'Call the Let Property procedure for
TankContentsColor to set the TankContentsColor
property.
TankContentsColor = ColorButton1.Color
Unload Me
End Sub
1.4.6 Making Modifications to the Expression Editor
Control
There is one more design criteria that we have not accounted for. We only want
the Data Source tab to appear when the user launches Expression Builder with
the Expression Editor control. The Expression Editor control has the following
properties for this purpose:
? ShowDatabaseTab
? ShowGlobalsTab
? ShowHistoricalTab
? ShowPicturesTab
Knowing this, on the UserForm_Activate event, we can set the ExpressionEditor control to only show the Database Tab by setting all but the
ShowDatabaseTab properties to true. Now, the code behind the UserForm
Activate event looks like this:
Private Sub UserForm_Activate()
-
8/10/2019 Creating a Dynamo Through Scripting
18/30
18 Creating a Dynamo with VBA
'Initialize form interface
'Set up the Expression Editor tabs
ExpressionEditor1.ShowDatabaseTab = True
ExpressionEditor1.ShowGlobalsTab = False
ExpressionEditor1.ShowHistoricalTab = False
ExpressionEditor1.ShowPicturesTab = False
'Set the contents of ExpressionEditor1 equal to theTankDataSource property
ExpressionEditor1.EditText = TankDataSource
'Set the color of ColorButton1 equal to theTankContentsColor property
ColorButton1.Color = TankContentsColor
End Sub
The complete code for the form is as follows:
Option Explicit
Public Tank As Object
Public Sub InitializeDynamo(DynamoName As Object)
Set Tank = DynamoName
End Sub
Public Property Get TankDataSource() As String
Dim AnimatedTankLevel As Object
-
8/10/2019 Creating a Dynamo Through Scripting
19/30
Creating a Dynamo with VBA 19
Set AnimatedTankLevel = FindLocalObject(Tank,
"TankAnimatedVerticalFill")
TankDataSource = AnimatedTankLevel.Source
End Property
Public Property Let TankDataSource(DataSource As String)
Dim TankDataSource As Object
Set TankDataSource = FindLocalObject(Tank,"TankAnimatedVerticalFill")
TankDataSource.SetSource DataSource
End Property
Public Property Get TankContentsColor() As Variant
Dim TankCore As Object
Set TankCore = FindLocalObject(Tank, "TankMain")
TankContentsColor = TankCore.ForegroundColor
End Property
Public Property Let TankContentsColor(Color As Variant)
Dim TankCore As Object
Set TankCore = FindLocalObject(Tank, "TankMain")
-
8/10/2019 Creating a Dynamo Through Scripting
20/30
20 Creating a Dynamo with VBA
TankCore.ForegroundColor = ColorButton1.Color
End Property
Private Sub cmdCancel_Click()
Unload Me
End Sub
Private Sub cmdOK_Click()
'Call the Let Property procedure for TankDataSourceto set the
'TankDataSource property
TankDataSource = ExpressionEditor1.EditText
'Call the Let Property procedure for
TankContentsColor to set the
'TankContentsColor property.
TankContentsColor = ColorButton1.Color
Unload Me
End Sub
Private Sub UserForm_Activate()
'Initialize form interface
'Set up the Expression Editor tabs
ExpressionEditor1.ShowDatabaseTab = True
ExpressionEditor1.ShowGlobalsTab = False
ExpressionEditor1.ShowHistoricalTab = False
-
8/10/2019 Creating a Dynamo Through Scripting
21/30
Creating a Dynamo with VBA 21
ExpressionEditor1.ShowPicturesTab = False
ExpressionEditor1.EditText = TankDataSource
ColorButton1.Color = TankContentsColor
End Sub
1.5 Adding a Dynamo to a Dynamo Set
The final step in building a dynamo is adding it to a dynamo set so that you can
reuse it again and again. This process is very simple:
[1] Select New from the File menu. A drop down menu appears.
[2] Select Dynamo Set from the drop down menu. A new dynamo set iscreated.
[3] Save the dynamo set as MyDynamoSet.
[4] Drag the BigTank group that you created from the picture to the dynamoset.
[5] Save MyDynamoSet.
You have created a new dynamo in a new dynamo set. You could also have
added the BigTank group to an existing dynamo set.
-
8/10/2019 Creating a Dynamo Through Scripting
22/30
22 Creating a Dynamo with VBA
2. Advanced TopicsOnce you are comfortable with the concepts in creating a dynamo, you will
probably want to do something a little more complex. The following sections
show you how to:
Set an intelligent default for a data source when a user tabs off of the data
source field.
Fetch and set limits from a data source in your dynamos.
Use the Advanced Color Form in your dynamos.
Use the FIX Dynamics dynamo Color By form in your dynamos.
2.1 Setting Intelligent Defaults for Data Sources
Sometimes, a user may know the database tag they want to connect to without
launching the Expression Builder. The user may not want to type in the full
NODE.TAG.FIELD name especially if it is lengthy. By setting an intelligent
default for the data source, you can allow the user to type in only the tagname
and then automatically fill in the rest. In this section, we will add this
functionality to our Big Tank Dynamo.
All you have to do to add this useful functionality is to make a cal l to theGlobalSubroutine, FetchLimits. FetchLimits returns:
The High and Low EGUs of the specified data source along with the fully
qualified name for the data source. To add the call to your dynamo form:
[1] In the dynamo set you just created, MyDynamoSet, select the BigTankdynamo.
[2] Right mouse click and select the Edit Script command from the dropdown menu. The Visual Basic Editor appears.
[3] Double click on the frmBigTankDynamo form in the dynamo set projectto display your dynamo form.
[4] Double click on ExpressionEditor1 to get to theExpressionEditor_AfterKillFocus event.
[5] Enter the following code on this event:
Private Sub ExpressionEditor1_AfterKillFocus()
Dim strDataSource As String
Dim HiLimit As Single
-
8/10/2019 Creating a Dynamo Through Scripting
23/30
Creating a Dynamo with VBA 23
Dim LoLimit As Single
Dim err As Integer
strDataSource = ExpressionEditor1.EditText
Call FetchLimits(strDataSource, HiLimit, LoLimit,
err)
The FetchLimits subroutine returns the fully qualifiedstring name in the first parameter.
ExpressionEditor1.EditText = strDataSource
End Sub
2.2 Letting Users Set Input and Output Limits
If you plan to let your users select a data source, you may want to allow them to
set the input and output limits. The FetchLimits subroutine described in the
section above that allows you to do that. We will have to add some textboxes to
our form to display the input and output limits. In Visual Basic editor under
your dynamo set project, open up the frmBigTankDynamo again. Add frames,
labels, and text boxes as shown below:
-
8/10/2019 Creating a Dynamo Through Scripting
24/30
24 Creating a Dynamo with VBA
We will add this functionality to the ExpressionEditor_OnKillFocus event so
that when the user tabs off or exits this control after entering their database tag,
the input ranges automatically fill in. We add on to the code we entered in the
AfterKillFocus event as follows:
Private Sub ExpressionEditor1_AfterKillFocus()
Dim err As Integer
Dim HiLimit As Single, LoLimit As Single
Dim ds As String
ds = ExpressionEditor1.EditText
Call FetchLimits(ds, HiLimit, LoLimit, err)
If (err = 0) Then
txtLoIn.Value = LoLimit
txtHiIn.Value = HiLimit
OldDataSource = ds
ExpressionEditor1.EditText = ds
-
8/10/2019 Creating a Dynamo Through Scripting
25/30
Creating a Dynamo with VBA 25
If a valid data source does not exist, use the default
values of 0 and 100.
ElseIf (err = 2) Then
err = 0
End If
2.3 Validating a Data Source and Launching theFIX Dynamics Quick Add Dialog
You will notice that many of the FIX Dynamics standard dynamos allow you toadd tags to your data source while configuring the dynamo. You can easily
apply this functionality to your own dynamos by using the Global Function
QuickAdd. This function takes a data source string as a parameter and returns
an integer based on the state of the data source. If the data source does not exist
but can be created, the QuickAdd function launches the FIX Dynamics Quick
Add dialog allowing the user to add a tag to the database. The syntax for
QuickAdd is as follows:
QuickAdd (ByVal DataSource As String) As Integer
Example:Dim intTemp
intTemp = QuickAdd String name for data source
The return values are as follows:0 = OK. Data source exists.
1 = Invalid syntax for data source
2 = Data source did not yet exist. Quick Add dialog was launched and user
added a database tag.
3 = Data Type mismatch
4 = Data Source did not exist. User did not choose to add tag but chose to Use
Anyway
5 = Data Source did not exist. User did not choose to add tag or Use Anyway.
-
8/10/2019 Creating a Dynamo Through Scripting
26/30
26 Creating a Dynamo with VBA
2.4 Accessing a Dynamo from Outside its FormOne of the most important features of this method of developing dynamos is that
you can access the dynamos properties that you set up from outside the dynamo
and its form. For example, if you wanted to change a the tanks data source to
FIX32.FIX.AI1.F_CV and the tanks vertical fill color to red when you click
on a button in run mode, you could do the following:
[1] With the BigTank dynamo in a picture, insert a command button in thepicture.
[2] Right mouse click on the command button and select Edit Script. TheVisual Basic Editor appears.
[3] Enter the following code in buttons click event:
Private Sub CommandButton1_Click()
Initialize the BigTank dynamo object with the form.
frmBigTankDynamo.InitializeDynamo BigTank
Set the value for the BigTanks TankDataSourceproperty.
frmBigTankDynamo.TankDataSource = "FIX32.FIX.AI1.F_CV"
Set the value for the BigTanks TankContentsColor
property.
frmBigTankDynamo.TankContentsColor = 255
End Sub
[4] Switch to run and click the button. The fill color changes to red and thedata source is now FIX32.FIX.AI1.F_CV.
Remember that when you change properties of an object in run mode, the object
will only hold those properties during that run session. If you switch back toconfigure mode or exit the workspace, the properties return to their original
configuration.
-
8/10/2019 Creating a Dynamo Through Scripting
27/30
Creating a Dynamo with VBA 27
2.5 Using the Global Color By Form in DynamosIntellution provides a global Color By form that you can access and use with
your dynamos. The global Color By form lets you animate the color of a section
of your dynamo with a data source. It looks like and behaves like the Color
Expert in the Workspace. Many of the standard Intellution dynamos that are
animated (TanksAnim1, TanksAnim2, ValvesAnim, PipesAnim) use the globalColor By form for animating color. Lets go back to our BigTank form and add
in a control that allows us to animate the color of the top portion of the tank.
First, lets rebuild our dynamo:
[1] Open the MyDynamoSet dynamo set that you created then open a newpicture.
[2] Drag the BigTank dynamo from MyDynamoSet into the new picture.When the form appears, just click Cancel.
[3] Ungroup the dynamo and rename the pie object TankTop.
[4] Regroup the dynamo and rename it back to BigTank.
[5] Close MyDynamoSet.
Now, we will add the button that will launch the global Color By form to the
BigTanks form.
[1] Right mouse click on the BigTank dynamo in the picture and click EditScript. VBE appears.
[2] Double click on the frmBigTank form in the new pictures project. YourBigTank user form appears.
-
8/10/2019 Creating a Dynamo Through Scripting
28/30
28 Creating a Dynamo with VBA
[3] Reduce the size of the Tank Contents Color button and add a commandbutton and label as shown below. You will code the command buttonsclick event to launch the Color By form.
[4] Name the command button cmdColorby.
Now, to add the code that lets you access the global Color By form.
First, you will need to add the following variables to the General Declarations
section in the forms code:
frmDynamoColor - to be set to an instance of the Color By form
blnColorFormShow to determine if the Color By form has already been
launched.BlnColorFormCancel to determine if user selected Cancel in the Color By
form.
In the General Declarations section of the forms code, add:
Private blnColorFormShow as Boolean
Private frmDynamoColor As Object
Private blnColorFormCancel As Boolean
Private blnFormActivate As Boolean
Now, on the command buttons click event, enter the following code:
Private Sub cmdColorBy_Click()
Dim TopObj As Object
Dim blnHasConnection As Boolean
-
8/10/2019 Creating a Dynamo Through Scripting
29/30
Creating a Dynamo with VBA 29
Dim lngIndex As Long
Dim lngStatus As Long
'If the global ColorBy form has been activated, we don't
want activate it again.
If blnColorFormShow = False Then
'Set the flag as to whether the form was shown to Truethen, create a local instance of the DynamoColorBy form
blnColorFormShow = True
GetFormDynamoColor frmDynamoColor
End If
Set the object TopObj equal to the pie piece of theTank called TankTop.
Set TopObj = FindLocalObject(Tank, "TankT")
Initialize the TopObj to the Color By form.
frmDynamoColor.InitializeColorByForm TopObj, frmBigTank,blnColorFormCancel
frmDynamoColor.Show
End Sub
Because you have created an instance of the Color By form, you have to make
sure that you close it when you leave the dynamo form. Add the following to
the OK and Cancel button click events:
Private Sub cmdOK_Click()
'Call the Let Property procedure for
TankDataSource to set the TankDataSource property
TankDataSource = ExpressionEditor1.EditText
'Call the Let Property procedure for
'TankContentsColor to set the TankContentsColor
'property.
-
8/10/2019 Creating a Dynamo Through Scripting
30/30
30 Creating a Dynamo with VBA
TankContentsColor = ColorButton1.Color
'Check it an instance of the global Color By form was
created. If it was, unload it.
If TypeName(frmDynamoColor) "Nothing" Then
Unload frmDynamoColor
End If
Unload Me
End Sub
For the Cancel button:Private Sub cmdCancel_Click()
'Check it an instance of the global Color By form was
created. If it was, unload it.
If TypeName(frmDynamoColor) "Nothing" Then
Unload frmDynamoColor
End If
Unload Me
End Sub
Now, try out your addition.
[1] Reopen open your MyDynamoSet dynamo set and delete the old BigTankdynamo.
[2] Right mouse click in the dynamo set and select Edit Script. Make sureyou remove the old frmBigTank from the MyDynamoSet VBE project .
[3] Drag the new BigTank dynamo into the MyDynamoSet dynamo set.
[4] Open a new picture and drag the BigTank dynamo into the new picture.
[5] Set the Data Base Tag, the Tank Contents Color, and the Animate Tank
Top color animation.
[6] Switch to run mode to verify your results.