The example in this section shows you how to animate an object through a VBA script; specifically, animating the rotation of a rectangle named Rect1. The code is taken directly from the iFIX Rotate Expert.
For this example, you need to provide operators with an interface in the configuration environment which allows them to animate the rotation of the selected object. You also need to allow them to select a data source with the Expression Editor control. For this example, assume that the operators will select a database block as their data source. You also want to allow them to select the minimum and maximum input and output values. After applying this form to a selected object, the operator can switch to run and see the object rotating as specified.
First, develop the basic form as shown in the following figure:
Rotate the Selected Object Dialog Box
The following script is intended for the OK button's Click event. The script creates an animation object, connects the animation object to the data point, and then connects the animation object to the selected shape. See the Creating Pictures manual for more information on Animation objects.
Example: Animating the Rotation of an Object
Private Sub cmdOK_Click()
Dim CurrentObject as Object
Dim RotateObject As Object
Dim i As Integer
Dim blnHasConnection As Boolean
Dim lngIndex As Long
Dim lngStatus As Long
Dim strFullName As String
Dim Result As Boolean
Dim FailedSourceString As String
Dim strPropertyName As String
Dim strFullQualifiedSource As String
Dim strExpression As String
Dim strFullyQualifiedExpression As String
Dim vtSourceObjects
Dim dblTolerance As Double
Dim dblDeadband As Double
Dim dblUpdateRate As Double
On Error GoTo ErrorHandler
'Set CurrentObject equal to the first selected object in
'the picture.
Set CurrentObject = _
Application.ActiveDocument.Page.SelectedShapes.Item(1)
'Check if the selected object's RotationAngle property is
'already connected to a datasoure using the IsConnected
'method.
CurrentObject.IsConnected "RotationAngle", blnHasConnection, lngIndex, _
lngStatus
'If it is, use the GetConnectionInformation method to get
'the fully qualified name of the data source as well as the
'data source object.
If blnHasConnection Then
CurrentObject.GetConnectionInformation lngIndex, _ 0
strPropertyName, strExpression, _
strFullyQualifiedExpression, vtSourceObjects
'vtSourceObjects is a variant array of the data source
'objects connected to the RotationAngle property of the
'selected object. Get the first object in the array.
'Assume that the first object connected to the
'RotationAngle is the one you want.
Set RotateObject = vtSourceObjects(0)
End If
'If a rotation connection does not exist, build an empty
'linear animation object off of the current object.
If (TypeName(RotateObject) = "Nothing") Then
Set RotateObject = CurrentObject.BuildObject("Linear")
End If
'Use the SetSource method to connect the Animation object to
'the data source object that the user entered in the Expression
'Editor. This connection overwrites any existing Rotation set
'up.
RotateObject.SetSource ExpressionEditor1.EditText, True, _
ExpressionEditor1.RefreshRate, ExpressionEditor1.DeadBand, _
ExpressionEditor1.Tolerance
'Check the Animation object's ConnectionFailed property. If the
'connection failed, send a message to the user.
If RotateObject.ConnectionFailed = True Then
FailedSourceString = "Data Source: " & _
RotateObject.FailedSource & " doesn't exist."
Result = MsgBox(FailedSourceString, vbOKOnly)
Exit Sub
End If
'Now, we can set the LoInValue, HiInValue, LoOutValue, and
'HiOutValue of the Animation object with the values the user
'entered in the form.
RotateObject.LoInValue = Val(txtLoIn.Value)
RotateObject.HiInValue = Val(txtHiIn.Value)
RotateObject.LoOutValue = Val(txtMinAngle.Value)
RotateObject.HiOutValue = Val(txtMaxAngle.Value)
'We connected the InputValue property of the Animation object
'to the data source. Animation objects receive their input
'from sources. Now, we will connect the Animation object's
'OutputValue property to the shape. It's output is connected
'to the object it is animating.
strFullName = RotateObject.FullyQualifiedName & ".OutputValue"
CurrentObject.Connect "RotationAngle", strFullName, lngStatus