Maxscript Ch01 Introduction PDF
Maxscript Ch01 Introduction PDF
278588
Metso Automation
1- 1
278588
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.
maxSCRIPT is an ideal way to create screen animations, such as an icon
that changes color based on values obtained from multiple comparative
inputs. For instance, use maxSCRIPT to create a pump icon. The valve
on the pump may then be programmed to change color based on a given
state, such as on, off, idle, broken, etc.
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:
Degrees
0 - 250
251 - 500
501 - 750
751 - 1000
Color of Tank
Blue
Yellow
Cyan
Red
Metso Automation
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.
1- 2
278588
Metso Automation
1- 3
278588
dblQ
intQ
strQ
Example
Dim x as dbl
Dim x as int
Dim x as str
Metso Automation
1- 4
278588
DblInQ
IntInQ
StrInQ
xxxOut types create (and delete when the screen closes) an LSS object
for output (as well as input) 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.
Note that although the xxxOut variable is being created for writing, the
current value of the variable is available to the script for internal
calculations.
DblOut
IntOut
StrOut
DblOutQ
IntOutQ
StrOutQ
Examples:
Metso Automation
1- 5
278588
IntOut(<external name>.<external
DblOut(<external name>.<external
StrOut(<external name>.<external
IntOutQ(<external name>.<external
DblOutQ(<external name>.<external
StrOutQ(<external name>.<external
Example:
Dimx selpt as StrOut(_sel_pt.tagname)
Let selpt = fic101
Metso Automation
1- 6
278588
Intctlout
Strctlout
Example:
Dim y as IntCtlOut(object.y)
Let y = 10
Your script should include one of the following in types
DblctlIn
Metso Automation
1- 7
278588
Intctlin
Strctlin
Example:
Dim tag as StrCtlIn(object.Top1Tag)
Dim outTag as StrOut(msg.outTag)
Let outTag = tag
Variables
Display
Mouseclick
Mouserclick
Mousedclick
Mouserow
Mousecol
Error
Functions
ABS; Absolute Value
ASC; convert number to ASCII character
AVI; specify and display frames
EXP; expand parameters in real time
NOT; Logical Negation
OBJMAP; perform lookup in typemap database
QUA; checking variable quality
SVC; select a service
TRANS; enable dual language translator
RGB; calculate a color
VAL; convert ASCII string to double
ASK; prompt operator to respond to a popup
SendMsg; send windows message
P_CONTROL; output point control popup
P_DETAIL; output point detail popup
SbpQuality; retrieve SBP data quality
SimplifiedQuality; retrieve simplified SBP data
quality
Metso Automation
1- 8
278588
"C:\custom\displays\operating\common\bmp\s-misc-
SBP_QUALITY_GOOD
SBP_QUALITY_DOUBTFUL
SBP_QUALITY_SUBSTITUTE
SBP_QUALITY_BAD
For example:
Dim value as DblOutQ(MyTag.value)
Let value = 100.0
SbpQuality value = SBP_QUALITY_DOUBTFUL
Metso Automation
1- 9
278588
Using Functions
Functions are so called because they are used as a function of a variable
in an expression as in this syntax:
Let variable = function argument
For example:
Let x = ABS (4)
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
Let ButtonTxtColor1 = RGB "96,96,96"
Else
Let ButtonTxtColor1 = RGB "0,0,0"
Endif
1- 10
278588
p1 as DblIn(%param1%)
p2 as DblIn(%param2%.ao)
out as DblOut(%param3%)
out = p1 + p2
Metso Automation
1- 11
278588
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 in
the same Group insuring no mistakes.
Metso Automation
1- 12
278588
"C:\custom\displays\operating\common\bmp\s-misc-
Metso Automation
1- 13
278588
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
Metso Automation
1- 14
278588
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
Metso Automation
1- 15
278588
Removing Files
To remove a file from the current project:
right click on the file you wish to remove and click Remove, or click the
Remove
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 and Projects
maxSCRIPT Editor allows you to create individual maxSCRIPT files or
a maxSCRIPT project that can be used to group common or relevant files
in an orderly manner.
Editing Files
Cut, Copy, and Paste functions can be accessed from the Edit menu or by
clicking their icons on the toolbar.
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.
Metso Automation
1- 16
278588
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.
Metso Automation
1- 17
278588
Metso Automation
1- 18
278588
Select Options from the Tools menu and check Line Highlighting to
enable the feature or uncheck the checkbox to disable the feature.
Formatting Files
Commenting and Uncommenting Text
Metso Automation
1- 19
278588
Toggling Bookmarks
To toggle a bookmark at the current line click Toggle Bookmark from
the Format menu. Bookmarks allow you to quickly access specific lines
of text. You can make as many bookmarks you want in the opened file
but will not be retained after closing and opening the file again. If youre
using maxVUE Editor to create process graphics and a maxSCRIPT error
is generated, the maxSCRIPT file will be opened in maxSCRIPT Editor
with a bookmark at the line with the error.
Moving through Bookmarks: to move between bookmarks click Next
Bookmark or Previous Bookmark from the Format menu or use the F2
and <SHIFT> + F2 shortcut keys respectively.
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.
New maxSCRIPT File
Open maxSCRIPT File
Save File
Metso Automation
Ctrl-N
Ctrl-O
Ctrl-S
1- 20
278588
New Project
Ctrl-J
Open Project
Ctrl-R
Print
Ctrl-P
Cut
Ctrl-X
Copy
Ctrl-C
Paste
Ctrl-V
Select All
Ctrl-A
Select Line
Ctrl-Alt-F8
Undo
Ctrl-Z
Next Word
Ctrl-RightArrow
Previous Word
Ctrl-LeftArrow
Delete Next Word
Ctrl-Delete
Delete Previous Word
Ctrl-Backspace
Document Start
Ctrl-Home
Document End
Ctrl-End
Comment Block
Ctrl-I
Uncomment Block
Ctrl-U
Indent
Tab
Outdent
Shift-Tab
Convert to Lowercase
Ctrl-L
Convert to Uppercase
Ctrl-K
Create New Line (above)
Ctrl-Shift-N
Next Bookmark
F2
Previous Bookmark
Shift-F2
Find
Ctrl-F
Find Next
F3
Find Previous
Shift-F3
Replace
Ctrl-H
Goto Line
Ctrl-G
Goto Matching Brace
Ctrl-]
Set Repeat Count
Ctrl-R
Toggle Whitespace Display
Ctrl-Alt-T
Insert File Path from Dialog
Ctrl-F1
Scroll Window Down
Ctrl-UpArrow
Scroll Window Up
Ctrl-DownArrow
Scroll Window Left
Ctrl-PageUp
Scroll Window Right
Ctrl-PageDown
Help
F1
Note: Holding down shift when using any of the navigational shortcut keys will
select any text that the cursor moves through.
Metso Automation
1- 21