0% found this document useful (0 votes)
88 views

GraphWorX32 - Getting Started With Scripting

The document provides an introduction to scripting in GraphWorX32 and examples of runtime and configuration scripts. It also demonstrates how to read from and write to process points, and how to use automation with ActiveX controls.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
88 views

GraphWorX32 - Getting Started With Scripting

The document provides an introduction to scripting in GraphWorX32 and examples of runtime and configuration scripts. It also demonstrates how to read from and write to process points, and how to use automation with ActiveX controls.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

GraphWorX32 – Getting Started with

Scripting
October 2013

Description: Guide to scripting in GraphWorX32. MsgBox "Hello World"


OS Requirement: Win 2000, XP Pro, Server 2003, Vista,
Server 2008, Windows 7 5. Close the Microsoft Visual Basic window and double-click
General Requirement: Familiarity with GraphWorX32 and on the rectangle object while still in configure mode. Your
scripting in general. message will appear.

NOTE: The rest of the examples in this application note will be


Introduction runtime scripts.

Automation can be a powerful tool to expand the abilities of Reading from and Writing to a Process Point
your application beyond the standard functions of
GraphWorX32. You can find examples of scripting within The simplest way to read from or write to an OPC tag is to use
GraphWorX32 in the C:\Program Files\ICONICS\ automation for the GraphWorX32 Process Point object. This
GENESIS32\Examples\GraphWorX32\OLE Automation method lets GraphWorX32 do all of the work actually getting
directory in a standard GENESIS32 installation. This document the value of a tag. This script will simply manipulate the value
will introduce you to the basics of scripting in GraphWorX32 that GraphWorX32 has already received from the OPC server.
and some commonly used automation calls.
1. We need to add a process point to our display before we
Runtime and Configuration Scripts write any scripts. In GraphWorX32, go to Dynamics 
Intrinsics  Process Point… or click on the button in
In GraphWorX32, you can execute scripts both from runtime the dynamics toolbar. Click on your display to add the
and from configure mode. Runtime scripts are the most common. process point.
To create a runtime script, follow the steps below.
NOTE: The process point needs to exist on the display for this script
to work, but it needs not to be visible to your users. You can put the
1. Add a button to a new GraphWorX32 display. point on a hidden layer, behind another object, or even use a hide
2. Select “Run Script” as the Action. dynamic if desired.
3. Hit the “Create” button, type “Runtime” into the Script
Name field, then hit OK. 2. Click on the “Data Tags” button and select the OPC tag that
4. Between the “Sub Runtime” line and the “End Sub” line, you would like to manipulate with your script. When you
type this simple script: are done configuring your process point, click on “OK”.

MsgBox "Hello World" NOTE: You can use local variables too!

3. In your script, use the “GetPointObjectFromName” method


5. Close the Microsoft Visual Basic window and put the
to create a link to the process point we just created. The
display into runtime. Click the button to see your message
path to your tag in the script must match the path to your
box.
tag in the process point exactly when in runtime. In most
cases, it’s easiest to copy the text from the Data Source
Configuration mode scripts are often used to create wizards that field of the process point and paste it into your script.
can build displays automatically. There are examples of such
Here is an example:
wizards in the “3_ScriptWizards” symbol library. (To open the
symbol library from GraphWorX32, go to View  Toggle Set ppt =
Symbol Toolbar.) You can drag these symbols onto your display ThisDisplay.GetPointObjectFromName("ICONICS.Simula
and double-click them in configuration mode to create a variety tor.1\SimulatePLC.OUTPUTS.FLOAT")
of objects.
NOTE: The code above must be all on one line to be properly
formatted. If you are using aliases, you cannot simply copy and paste.
To create a configuration mode script, follow the steps below. If you have aliases in your process point, you must resolve those
aliases within the script as well, or the script’s path will not match the
1. Add a rectangle to your display. process point’s path.
2. Right-click on the rectangle and select “Create VBA Script”.
3. In the Script Name field, type “Configure”, then hit OK. 4. Now in your script “ppt.Value” will equal the value of the
4. Between the “Sub Configure” line and the “End Sub” line, process point on your display. It is writeable, so you may
type this simple script: set “ppt.Value” equal to some number if your script

Copyright 2013 ICONICS, Inc. Page 1 of 2 GraphWorX32 - Scripting Getting Started.doc


GraphWorX32 – Getting Started with
Scripting
October 2013

requires it. Set oleObject = ThisDisplay.GetVisibleObjectFromName(


"awxViewer").GetOleObject
Here is the example extended:
NOTE: The code above must be all on one line to be properly
Dim x as Integer
formatted.
Dim y as Integer

Set ppt = 5. There are many helpful examples of scripting using


ThisDisplay.GetPointObjectFromName("ICONICS.Simula ActiveX automation in the Symbols Toolbar. Open the
tor.1\SimulatePLC.OUTPUTS.FLOAT") symbols toolbar by going to View  Toggle Symbol
x = ppt.Value ‘store the value Toolbar or clicking on the button in the Draw toolbar.
x = 10 + x ‘modify the value
ppt.Value = x ‘write the value back The ActiveX scripts can be found in 3_ScriptWizards/VB
Script Wizards.sdf. Drag a wizard button onto you display
and double-click it to generate the example scripts.
How to Use Automation with an ActiveX NOTE: For more information on the Symbols Toolbar, please refer
to the application notes GraphWorX32 – Using the Symbols Library
There are many useful automation methods included with and GraphWorX32 – Script Wizard Help.
ActiveX controls, but how to create an object from an ActiveX
to use such methods is not always obvious. Here is the proper Discovering Automation Methods
way to create a link to your ActiveX objects in your script.
NOTE: This method will work for both, ICONICS ActiveX controls
A valuable resource for scripting is the Object Browser feature
and third-party ActiveXs. of the Visual Basic Editor. Whether you are using VBScript or
VBA, the Object Browser can be used to look up all the
1. Add the desired ActiveX to your display. available methods for a given object.
2. In configure mode, right-click on the ActiveX and select
“Application Property Inspector”. 1. Open the Visual Basic Editor from GraphWorX32 by going
to Tools  Macros  Visual Basic Editor or hitting Alt-
F11.
2. Open the Object Browser by going to View  Object
Browser, hitting F2, or clicking on the button in the
toolbar.
3. From here you can browse or search all of the classes and
methods available to you in your current libraries. To limit
your search to a specific library, select it from the top drop-
down list. If a library you want to look at is not listed, you
can add it by going to Tools  References. The libraries
Figure 1 - Application Property Inspector
for an ActiveX will be added automatically if the ActiveX
is added to your display.
3. In the Object Name field, give your ActiveX a name. We
will use this name in our script to get this ActiveX NOTE: Most, but not all automation methods listed in the Object
specifically. Browser are also available in VBScript.

4. Another useful tool for finding automation methods is the


GENESIS32 - OLE Automation References document,
located on your installation disc or in the Documentation
section of our website.
Figure 2 - Object Name 5. You can also find some helpful tips in the GenBroker –
OLE Automation Support Application Note, also located on
4. Now we can use the “GetVisibleObjectFromName” and your CD or in the Application Notes section of our website.
“GetOleObject” methods to get the OLE object from the
display. In the example below, any automation methods for
the ActiveX can be called from oleObject.

Copyright 2013 ICONICS, Inc. Page 2 of 2 GraphWorX32 - Scripting Getting Started.doc

You might also like