Maxscript Reference PDF
Maxscript Reference PDF
Introduction................................................................................................................................................................. 1-1
Overview....................................................................................................................................................................1-1
Creating a Display Containing Script.....................................................................................................................1-1
Creating Script Files...........................................................................................................................................1-2
Developing Script Using maxSCRIPT...................................................................................................................1-2
Using Dimension Statements .................................................................................................................................1-3
Using Local Variables........................................................................................................................................1-3
Reading and Writing from the Software Backplane...........................................................................................1-4
Performing External Writes ...............................................................................................................................1-4
Interacting with Other maxVUE Controls..........................................................................................................1-5
Writing Script Logic ..............................................................................................................................................1-6
Using Let and If, Else Commands......................................................................................................................1-6
Using the Bitmap Command ..............................................................................................................................1-7
Using Functions .................................................................................................................................................1-7
Using Special Variables .....................................................................................................................................1-8
Placing Scripts in Groups.......................................................................................................................................1-8
Making Scripts Portable Using Parameterization ..................................................................................................1-8
Specifying a Percent (%) Character .................................................................................................................1-10
Putting It All Together .........................................................................................................................................1-10
Reviewing maxSCRIPT Error Messages .............................................................................................................1-10
Writes to Constants Are Prevented ..................................................................................................................1-11
Using the maxSCRIPT Editor..............................................................................................................................1-11
Creating New Files and Projects ..........................................................................................................................1-12
Working with Projects .........................................................................................................................................1-12
Renaming the Project .......................................................................................................................................1-12
Adding Files.....................................................................................................................................................1-13
Renaming Files ................................................................................................................................................1-13
Editing Files.........................................................................................................................................................1-14
Enabling Standard Editor Options .......................................................................................................................1-14
Using Auto Complete.......................................................................................................................................1-15
Using Line Numbering.....................................................................................................................................1-16
Using Line Highlighting...................................................................................................................................1-16
Using Syntax Highlighting ...............................................................................................................................1-16
Formatting Files ...................................................................................................................................................1-17
Commenting and Uncommenting Text ............................................................................................................1-17
CHAPTER 2.......................................................................................................................2-1
CHAPTER 3.......................................................................................................................3-1
v
Preface
Audience
This publication is intended for process control and software engineers and
programmers involved with the design and development of human-machine
interface applications in a control environment.
Hidden Logic This has full Visual Basic capability, but in addition
to maxVUE, you must make a separate purchase of
the Visual Basic tools and have some knowledge of
the Visual Basic environment.
You may also add Visual Basic and C + + controls to maxVUE to add full-
blown programming capabilities to maxVUE, however, these options present
some obvious disadvantages.
Introduction
Overview
maxSCRIPT is an OCX Control that helps you design a custom display
within the maxVUE environment. Use maxSCRIPT for screen design
applications to incorporate customized logic not available from any of the
other existing standard controls.
maxSCRIPT uses a simplified Basic-like language that you can learn quickly
to create logical statements and perform simple calculations. One or more
instances of this control may be placed onto any maxVUE display.
Use the control to create local data and perform simple calculations using
live data. The results of the calculations can be displayed on the associated
display.
Color changes can be applied to other controls. For example, assume your
process contains a tank that is filled with a reagent that must be heated to
1000 degrees. Script logic could be used to change the color of the graphic
every 250 degrees. Logic could be set up as follows:
• Use the mouse to create and place the maxSCRIPT control object on
your display. You may scale the control to any size including full screen.
• Access the Script property page to create or edit the script file in a
maxSCRIPT Editor session. Use the Editor to create simple text files
with a default extension of .mxs.
An additional control property page called Default lets you define a bitmap
that you want to appear in the maxSCRIPT window to replace the standard
maxSCRIPT icon.
A script may be stored with a display if used only by that display. When you
intend to use scripts multiple times, they should be kept in the common area
c:\custom\database\scripts.
One Caution: if you use Notepad or another text editor to edit a script
outside of the maxVUE Editor, the old .mxo file will not be updated (the
maxSCRIPT Editor automatically deletes the .mxo file for you if you make
an edit). You can simply delete the .mxo file to cause a compilation to take
place the next time that the script is executed.
Note: scripts have no size limits (other than any editing utility size
limitations). Keep in mind, however, that as the script is compiled when the
display is called up, large scripts may effect display performance.
Where:
<alias> any string that uniquely identifies this value in the rest of the script
Example
Dim x as dbl
Dim x as int
Dim x as str
Where:
<alias> any string that uniquely identifies this value in the rest of the script
<service> any valid SBP service name
<extended member> any valid SBP extension
<type> consists of the following in and out types
xxxOut types create (and delete when the screen closes) an LSS object for
output (as well as input if necessary) so that other controls can access the
calculated results. A <service> is created for the purpose of housing outputs
in the Local Status Server. The same service can (and should) be used for
multiple members. The members can be of all different types.
Examples:
Example:
dimx s as strout(_sel_pt.tagname)
This lets you write to existing software backplane service members, such as
DPU point (service) attributes (members) and LSS service members, such as
_sel_pt.
The function of the x is to prevent the script from creating an _lss variable of
the name (<external name>.<external attribute>), which is deleted when the
script is terminated.
DIMX is only functional for dimension statements using out types as shown
in the following:
Example
Where:
Example:
Dim x as intctlout(object.x)
Dim y as intctlout(object.y)
Let y = 10
For example:
Let c = a + b.
The following script sample uses let and if, else expressions.
if ( AnyAlarm1 = 1 ) or (AnyAlarm2 = 1 )
let AnyAlarm = 1
Else
let Anyalarm = 0
EndIf
Bitmap "C:\custom\displays\operating\common\bmp\s-misc-1.bmp"
Using Functions
Functions are so called because they are used as a function of a variable in
an expression as in this syntax:
For example:
maxSCRIPT supports the functions listed in Table 1-1, which are also listed
in Chapter 3, "Using Special Functions."
The following sample script includes the RGB function. In this example the
RGB function changes the color of the caption text placed on a button based
on the state of the input BExp1. When the if statement becomes true, the
caption appears, assuming the color represented by "96,96,96". When the if
statement is not true, the RGB function generates a null string representing
no color, effectively canceling the button text.
If BExp1 = 1
If mousedclick
Let mousedclick = 0
let display = "popups\zpop-ct-dv2-o-s-c.mn
dp1=%param1%"
endif
See "Using Special Variables," in Chapter 3 for a listing of all the available
variables and their syntaxes.
Where scripts are included with a group, cutting and pasting the group will
also take the script reference along. Note in this case, multiple groups would
be using the same script. This is handy when you want to make global
changes to script logic that affect all instances.
Example
Dim p1 as dblIn(%param1%)
Dim p2 as dblIn(%param2%.ao)
Dim out as dblOut(%param3%)
Let out = p1 + p2
You must include the control in a group – even if it contains only a single
script item – to properly use parameters. If you edit the parameters of a
control not in a group, you will be editing the one and only set of default
parameters for the whole display.
Select Edit Group Parameters from the Group Menu to access the
Parameters Property Sheet.
Enter the point name to be used with the Parameter in the Parameter
Assignment field and a description for the parameter. A parameter may be
defined to be another parameter such as %DP1%. At run-time, maxVUE will
continue parsing the parameterized name until it has been resolved.
Now, you may create a display once and use it many times in many places. If
you define subsystems using hierarchical identifiers, for instance, you will
probably find yourself creating similar displays for multiple hierarchical
groups.
You are now free to copy the display containing the parameter names. At
runtime, maxVUE decodes the parameters it finds and inserts the actual
values.
Note: by using parameters for the outputs of the script, the same parameter
can be used for the script as is used for a Bar or a List Box insuring no
mistakes.
Dim x as dblin(test.op%%)
Bitmap "C:\custom\displays\operating\common\bmp\s-misc-1.bmp"
if ( AnyAlarm1 = 1 ) or (AnyAlarm2 = 1 )
let AnyAlarm = 1
Else
let Anyalarm = 0
EndIf
dim s as strin(_lss.time)
let s = "now"
This generates the following error message. The 3 indicates that the error
was detected at line three.
In another script example, the following contains a logic error that would
yield the erroneous result i = 2. maxSCRIPT diagnostic capabilities prevent
this from occurring.
dim i as int
let 1 = 2
let i = 1
From the File menu, point to New and click maxSCRIPT file.
To create a new project click 'New' then 'maxSCRIPT Project' under the File
menu or the <CTRL> + J shortcut key.
From the File menu, point to New and click Project to access the Create
Project dialog.
Enter a file name for the project, select a directory location, and click Save.
When you save the file, the Editor adds a *.msp to the file name.
When you create the project file, the Editor opens a properties window
containing a Windows Explorer style directory tree showing all the files in
the current project.
The files can be given a name to identify themselves in the project. Any
changes to the project will not be saved until Save Project is clicked under
the File menu.
Select the root file name, the topmost node in the project window, right
click and select Rename from the popup menu.
Renaming the project gives the project a name to identify itself and does not
change the actual filename.
Adding Files
To add a file to the project
Right-click anywhere in the project window and click Add, or click the Add
button on the project window toolbar.
Removing Files
right click on the file you wish to remove and click Remove, or click the
Remove button on the project window toolbar.
Renaming Files
To change the name of a file in the current project, select the file you wish to
rename, right click and select Rename from the popup menu. Renaming the
file simply changes the name to identify itself in the project and does not
change the actual filename.
Creating New Files To create a new maxSCRIPT file simply navigate the
File menu to New then maxSCRIPT File. You can also click the New button
on the toolbar or use the <CTRL> + N shortcut key.
New then maxSCRIPT Project under the File menu or the <CTRL> + J
shortcut key.
Editing Files
Cut, Copy, Paste Cut, copy, and paste functions can be accessed from the
Edit menu or by clicking their icons on the toolbar.
Undo and Redo Undo and redo can be accessed from the Edit menu or by
clicking their icons on the toolbar. Undo can also be accessed by using the
<CTRL> + Z shortcut key. You can undo and redo actions an unlimited
amount of times.
Find, find next and replace functions can be accessed from the Edit menu,
clicking their icons on the toolbar or using their <CTRL> + F, F3, and
<CTRL> + H shortcut keys respectively.
Selecting all text can be accessed from the Edit menu or by using the
<CTRL> + A shortcut key.
Auto complete
Line numbering
Line highlighting
Syntax highlighting
All of these features can be seen in the following picture of an edit window:
Select Options from the Tools menu to enable auto complete, if the feature is
not already enabled. From the Options dialog, check Auto Complete to
enable it. Uncheck the checkbox to disable the feature.
Inside the maxSCRIPT Editor window, press the period key <.> to access a
pop-up list of commonly used attributes.
As you continue to type as normal, the auto complete feature will select the
word it thinks you are typing.
Press the [TAB] or [SPACE] key or click the selection to finish the word.
Press the [ENTER] key to insert whatever word you have typed in the auto
complete box without finishing the word.
You may customize the auto complete attributes list to suit your specific
requirements.
Select MaxScriptEditor.txt from the Tools menu. When you edit the
MaxScriptEditor.txt file it will be placed in C:\Custom\Displays\
Select Options from the Tools menu to enable line numbering, if the feature
is not already enabled. From the Options dialog, check Line Numbering to
enable it. Uncheck the checkbox to disable the feature.
Press <CTRL> + G. to access the Goto Line dialog box , enter a line number
and click OK.
Select Options from the Tools menu and under line numbering, check Bold
or Italics.
Select Options from the Tools menu and check Line Highlighting to enable
the feature or uncheck the checkbox to disable the feature.
Select Options from the Tools menu and check Syntax Highlighting to
enable the feature or uncheck the checkbox to disable the feature.
Formatting Files
Commenting and Uncommenting Text
Rem
; Semicolon character
' apostrophe character
When maxSCRIPT is executed, any text beginning with the above characters
is ignored.
Place your cursor on the line to be commented and click the Comment button
on the formatting toolbar.
You may also select Comment Block from the Format pull-down menu or
press <CTRL> + I shortcut key.
Place your cursor on the line to be uncommented and click the Uncomment
button on the formatting toolbar.
You may also select Uncomment Block from the Format pull-down menu or
press < <CTRL> + U shortcut key.
Place your cursor on the line you wish to indent and click the Indent button
on the formatting toolbar.
You may also select Indent Text from the Format pull-down menu, or press
the <Tab> key.
Place your cursor on the line you wish to outdent and click the Outdent
button on the formatting toolbar.
You may also select Outdent Text from the Format pull-down menu, or press
<SHIFT> + TAB.
Clear Bookmark: to clear all the bookmarks in the current file click Clear
Bookmarks from the Format
Shortcut Keys
maxSCRIPT Editor has many shortcut keys that make it easy to access
common operations. The following table lists the default keystrokes and
their associated actions.
Creating maxSCRIPTs
Using Simple Examples
Getting Started
To use the maxSCRIPT control effectively you need to become acquainted
with the maxSCRIPT scripting language. This simple but powerful script
language consists of a relatively small number of commands, special
variables and functions that you may learn with ease. Script elements are all
listed in detail in the maxSCRIPT Script Language Reference Guide in
Chapter 3.
This chapter shows you how to create a few simple maxSCRIPT controls by
example in three introductory exercises. The first exercise shows you how to
display bitmaps based on the state of an analog output. A second exercise
shows you how to implement a similar maxSCRIPT using parameterization.
A third exercise demonstrates the use of the mouseclick variable.
The exercises are followed by four examples of script developed for real
applications by Metso Automation MAX Controls engineers. Each example
illustrates an aspect of script that you may implement when you compose
your own script files.
1. From the Start menu, point to Programs, maxDNA, Utilities, and click
TestSBP to open the TestSBP utility dialog display.
_lss.addsvc. fuel_flow.pid
4. Click the Apply button to add this simulated point to the Local Status
Server.
After you add fuel_flow.pid, follow the same steps to add the second
simulated point, air_flow.pid.
When you finish, you will have added two new services to the Local Status
Server. To confirm that the services were added, open the LLS dialog and
locate the two points you added under the service list. When you select any
of the points, a list of default attributes appears under the Member list,
including AO.
Note: when you close maxVUE and shutdown the maxSTATION, these two
services will be deleted from the Local Status Server.
2. Click the New tool button to access the file directory dialog box and
enter a file name, such as mydisplay.mn, or any name meaningful to you.
3. Click the maxSCRIPT Control tool button from the OLE Animator
tool bar. Place the cursor on the desired location on the screen and click
but do not release the button.
4. Drag the mouse to size the maxSCRIPT display window as desired and
release the button when satisfied with the dimensions. Remember this
will be the size and location of the bitmap window.
5. Click the Select tool button and click on the maxSCRIPT control
you just created to select it.
7. From the Script tab, click the New button to create a new script and
enter an appropriate name for the script. Create a file location under the
Custom directory such as c:\custom\database\scripts. Any additional
scripts that you create should be saved to this location.
9. From the maxSCRIPT Editor, enter the desired code and select Save
from the File menu when you are done.
10. From the Default tab, enter an image file or background color that you
want to appear in the control window to replace the standard icon that
appears when you first call out a maxSCRIPT instance.
This summarizes all the steps required to create a maxSCRIPT control. Now
you're ready to create scripts based on the examples outlined at the
beginning of this chapter. Refer to the next sections.
The script will consists of three common script language elements, the
dimension statement, If, Else conditional statements, and the bitmap
command. In addition to the maxSCRIPT pump control, you'll be creating
another maxSCRIPT control containing a button that calls out the control.
2. The rest of the script uses if, else conditional expressions that
incorporate bitmap commands as shown in the following figure:
3. Save the script file using maxSCRIPT Editor menu options. In our
example, the script is named 3-state-vlv.mxs.
In this suggested script, the following line contains the path name of the
target display:
2. Click anywhere on the logo screen (but away from the maxVUE logo
animation) to open the Main Menu display.
4. Select fuel_flow as the selected point and bring up the faceplate. Increase
or decrease the AO to within the valve condition values specified in the
maxSCRIPT. Are the Bitmaps changing based on the AO of the
specified tag?
1. From the maxVUE Editor open the display you created in Exercise 1.
2. Click the Select tool button and click on the maxSCRIPT control
you created in the previous exercise to select it.
5. From the Script tab, click the Edit button to select the script for the 3-
state valve condition you created earlier.
7. From the maxSCRIPT Editor File menu, save the script under a new
name, such as 3-state-vlv-param.
8. Click the Select tool button and click on the maxSCRIPT control
you created. Right-click to bring up Control Menu pop-up and select
Group from the context menu.
9. Select the Group, Create New Group – From Selected Objects option
to make the maxSCRIPT instance a group.
10. Select the Group, Edit Group Parameters option and edit the Param1
assignment to be Fuel_flow.
11. Now create a second instance of the script for the point air_flow. Click
the Select tool button and click on the maxSCRIPT control you
created in this exercise to select it. Copy and paste the maxSCRIPT
instance somewhere on the display.
13. Click the Save tool button to save the changes to your mydisplay.mn
display and close the maxVUE Editor.
2. Click anywhere on the logo screen (but away from the maxVUE logo
animation) to open the Main Menu display.
3. Edit the screen button you created in the previous exercise to display
swap to mydisplay.mn, and close the maxVUE Editor.
1. With the maxVUE Editor open on your display, click on the New
tool button to access the file directory dialog box and enter a file name,
such as mydisplay_exercise3.mn or any name of your choosing.
3. Drag the mouse to size the maxSCRIPT display window as desired and
release the button when satisfied with the dimensions. Remember this
will be the size and location of the navigation button.
4. Click the Select tool button and click on the maxSCRIPT control
you just created to select it.
6. From the Script tab, click the New button to create a new script and
enter an appropriate name for the script, such as display_swap.mxs.
Click the Save button to bring up the maxSCRIPT Editor.
7. From the maxSCRIPT Editor, enter the desired code and select Save
from the File menu when you are done. Create a file location under the
Custom directory such as c:\custom\database\scripts.
8. The first line of script uses the bitmap command to define the
background for the display button. Refer to the following figure:
9. The next two lines set up the conditions for the display swaps based on
the value of the mouseclick variable. Refer to the following figure:
10. The next line of script specifies the target display you wish to open with
a mouse click. Enter the name of an existing maxVUE display, such as
the displays you created in the previous exercises containing
maxSCRIPT controls.
Be sure the correct full file path and display name (including file
extension) is specified. The file path must begin after
C:\Custom\Displays\Operating. For example, Main\Mainmenu2.MN,
Boiler\Boiler.MN, Air\Air.MN, etc. Refer to the following figure:
11. End the condition (endif) and save the script file using the maxSCRIPT
Editor menu options.
2. Click anywhere on the logo screen (but away from the maxVUE logo
animation) to open the Main Menu display.
3. Click the navigation button you created to display swap to the target
display you specified in your script, such as mydisplay.mn or whatever
you chose to call it.
examples each incorporate some script coding ideas that you may want to
borrow when you create your own scripts.
Bitmap
C:\custom\displays\operating\common\bmp\hide_bitmap.bmp"
if ( AnyAlarm1 = 1 ) or (AnyAlarm2 = 1 )
let AnyAlarm = 1
Else
let Anyalarm = 0
EndIf
Bitmap
"C:\custom\displays\operating\common\bmp\hide_bitmap.bmp"
In this case, the bitmap is only use to hide the maxSCRIPT control on the
display. The bitmap command calls out a background color that is identical
to the screen display color, making the control blend in with its background
and disappear from view. This is a convenient way to hide the control when
it need not be visible, reducing screen clutter and confusion.
The next part of the script uses six dimension statements to read and write
values to the Local Status Server in the Software Backplane.
The first two dimension statements are reading two input values from the
parameterized tag names %param1%.out and %param2%.out.
The two inputs have two associated attributes for alarming called
AnyAlarm1 and AnyAlarm2. The following dimension statements are
reading these two values:
The script uses a Let statement to calculate an average for the two input
values, Input1 and Input2. The following dimension statement is used to
output the result of this calculation to a location in the Local Status Server
called %param1%_avg.out.
Finally, the script uses an If expression to test for an alarm state. The
expression states that if AnyAlarm1 or AnyAlarm2 enters a true state, then
let an output value, created in maxSCRIPT, called AnyAlarm equal 1. Using
a dimension statement, this value is then passed on to an output tag called
%param1%_avg.Anyalarm. This then activities a screen alarm indicator. See
the following dimension statement:
If dp1 = "OilSeqAF"
Let TitleTxt1 = "Oil Elevation A Front
Sequence"
Let TitleTxt2 = "Oil Elevation A Front
Sequence"
Endif
The script begins with two dimension statements that are writing to two
tagname.attribute locations in the Local Status Server called
Title/TitleTxt1.text and Title/TitleTxt1.text. Notice that the dimension
statement includes an x (dimx). This means the script assumes it is accessing
an existing variable, and does not need to create an object that is recreated
and deleted each time maxVUE is opened and closed.
The script logic following the dimension statement states that if a display is
accessed called "OilSeqAF," let the display title be "Oil Elevation A Front
Sequence."
'-------------------------------------------------
'This script hides the State2 command and feedback
'button when Numstate = 2.
'-------------------------------------------------
Dim Height_rectangle as
dblctlout(tank/State2rectangle.height)
Dim Height_button as dblctlout(tank/state2.height)
Dim Width_rectangle as
dblctlout(tank/State2rectangle.width)
Dim Width_button as dblctlout(tank/state2.width)
If Numstate = 2
let Width_rectangle = 0
let Width_button = 0
let height_rectangle = 0
let height_button = 0
endif
The pop-up as created contains three buttons that may be assigned different
functionality depending on the inputs the pop-up is currently referencing. In
certain specific instances, however, only two buttons are relevant to the
application that called the pop-up. The script shown here is designed to hide
the third button when an input indicates only two buttons are needed.
The script begins with several comment lines set off by the initial single
quote or apostrophe character. When the script is compiled, text strings that
follow a single quote are ignored. The comments summarize the purpose of
the script, which is to hide the Stated 2 command and feedback button when
an input called Numstate equals 2.
The script continues with a bitmap command that displays a pop-up display
file called S- popback-1.bmp.
The four other dimension statements define names to be used to write to the
size attributes of the State2 button. Note that the size attributes include a
rectangle that refers to the border surrounding the button.
Note: controls can be renamed using maxVUE Editor Layers button. Click
the Layers button, locate and select the control of interest, right-click and
select Rename from the menu and enter a new name. See discussion under
"Interacting with Other maxVUE Controls," in Chapter 3.
The logic that follows the dimension statements states that if Numstate reads
an input equaling 2 then write a zero to the size attributes of the button and
surrounding rectangle. This effectively makes the button and button border
disappear from the display when this script is in effect.
Note: when you select Test Mode in the maxVUE Editor, scripts can modify
the parameters of other unsaved controls, such as width, height, x or y, or
color. If you save the graphic after the script is run, these parameters changes
will be remembered. Be sure to save prior to testing to prevent this.
By using script this way, you create a single display that may be tailored for
multiple purposes, eliminating the need to create multiple displays designed
to anticipate very specific uses.
Bitmap "c:\custom\displays\operating\common\bmp\s-cb-a-
1.bmp"
fBitmap "c:\custom\displays\operating\common\bmp\s-cb-a-
1fl.bmp"
Bitmap "c:\custom\displays\operating\common\bmp\s-cb-a-
2.bmp"
fBitmap "c:\custom\displays\operating\common\bmp\s-cb-a-
2fl.bmp"
elseif DevState = 2
Bitmap "c:\custom\displays\operating\common\bmp\s-cb-a-
1.bmp"
fBitmap ""
elseif DevState = 1
Bitmap "c:\custom\displays\operating\common\bmp\s-cb-a-
2.bmp"
fBitmap ""
else
Bitmap "c:\custom\displays\operating\common\bmp\s-cb-a-
5.bmp"
fBitmap ""
endif
If mouseclick
Let mouseclick = 0
Let SelPt = "%param1%"
endif
If mousedclick
Let mousedclick = 0
let display = "popups\zpop-ct-dv2-o-s-c.mn dp1=%param1%"
endif
The script uses three dimension statements to define inputs for DevState,
Ovrd1, and Ovrd0. The logic that follows the dimension statements reads the
inputs for the above attribute values to determine which set of inputs makes
any of a series of if expressions true.
For instance if Ovrd1 = 1 and DevState = 2, then the script displays the
following two bitmaps using these path names:
"c:\custom\displays\operating\common\bmp\s-cb-a-
1.bmp"
"c:\custom\displays\operating\common\bmp\s-cb-a-
1fl.bmp"
The bitmap images are identical but use different shades of the color red.
The first bitmap uses a medium red and the second bitmap uses a dark red.
The first bitmap is called out using the Bitmap command, while the second
bitmap is called out using the fBitmap command. To create the illusion of a
single flashing image, the fBitmap command causes maxVUE in runtime
mode to display both bitmaps alternating in rapid succession.
Note that the script is written to display only one of two flashing bitmaps
when the proceeding if conditional logic is satisfied. The fBitmap command
is used in three other places in the script followed by a null text string as in
the following:
Bitmap "c:\custom\displays\operating\common\bmp\s-cb-a-
5.bmp"
fBitmap ""
When a script uses the fBitmap command, you must continue to use this
command in other places that call for a bitmap even when a flashing bitmap
is not desired. For instances where a flashing bitmap is not desired, use the
fBitmap "" script construct to nullify or cancel a flashing bitmap command.
Overview
The maxSCRIPT OCX control uses a Basic-like script language, allowing
you to create maxVUE display applications using a more free-form
programming approach. The script language, developed by Metso
Automation MAX Controls, uses elements, such as dimension statements,
commands, variables, and logical expressions, providing you with a rich
coding language. All the elements you may currently include in your script
files are listed in this reference chapter. Each of the following sections
describes the script element and its general syntax, and shows you how the
element is typically incorporated in script using basic examples.
Where:
<alias> any string that uniquely identifies this value in the rest of the script
<type> is from
Note when you first create them, double variable (0.0), integer variable (0)
and string variable (“”) begin as null values. The following technique can be
used to do something on the first pass only:
Example
Dim f as int
If f = 0
Let f = 1
…..do something
endif
Where:
<alias> any string that uniquely identifies this value in the rest of the script
<service> any valid SBP service name
<extended member> any valid SBP extension
<type> consist of the following in and out types:
In Types:
Out Types:
xxxOut types create (and delete when the screen closes) an LSS object for
output (as well as input if necessary) so that other controls can access the
calculated results. A <service> is created for the purpose of housing outputs
in the Local Status Server. The same service can (and should) be used for
multiple members. The members can be of all different types.
Examples:
Dim A as strout(_sel_pt.tagname)
has the unfortunate effect of deleting the selected point object when the
script is terminated. It is up to the script writer not to use existing local status
variable names in an xxxOut dimension. Instead, use <Scriptname>.out or
something similar.
A command is an action that takes place upon a write from the software
backplane. Although commands are not readable, you might write the same
value each time (0, for example).
Where:
<alias> any string that uniquely identifies this value in the rest of the script
<service> any valid SBP service name
<extended member> any valid SBP extension
<type> consist of the following out type:
Example
Without the use of the command statement, maxSCRIPT only writes the
value once, assuming nothing has changed since the last write. The
command statement, in effect, forces a demand write. maxSCRIPT will
perform the write regardless of what was written to this command the last
time, and it will not subscribe to the command to update current values.
Note that the maxSCRIPT variable Display (See Table 1-1 above) uses the
sCmdOut command statement on behalf of the user.
Note that normal outputs DO subscribe to values and can be used as inputs.
Example:
dim a as intout(test.out)
if a = 5
let a = 0
endif
dimx s as strout(_sel_pt.tagname)
When out types are used with the dimx command, an existing variable is
assumed (and not created or deleted).
The function of the x is to prevent script from creating an _lss variable of the
name (<external name>.<external attribute>), which is deleted when the
script is terminated.
Should you write a dimx statement for xxxIn types, the script will perform
like a dim statement without the x. The x is ignored for inputs.
Syntax
Where:
<alias> any string that uniquely identifies this value in the rest of the script
<service> any valid SBP service name
<extended member> any valid SBP extension
<type> is intout, dblout or strout
Example
Subscribe _KEYBOARD.BUFFER.<MASK>
M - ode
D - isplay
P- an
C - ursor
Z - oom
U - ser
L -ogic
S - etpoint
O - utput
A –alarm
For example:
_keyboard.respool
allows an application to throw back any keys that it is not interested in.
Intcmdout has a second feature. Since it does not subscribe to a value, it will
write the same value over and over again. The normal dimx output point will
not write unless a value is different from the last value received from a point.
If (key = 115)
Rem do f4 special processing
Endif
_keyboard.buffer.u
Unfortunately, this fragment has the side effect of intercepting all of the
User function keys. If this script is not capable of handling all of the keys it
has to put them back for the next subscriber. This is resolved in the next
example containing the Dimx respool statement.
If (key = 115)
Rem do f4 special processing
Else
Let respool = key
Endif
Finding Keycodes
Notice that the script in the preceding example references a specific function
key by its number code, 115. The following script can be used to find
keycodes:
Put this script on a graphic, with a single point displaying the integer at
test.out, and you will see keys as they are pressed. Notice that a key is
always followed by a zero around one second after the key has been pressed.
Where:
<xxx> is replaced by Dbl, Int or Str; note that the out types include the
characters ctl, indicating the script will interact with other controls. For
example, Dblctlout.
<object name> is the name of the object as seen and set in the Layers button
of the maxVUE Editor
<parameter> is from the list:
x - the x position
y - the y position
width - the width of the object
height - the height of the object
color - the color of the object
linecolor - the linecolor of the object
Example:
Dim x as intctlout(object.x)
Dim y as intctlout(object.y)
Let y = 10
Note: when you select Test Mode in the maxVUE Editor, scripts can modify
the parameters of other unsaved controls, such as width, height, x or y, or
color. Be sure to save any unsaved controls prior to testing to prevent this.
Color is best represented by a dbl value. The dbl value should be calculated
as:
intctlout(<controlname>.<attribute>)
dblctlout(<controlname>.<attribute>)
strctlout(<controlname>.<attribute>)
you need to know the name of the target control, which may be any available
maxVUE control, such as a Button Control, Box, and so forth).
1. Click the Layers Button to display the Edit Layers and Control Order
pop-up of the selected file.
2. When you access the Edit Layers and Control Order pop-up, display
objects appear in Folders, organized in a tree structure.
3. To change the default name to any name of your choosing, select the
object and right-click to bring up a pop-up menu. Click Rename from
the menu and enter a new name.
All Group Folders (except the root) may be renamed. The individual drawing
items within a Folder may also be rename. It IS OK that the names are not
unique when a group is copied and pasted. This function will first search for
a control within the group with <controlname>. It will then look at the next
level of grouping and so forth.
• Let
• If, else, etc
• Bitmap/fbitmap
• Play
• ToolTip
• Run
Where:
Example:
Bitand and bitor are used to AND or OR two operators together to produce
either a zero or non-zero result. Typically, one of the operators will be an
integer constant whose decimal equivalent is one or more bits set, while the
other is a multi-bit integer which is to be tested for the state of a bit buried
within the integer.
Example of use of bitand (example taken from the popup used for the Digital
Input Buffer); the goal of the code is to animate individual bits of a word;
thus, through parameters, this code is called 16 times in the Detail Popup.
Bitmap = "C:\mcs\displays\common\bmp\backgray.bmp"
Dim bn as Int
Dim bit as Int
Dim word as intin(%param1%.%param3%)
Dim start as intin(%param1%.BIT_NUM)
Dim bits as intin(%param1%.FIELD_SZ)
Let bn = %param2%
If <expression>
Else
ElseIf <expression> (Note one word)
Endif
Where:
Example
When you create the control in the maxVUE Editor, you may scale the
window to any size including full screen. The bitmap assumes the size of the
control window.
You can control how and when a bitmap or multiple bitmaps appear in run
mode using the bitmap instruction by itself or with additional script logic:
Bitmap “<expression>”
Where
Dim f as int
If f = 0
Let f = 1
Bitmap “c:\winnt\winnt.bmp”
Endif
bitmap "C:\winnt\winnt.bmp"
fbitmap "C:\winnt\winnt256.bmp"
fbitmap ""
You can reset the name of the normal bitmap and flashing bitmap at anytime.
play "c:\winnt\media\start.wav"
To create a ToolTip that displays the last error message for the maxSCRIPT
control, combine the ToolTip command with the Error variable. See "Using
the Error Variable," in the following section.
If MouseClick
Let MouseClick = 0
Run "c:\Mcs\Report\ReportControlPanel.exe,Reports Control Panel"
Endif
The Window Title may include the wild card character (*) to match multiple
characters, or the position wild card character (?) to match any character in a
position:
If MouseClick
Let MouseClick = 0
Run "C:\Winnt\System32\mspaint.exe,*paint"
Endif
• Display
• Mouseclick, Mousedclick, Mouserclick
• Error
If mouseclick = 1
Let mouseclick = 0 ;need to reset it
……
Endif
tooltip error
will copy the last error to ToolTip. Error can be set by applications
software:
Note the units of row and col are percent of the graphic and can be placed
into x and y directly.
Example:
ABS(Expression)
Example:
Dim dev as dbl
Dim pv as dblin(tagname.pv)
Dim sp as dblin(tagname.lsp)
Let dev = abs(pv-sp)
Example:
dim i as intout(script.int)
dim s as string
let s = "The " + asc(i) + "time"
Note there are no errors. Asc will truncate all numbers from 0 to 255 without
raising an error.
Example:
The ASK function places a message popup in front of the operator so that
the operator can make a decision. The operator must always answer the
message popup.
Yesno: the operator will be asked yes or no to answer a question. The result
will be 1 if the operator clicks on Yes, or 0 if the operator clicks on No.
Input: the operator will be asked to enter a string variable, which will then
be placed in the result.
Alert: the operator will merely have to acknowledge the popup; no result
will be returned.
Where
<popup caption> would be replaced by the title of the message box, such as
Add Trend Point
dim s as strin(_sel_pt.tagname)
dim d as str
if mouseclick
let mouseclick = 0
if s <> ""
let d = p_control(s)
if d <> ""
let d = d + " dp1=" + s
let display = d
else
ask "Selected Point Not Recognized|No Control popup|alert"
endif
endif
endif
tooltip "Click to call up a Point Control popup for the selected
point. Note - You must Select a point first."
In this example, the code generates an alert-type message box, with text
message Selected Point Not Recognized, and with title No Control popup, if
the p_control function does not return a display name.
Here is another example. Using this fragment, an operator can, using ASK,
call up a trend, and then enter a tagname and an attribute to be trended. An
alternative method to calling up the Trend Attributes popup.
Before using an AVI it must be loaded. In the following example, this script
is used to load an AVI called clock:
avi <frame>
Frame Rate
The frame rate for new frames is 1/2 second. For example, the following
code will display the frames 1,2,3,5,7 in sequence at a rate of 1/2 second.
if gonow
let gonow = 0
avi 1
avi 2
avi 3
avi 5
avi 7
endif
Example:
Put a list control with two entries (writes on junk.in) and you can type in a
string (%param1%.%dp1%) and see what it gets expanded to.
Dim s as str
dim d as dbl
Dim i as intin(test.in)
let s = "%%"
if i = 0
let s = s + "fic101"
elseif i = 1
let s = s + "lic101"
endif
let s = s + ".pv%%"
let d = exp(s)
Note the double parenthesis characters (%%) are used because lines of script
are pre-expanded prior to compilation. %% expands to a %.
NOT (Expression)
Example:
if not (a = b)
The function references a database file listing all known object types and
their associated point detail and point data pop-up displays by specific file
name. All objects in systems from MAX1 through maxDNA have an object
type such as PID, SUMMER etc. This file is located in:
C:\custom\displays\operating\database\typemap.mdb
The database file table consists of the following columns, which can be
filled in:
PointDataPopup
PointDetailPopup
PointControlPopup
UserDefined1
UserDefined2
UserDefined3
UserDefined4
Help
Note: The only ones in service for maxDNA are PointDataPopup and
PointDetailPopup.
Where
Example
Note that the temporary string ‘s’ is used to compute the string consisting of
the object type and the column to be accessed separated by the vertical bar.
Objmap will return an error message in the string should an object type not
be found, or the column name not be found. In addition, you can test the
quality of an Objmap function to determine if the lookup is successful:
Example
If qua(objmap(“%_sel_pt.forward.objtype%” +
“|PointDataPopup”)
…
endif
For DBM-based points, the TypeMap.mdb database file is searched for the
name of a popup, which will typically come from either
C:\Mcs\Displays\Mn\PointData folders, or C:\Mcs\Displays\Mn\PointDetail
folders (but, of course, it is possible for you to create a modified set of
displays in the Custom path, after modifying the TypeMap.mdb file).
For DPU4E-based points, the Point Control popups will typically come from
C:\Mcs\Displays\Popups\dpmsxxx folders (where xxxx is the name of an
atomic block), while the Point Detail popups will typically be the
PtDetailsTabular.mn display (looks like the Point Browser), although you
could create custom Control or Detail popups which would be stored in the
C:\Custom\Displays\Operating\Popups path.
For DPU4E-based atomic blocks, the display names are always going to be
stored in a folder C:\Custom\Displays\Operating\Popups\<objname>, with
file name either <objname>-control.mn or <objname>-detail.mn. For
example:
The MAMC-supplied Point Control popup for the Atag atomic block is:
C:\Mcs\Displays\Mn\Popups\dpmsATAG\dpmsATAG-control.mn.
C:\Custom\Displays\Operating\Popups\dpmsATAG\dpmsATAG-control.mn.
These path and file names are the template for what you would use if you
had created your own DPU4E Custom Function Blocks, and wanted to
provide them with either a Control or Detail popup.
dim s as strin(_sel_pt.tagname)
dim d as str
if mouseclick
let mouseclick = 0
if s <> ""
let d = p_control(s)
if d <> ""
let d = d + " dp1=" + s
let display = d
else
ask "Selected Point Not Recognized|No Control popup|alert"
endif
endif
endif
tooltip "Click to call up a Point Control popup for the selected
point. Note - You must Select a point first."
The variable s contains the tagname of the selected point. The variable d
contains the path and name of the popup found by p_control.
Example:
dim s1 as strin(input1.tagname)
dim s2 as strin(input2.tagname)
dim same as int
if s1 = s2
let same = 1
endif
s1 = s2
If any variable in a calculation is bad (timed out, tag not found, data not
available yet) the result is zero or false. So the above program will work.
There are still situations where it would not as in the following example:
To be absolutely sure the data is good incorporate the Qua function in scripts
as shown in the following example:
dim s1 as strin(input1.tagname)
dim s2 as strin(input2.tagname)
dim same as int
if qua(s1 = s2)
if s1 = s2
let same = 1
endif
endif
Note: the Qua function is performed on the result of the calculation s1 = s2.
The result is thrown away.
Caution: some scripts that used to operate under Release 1.6.4 may operate
differently under Release 1.6.5 due to the introduction of quality. In the first
example, your program may depend on falling through the comparison (even
though it is an error to do so)!
RGB ("r,g,b")
Example:
dim c as dblctlout(box.color)
let c = rgb "255,0,128"
The following example sets a full red, no green and half-blue intensity. RGB
returns a double and can be stored in any dbl variable.
Example:
dim c as dblctlout(box.color)
dim d as dbl
let d = rgb "255,0,128"
let c = d
You may use the RGB function with the color and linecolor attributes of a
control using this syntax:
The following script should popup the point picker on a mouse click:
If mouseclick
Let mouseclick = 0
SendMsg “Point Picker WakeUp”
Endif
SVC ("service.member")
Example:
Example:
dim i as int
dim s as strout(script.txt)
let i = val(s) 'convert an input string into a number
Note there are no errors reported. Val will convert as many characters as are
appropriate and stop without error in any case.
Example:
Note that the “_scr” addition to one of the driving tagnames creates a
somewhat unique place in which to store the output of the script.
Without the declaration of dummy, the above script will only execute when
the out subscription times out..
Rem
; Semicolon character
' apostrophe character
When maxSCRIPT is executed, any text beginning with the above characters
is ignored.