278588 maxscript a

Upload: trung2i

Post on 03-Feb-2018

221 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/21/2019 278588 Maxscript A

    1/77

  • 7/21/2019 278588 Maxscript A

    2/77

  • 7/21/2019 278588 Maxscript A

    3/77

    ContentsPREFACE............................................................................................................................III

    How This Book Is Organized ..............................................................................................................................iiiAudience..............................................................................................................................................................iiiUsing Online Help ...............................................................................................................................................iiiUsing Other Programming Facilities...................................................................................................................iii

    CHAPTER 1...................................................................................................................... 1-1

    Introduction .................................................................................................................................................................1-1Overview ...................................................................................................................................................................1-1

    Creating a Display Containing Script ....................................................................................................................1-1Creating Script Files ..........................................................................................................................................1-2

    Developing Script Using maxSCRIPT ..................................................................................................................1-2Using Dimension Statements.................................................................................................................................1-3

    Using Local Variables .......................................................................................................................................1-3Reading and Writing from the Software Backplane..........................................................................................1-3Performing External Writes...............................................................................................................................1-4Interacting with Other maxVUE Objects...........................................................................................................1-5

    Writing Script Logic..............................................................................................................................................1-6Using Let and If, Else Commands.....................................................................................................................1-7Using the Bitmap Command..............................................................................................................................1-7

    Using Functions.................................................................................................................................................1-7UsingSpecial Variables.....................................................................................................................................1-8

    Placing Scripts in Groups ......................................................................................................................................1-8Making Scripts Portable Using Parameterization..................................................................................................1-9

    Specifying a Percent (%) Character.................................................................................................................1-10Putting It All Together.........................................................................................................................................1-10Reviewing maxSCRIPT Error Messages.............................................................................................................1-11

    Writes to Constants Are Prevented..................................................................................................................1-11Using the maxSCRIPT Editor .............................................................................................................................1-11Creating New Files and Projects..........................................................................................................................1-12Working with Projects.........................................................................................................................................1-12

    Renaming the Project.......................................................................................................................................1-13Adding Files ....................................................................................................................................................1-13

    Renaming Files ................................................................................................................................................1-13Editing Files.........................................................................................................................................................1-14Enabling Standard Editor Options.......................................................................................................................1-14

    Using Auto Complete ......................................................................................................................................1-15Using Line Numbering ....................................................................................................................................1-16Using Line Highlighting..................................................................................................................................1-16Using Syntax Highlighting ..............................................................................................................................1-16

    Formatting Files...................................................................................................................................................1-17Commenting and Uncommenting Text............................................................................................................1-17

    Metso Aut omation 278588

  • 7/21/2019 278588 Maxscript A

    4/77

    maxSCRIPT User's Guide

    Indenting and Outdenting Text ...................................................................................................................... 1-17Toggling between Upper and Lower Case ..................................................................................................... 1-18Toggling Bookmarks ...................................................................................................................................... 1-18Shortcut Keys.................................................................................................................................................. 1-18

    CHAPTER 2 ......................................................................................................................2-1

    Creating maxSCRIPTs Using Simple Examples...................................................................................................... 2-1

    Getting Started.......................................................................................................................................................... 2-1Creating Points to be used in the Following Exercises..................................................................................... 2-1

    Creating and placing a maxSCRIPT Control........................................................................................................ 2-2Exercise 1: Creating a Three-State Valve Condition Using Script ....................................................................... 2-4

    Testing Exercise 1 in Runtime Mode................................................................................................................ 2-6Exercise 2: Creating a maxSCRIPT Control Using Parameters ........................................................................... 2-7

    Testing Exercise 2 in Runtime Mode................................................................................................................ 2-8Exercise 3: Creating a Navigation Button Using Script ....................................................................................... 2-8

    Testing Exercise 3 in Runtime Mode.............................................................................................................. 2-11Studying maxSCRIPT Examples........................................................................................................................ 2-11Example 1: Calculate an Average, Trigger an Alarm Indicator.......................................................................... 2-11Example 2: Working with Text StrIngs.............................................................................................................. 2-13Example 3: Hiding a Button in a Pop-up Display............................................................................................... 2-14Exercise 4: Using Flashing Bitmaps................................................................................................................... 2-15

    CHAPTER 3 ......................................................................................................................3-1

    maxSCRIPT Script Language Reference Guide...................................................................................................... 3-1

    Overview .................................................................................................................................................................. 3-1Using Dimension Statements................................................................................................................................ 3-1

    Creating Local Variables .................................................................................................................................. 3-1Creating Objects in the Local Status Server ..................................................................................................... 3-2Performing External Writes .............................................................................................................................. 3-3

    Performing Demand Writes Using Command Statements................................................................................ 3-4Subscribing to Keyboard Groups Using _Keyboard ........................................................................................ 3-5Interacting with Other maxVUE Controls ........................................................................................................ 3-6

    Using maxSCRIPT Commands ............................................................................................................................ 3-9Using Let X = Y Expressions ........................................................................................................................... 3-9Using If, Else, ElseIf, EndIf Expressions ....................................................................................................... 3-10Using the Bitmap Command........................................................................................................................... 3-10Using Flashing Bitmap Command.................................................................................................................. 3-11Using the Play Command ............................................................................................................................... 3-11Using the ToolTip Command ......................................................................................................................... 3-12Using the Run Command................................................................................................................................ 3-12

    Using Special Variables...................................................................................................................................... 3-12Using the DisplayVariable............................................................................................................................. 3-13

    Using the Mouse Clicks Variable ................................................................................................................... 3-13Using the ErrorVariable................................................................................................................................. 3-13Using Variables Mouserow/ Mousecol to Locate Mouse Cursor ................................................................... 3-13

    Using Special Functions ..................................................................................................................................... 3-14Using the Absolute Value Function................................................................................................................ 3-14Using the ASCII Character Function.............................................................................................................. 3-15Using the ASK Function................................................................................................................................. 3-15Using the AVI Function.................................................................................................................................. 3-16Using the Expand Function ............................................................................................................................ 3-17

    Metso Aut omation 278588

  • 7/21/2019 278588 Maxscript A

    5/77

    Contents

    Using the Logical Negation Function..............................................................................................................3-18Using the Objmap Function to Access the TypeMap ......................................................................................3-18Using the P_CONTROL and P_DETAIL Functions.......................................................................................3-19Using the QUA Function.................................................................................................................................3-21Using the RGB Function .................................................................................................................................3-21Using the SendMsg Function ..........................................................................................................................3-22

    Using the Service Function..............................................................................................................................3-22Using the TRANS Function ............................................................................................................................3-23Using the Value Function ................................................................................................................................3-23

    Creating Unique Output Names...........................................................................................................................3-23Changing maxSCRIPT Execution Time..............................................................................................................3-24Annotating Script with Comment Text................................................................................................................3-24

    APPENDIX A ....................................................................................................................A-1

    v

  • 7/21/2019 278588 Maxscript A

    6/77

  • 7/21/2019 278588 Maxscript A

    7/77

    Preface

    How This Book Is Organized

    maxSCRIPT is an OCX Control that lets you design your own custommaxVUE display applications using an easy-to-learn, Basic-like scriptlanguage. This publication introduces you to maxSCRIPT programmingconcepts and presents you with a script language reference guide located in

    Chapter 3. If you are not familiar with maxSCRIPT, refer to Chapter 1 for anintroduction and description of the control and the associated script language.Refer to Chapter 2 to review tutorial exercises and real examples ofmaxSCRIPT scripts authored by Metso Automation engineers.

    Audience

    This publication is intended for process control and software engineers andprogrammers involved with the design and development of human-machineinterface applications in a control environment.

    Using Online HelpMany of the concepts noted in this publication, such as maxVUE groups andparameterization, are explained more fully in maxVUE online help. Press theF1 key to access help.

    Using Other Programming Facilities

    maxSCRIPT is one of several controls that add programming capability tomaxVUE. Other facilities consist of:

    Wrapper Calculations The easiest to implement; use this to place a one-linecalculation most places where a Software Backplane(SBP) identifier is used.

    Hidden Logic This has full Visual Basic capability, but in additionto maxVUE, you must make a separate purchase ofthe Visual Basic tools and have some knowledge ofthe Visual Basic environment.

    Metso Aut omation 278588

  • 7/21/2019 278588 Maxscript A

    8/77

    maxSCRIPT User's Guide

    You may also add Visual Basic and C ++ controls to maxVUE to add full-blown programming capabilities to maxVUE, however, these options presentsome obvious disadvantages.

    VB Control This option presents you with a good deal of presentationflexibility but requires the separate purchase of VB

    Professional Version and the services of a VBprogrammer. It cannot take full advantage ofparameterization.

    C++ Control Requires a professional C++ programmer.

    Metso Automation 278588iv

  • 7/21/2019 278588 Maxscript A

    9/77

    Chapter 1

    Introduction

    OverviewmaxSCRIPT is an OCX Control that helps you design a custom displaywithin the maxVUE environment. Use maxSCRIPT for screen designapplications to incorporate customized logic not available from any of theother existing standard controls.

    maxSCRIPT uses a simplified Basic-like language that you can learn quicklyto create logical statements and perform simple calculations. One or moreinstances of this control may be placed onto any maxVUE display.

    Use the control to create local data and perform simple calculations usinglive data. The results of the calculations can be displayed on the associateddisplay.

    maxSCRIPT is an ideal way to create screen animations, such as an icon thatchanges color based on values obtained from multiple comparative inputs.For instance, use maxSCRIPT to create a pump icon. The valve on the pumpmay 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 yourprocess contains a tank that is filled with a reagent that must be heated to1000 degrees. Script logic could be used to change the color of the graphicevery 250 degrees. Logic could be set up as follows:

    Degrees Color of Tank

    0 - 250 Blue251 - 500 Yellow501 - 750 Cyan751 - 1000 Red

    Creating a Display Containing ScriptTo create a display containing maxSCRIPT expressions and commands:

    Use the mouse to create and place the maxSCRIPT control object onyour display. You may scale the control to any size including full screen.

    Metso Aut omation 278588

  • 7/21/2019 278588 Maxscript A

    10/77

    maxSCRIPT User's Guide

    Access the Script property page to create or edit the script file in amaxSCRIPT Editor session. Use the Editor to create simple text fileswith a default extension of .mxs.

    Note: the maxSCRIPT Editor, an integrated text editor, simplifies scriptediting and debugging. Scripts may also be edited in a simple text editor,

    such as Notepad, as long as the result is a simple ASCII text file (noformatting characters).

    Save the script file to a common script path, such asC:\Custom\Displays\Operating\Scripts.

    An additional control property page called Default lets you define a bitmapthat you want to appear in the maxSCRIPT window to replace the standardmaxSCRIPT icon.

    Similar to other controls, property pages are available to define themaxSCRIPT control as a navigation button (Display Navigation Page), to

    define borders for the button (Border Page), and to define window sizing andplacement (Drawing Options).

    Creating Script Files

    Script files are created with the extension .mxs.Note the control containsonly a reference to a script file.It is common to reuse script files many timeseven on the same display.

    A script may be stored with a display if used only by that display. When youintend to use scripts multiple times, they should be kept in the common areaC:\Custom\Displays\Operating\Scripts.

    maxSCRIPT is compiled in order to improve performance. When a script isexecuted for the first time by maxVUE Runtime, it is automatically compiledinto a new file that is smaller and executes faster. The new file, which islocated in the same folder as the text script file, has the extension .mxo.

    One Caution: if you use Notepad or another text editor to edit a scriptoutside of the maxVUE Editor or if you copy an updated .mxs file from onePC to another, the old .mxo file will not be updated (the maxSCRIPT Editorautomatically deletes the .mxo file for you if you make an edit). You cansimply delete the .mxo file to cause a compilation to take place the next timethat the script is executed.

    Developing Script Using maxSCRIPTScripts associated with a particular presentation are typically small in size.You may place as many scripts within a graphics presentation as neededusing multiple maxSCRIPT controls.There is one script per control.

    Metso Aut omation 2785881-2

  • 7/21/2019 278588 Maxscript A

    11/77

    Introduction

    Note: scripts have no size limits (other than any editing utility sizelimitations). Keep in mind, however, that as the script is compiled when thedisplay is called up, large scripts may effect display performance.

    Scripts consist of dimension statements, commands, variables, and specialfunctions, and other elements, all of which are listed in Chapter 3,

    "maxSCRIPT Script Language Reference Guide."

    Using Dimension StatementsDimension statements, which will appear inall scripts that you create,definenames (aliases) that allow you to read data from and perform writes to localvariables and to locations within the Software Backplane.

    You may use dimension statements to:

    Create temporary named objects in the Local Status Server to outputinformation to other Software Backplane users

    Interact with other controls Define external values to be written to, such as an existing point in the

    Local Status Server that is preserved even when you close a maxVUEsession.

    Create local variables to be use exclusively within this program

    Using Local Variables

    The dimension syntax for a local variable is written as:

    Dim as

    Where:

    any string that uniquely identifies this value in the rest of the script

    can be any of the following:

    dbl Double precision, floating point integerint integer valuestr string characters such as a description or tagname

    Example

    Di m x as dblDi m x as i ntDi m x as str

    Reading and Writing from the Software Backplane

    To read and write to values from the Software Backplane use the followingsyntax:

    Metso Aut omation 278588 1-3

  • 7/21/2019 278588 Maxscript A

    12/77

    maxSCRIPT User's Guide

    Dim as (.)

    Where:

    any string that uniquely identifies this value in the rest of the script any valid SBP service name

    any valid SBP extensionconsists ofthe following in and out types

    xxxIn types refer to an already existing variable, which is to be read andtypically used in a calculation.

    DblIn Double precision, floating point numberIntIn Integer variableStrIn string characters such as a description or tagname

    xxxOut types create (and delete when the screen closes) an LSS object foroutput (as well as input) so that other controls can access the calculatedresults. A is created for the purpose of housing outputs in theLocal Status Server. The same service can (and should) be used for multiplemembers. The members can be of all different types.

    Note that although the xxxOut variable is being created for writing, thecurrent value of the variable is available to the script for internal calculations.

    DblOut Double precision, floating point numberIntOut Integer variableStrOut string characters such as a description or tagname

    Examples:

    di m xyz as Dbl Out ( b. condou)di m i 12 as I nt Out ( b. coni nt )di m t xt as St r Out ( b. cont xt )

    di m asaw as Dbl I n( saw. ao)di m l ss_ser vi ce_count as I nt I n( _l ss. numsvc)di m now as St r I n( _l ss. t i me)

    Performing External Writes

    To access an existing object as an output, write the dimension statement asdimx.

    Example:

    di mx s as St r Out ( _sel _pt . t agname)

    Metso Aut omation 2785881-4

  • 7/21/2019 278588 Maxscript A

    13/77

    Introduction

    This lets you write to existing software backplane service members, such asDPU point (service) attributes (members) and LSS service members, such as_sel_pt.

    The function of thexis to prevent the script from creating an _lss variable ofthe name (.), which is deleted when the

    script is terminated.

    DIMX is only functional for dimension statements using out types as shownin the following:

    di mx I ntOut ( . )di mx Dbl Out ( . )di mx St r Out ( . )

    Example:

    Di mx sel pt as St r Out ( _sel _pt . t agname)Let sel pt = f i c101

    Interacting with Other maxVUE Objects

    To interact with other objects on a given maxVUE display, use the followingsyntax:

    Dim as CtlOut(.)

    Dim as CtlIn(.)

    Where:

    is the alias for this parameter within maxSCRIPT is replaced by Dbl, Int or Str; note that the types include thecharacters ctl, indicating the script will interact with other controls. Forexample, Dblctlout or StrctlIn.Ctlout indicates that this is a write to a maxVUE control object.CtlIn indicates that this is a read of a maxVUE control object property. is the name of the object as seen and set in the Layersbuttonof the maxVUE Editor is from the list:

    x - the x position in percent of screeny - the y position in percent of screenwidth - the width of the object

    height - the height of the objectcolor - the Fill Color of a maxVUE static objectlinecolor - the Line Color of a maxVUE static objectPropertyName - the Property Name of the control object.

    Refer to Appendix A for property names of standard maxVUE controlobjects.

    Your script should include one of the following out types

    Metso Aut omation 278588 1-5

  • 7/21/2019 278588 Maxscript A

    14/77

    maxSCRIPT User's Guide

    Dblctlout Double precision, floating point number output to themaxVUE object.

    Intctlout Integer number output to the maxVUE object

    Strctlout string characters output to the maxVUE object

    Example:

    Di m y as I nt Ct l Out ( obj ect. y)Let y = 10

    Your script should include one of the following in types

    DblctlIn Double precision, floating point number read from amaxVUE object

    Intctlin Integer value read from a maxVUE object

    Strctlin string characters read from a maxVUE object

    Example:

    Di m t ag as St r Ct l I n( obj ect . Top1Tag)Di m out Tag as St r Out ( msg. out Tag)Let out Tag = t ag

    Writing Script LogicOnce you identify write and read operations (using dimension statements toobtain data), you may usecommands combined with logical expressions toperform various operations that incorporate the data. maxSCRIPT uses thefollowing commands, variables, and functions to create logical arguments:

    Table 1-1.maxSCRIPT Commands, Variables, and Functions

    Commands Variables Functions

    LetIfElseElseIfEndif

    Bitmap/fbitmapPlayTooltipRun

    DisplayMouseclickMouserclickMousedclickMouserow

    MousecolError

    ABS; Absolute ValueASC; convert number to ASCII characterAVI; specify and display framesEXP; expand parameters in real time

    NOT; Logical Negation

    OBJMAP; perform lookup in typemap databaseQUA; checking variable qualitySVC; select a serviceTRANS; enable dual language translatorRGB; calculate a colorVAL; convert ASCII string to doubleASK; prompt operator to respond to a popupSendMsg; send windows messageP_CONTROL; output point control popup

    Metso Aut omation 2785881-6

  • 7/21/2019 278588 Maxscript A

    15/77

    Introduction

    P_DETAIL; output point detail popup

    The basicsyntax of any logical expression is Commandplus argument. Anexpression begins with one of the commands listed in the preceding table anduses variables, functions, or a combination of both as part of its argument.

    Refer to the following sections for specific examples of these three scriptelements.

    Using Let and If, Else Commands

    Use Let statements and if, else statements to create logical expressions andset up simple arithmetic operations.The syntax of an expression usingLetis:

    Let variables = expression

    For example:

    Let c = a + b.

    The following script sample usesLetand if, elseexpressions.

    Let out put = ( I nput 1 + I nput 2 ) / 2

    i f ( AnyAl arm1 = 1 ) or ( AnyAl arm2 = 1 )Let AnyAl arm = 1

    El seLet Anyal arm = 0

    EndI f

    Using the Bitmap CommandmaxSCRIPT also lets you display bitmaps using the Bitmapcommand. Youmay create a maxSCRIPT control incorporating multiple bitmaps that mayrepresent, say, a state change in your process or various mode changes, orwhatever your application may call for. Using if, else logic, the script maydisplay the bitmap associated with a given state. An additional fbitmapoption lets you create a flashing bitmap. The following sample script showsthe Bitmap command and the path name of a bitmap:

    Bi t map "C: \ cust om\ di spl ays\ operat i ng\ common\ bmp\ s- mi sc- 1. bmp"

    See "Using maxSCRIPT Commands," in Chapter 3 for a listing of other

    available commands and their syntaxes.

    Using Functions

    Functions are so called because they areused as a function of a variable in anexpression as in this syntax:

    Let variable = function argument

    Metso Aut omation 278588 1-7

  • 7/21/2019 278588 Maxscript A

    16/77

    maxSCRIPT User's Guide

    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 theRGB function changes the color of the caption text placed on a button basedon the state of the input BExp1. When the if statement becomes true, thecaption appears, assuming the color represented by "96,96,96".When the ifstatement is not true, the RGB function generates a null string representingno color, effectively canceling the button text.

    I f BExp1 = 1Let But t onTxt Col or1 = RGB "96, 96, 96"

    El seLet But t onTxt Col or1 = RGB "0, 0, 0"

    Endi f

    UsingSpecial Variables

    Variables, such as Display, Let you open a display or pop-up, andMouseclick, Let you create a script control that responds to mouse clicks.The following sample script logic contains both:

    I f Mousecl i ckLet Mousecl i ck = 0Let di spl ay = "popups\ zpop- ct - dv2- o- s- c. mn dp1=%par am1%"

    Endi f

    See "Using Special Variables," in Chapter 3 for a listing of all the availablevariables and their syntaxes.

    Placing Scripts in GroupsYou may place scripts in a group making it possible to reuse them multipletimes in many other instances. A Group is a named collection of objects,such as drawing objects, ActiveX Controls, and other groups, that maxVUEtreats as a single entity. Groups can be cut, copied, pasted, moved, resized,and deleted just like other objects. This makes it easy to reuse a drawingdepicting some process many times in other displays. You may create grouplibraries containing grouped drawings that can be incorporated in otherdisplays and modified to adapt it for other purposes.

    Where scripts are included with a group, cutting and pasting the group willalso take the script reference along. Note in this case, multiple groups would

    Metso Aut omation 2785881-8

  • 7/21/2019 278588 Maxscript A

    17/77

    Introduction

    be using the same script. This is handy when you want to make globalchanges to script logic that affect all instances.

    Making Scripts Portable Using ParameterizationTo make maxSCRIPTs even more portable, you may create scripts usingparameterization. With parameterization you may create displays and displaygroups containing maxSCRIPT controls and other standard controls that donot contain specific point references. Instead, point references are indicatedby %paramn% or %dpn% where n is the parameter or display parameternumber. Expansion is identical to that of any other control.

    Example

    Di m p1 as Dbl I n( %par am1%)Di m p2 as Dbl I n(%par am2%. ao)

    Di m out as Dbl Out ( %param3%)Let out = p1 + p2

    Parameters, such as %Param1% or %DP1%, can then be defined differentlyfor each display or display group.

    You must include the control in a group even if it contains only a singlescript item to properly use parameters. If you edit the parameters of acontrol not in a group, you will be editing the one and only set of defaultparameters for the whole display.

    Select Edit Group Parameters from the Group Menu to access the

    Parameters Property Sheet.

    Metso Aut omation 278588 1-9

  • 7/21/2019 278588 Maxscript A

    18/77

    maxSCRIPT User's Guide

    Enter the point name to be used with the Parameter in the ParameterAssignment field and a description for the parameter. A parameter may bedefined to be another parameter such as %DP1%. At run-time, maxVUE willcontinue 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 willprobably find yourself creating similar displays for multiple hierarchicalgroups.

    You are now free to copy the display containing the parameter names. Atruntime, maxVUE decodes the parameters it finds and inserts the actualvalues.

    Note: by using parameters for the outputs of the script, the same parametercan be used for the script as is used for a Bar or a List Box in the same Groupinsuring no mistakes.

    Specifying a Percent (%) Character

    Percents are part of the expansion of parameters - %param1% for example.As such they are special characters. If you actually want a percent (%), youmust use %%. Example:

    Di m x as Dbl I n( t est . op%%)

    Putting It All TogetherThe following shows a complete sample script incorporating many of the

    elements introduced in the proceeding discussion. This script will cause anon-screen alarm indicator to be set based on the state of two inputs. For adetailed discussion of this script, refer to Chapter 2, "Example 1: Calculatean Average, Trigger an Alarm Indicator."

    Bi t map "C: \ cust om\ di spl ays\ operat i ng\ common\ bmp\ s- mi sc- 1. bmp"

    Di m I nput 1 as I nt I n( %param1%. out )Di m I nput 2 as I nt I n( %param2%. out )Di m Output as I nt Out ( %par am1%_avg. out )

    Di m AnyAl arm1 as I nt I n( %par am1%. Anyal arm)Di m AnyAl arm2 as I nt I n( %par am2%. Anyal arm)Di m AnyAl arm as I ntOut ( %par am1%_avg. Anyal arm)

    Let out put = ( I nput 1 + I nput 2 ) / 2

    i f ( AnyAl arm1 = 1 ) or ( AnyAl arm2 = 1 )Let AnyAl arm = 1

    El se

    Metso Aut omation 2785881-10

  • 7/21/2019 278588 Maxscript A

    19/77

    Introduction

    Let Anyal ar m = 0EndI f

    Reviewing maxSCRIPT Error Messages

    maxSCRIPT produces two types of errors, run-time and compile. The scriptis compiled when it is loaded. Syntax is partially checked. Run-time errorsare mostly "tag or attribute not found" types of errors.To view errors in themaxVUE editor, right click on the control and select Control Propertiesfrom the menu to bring up the Scripts property page. View errors from thispage.

    Writes to Constants Are Prevented

    maxVUE includes diagnostic capabilities to prevent writes to constant data.The following will result in an error:

    di m s as St r I n( _ l ss. t i me)Let s = "now"

    This generates the following error message. The 2indicates that the error wasdetected at line two.

    Wr i t e t o a const ant ( 2)

    In another script example, the following contains a logic error that wouldyield the erroneous result i = 2. maxSCRIPT diagnostic capabilities preventthis from occurring.

    di m i as i ntLet 1 = 2Let i = 1

    Using the maxSCRIPT EditorUse the maxSCRIPT Editor you to view, create or edit maxSCRIPT (*.mxs)files in a multiple document environment. The integrated maxSCRIPTEditor, similar to any text or word processing program, simplifiesmaxSCRIPT editing and debugging as you create process displays.

    When you place a maxSCRIPT instance on a maxVUE display and create ascript file, the following editing window appears: Most of the basic functionscan be accessed through a menu, a toolbar button or a shortcut key.

    Metso Aut omation 278588 1-11

  • 7/21/2019 278588 Maxscript A

    20/77

    maxSCRIPT User's Guide

    ]

    Creating New Files and ProjectsmaxSCRIPT Editor allows you to create individual maxSCRIPT files or amaxSCRIPT project. Create a maxSCRIPT project to group togethercommon or relevant files. See "Working with Projects," in the next section.

    To create a new maxSCRIPT file:

    From the File menu, point to New and click maxSCRIPT file.

    Alternatively, click the New icon on the toolbar or press + N.

    To create a new project click 'New' then 'maxSCRIPT Project' under the Filemenu or the + J shortcut key.

    Working with ProjectsTo group related maxSCRIPT files in one place, create a project file.

    To create a project file:

    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 windowcontaining a Windows Explorer style directory tree showing all the files inthe current project.

    Metso Aut omation 2785881-12

  • 7/21/2019 278588 Maxscript A

    21/77

    Introduction

    The files can be given a name to identify themselves in the project. Anychanges to the project will not be saved until Save Project is clicked underthe File menu.

    Renaming the Project

    To change the name of the current project:

    Select the root file name, the topmost node in the project window, right clickand select Rename from the popup menu.

    Renaming the project gives the project a name to identify itself and does notchange 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

    To remove a file from the current project:

    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 thefile simply changes the name to identify itself in the project and does notchange the actual filename.

    Creating New Files and Projects

    maxSCRIPT Editor allows you to create individual maxSCRIPT files or amaxSCRIPT project that can be used to group common or relevant files in anorderly manner.

    Metso Aut omation 278588 1-13

  • 7/21/2019 278588 Maxscript A

    22/77

    maxSCRIPT User's Guide

    Creating New Files: To create a new maxSCRIPT file simply navigate theFile menu to New then select maxSCRIPT File. You can also click the Newbutton on the toolbar or use the + N shortcut key.

    Creating New Projects: A maxSCRIPT project helps the user to grouprelevant files in an easily accessible fashion. To create a new project clickNew then maxSCRIPT Project under the File menu or the + Jshortcut key.

    Editing Files

    Cut, Copy, and Paste functions can be accessed from the Edit menu or byclicking their icons on the toolbar.

    Undo and Redo can be accessed from the Edit menu or by clicking theiricons on the toolbar. Undo can also be accessed by using the + Zshortcut key. You can undo and redo actions an unlimited amount of times.

    Find, Find Next, and Replace

    Find, find next and replace functions can be accessed from the Edit menu,clicking their icons on the toolbar or using their + F, F3, and + H shortcut keys respectively.

    Selecting all text can be accessed from the Edit menu or by using the + A shortcut key.

    Enabling Standard Editor OptionsThe maxSCRIPT Editor includes standard features that can be enabled ordisabled from the Options menu accessible from the Tools menu:

    Auto complete

    Line numbering

    Line highlighting

    Metso Aut omation 2785881-14

  • 7/21/2019 278588 Maxscript A

    23/77

    Introduction

    Syntax highlighting

    All of these features can be seen in the following picture of an edit window:

    Using Auto Complete

    Use the auto complete feature to select commonly used attributes from a pop-

    up list as you create script. The feature anticipates the attribute you intend totype and automatically completes the word.

    To use auto complete:

    Select Options from the Tools menu to enable auto complete, if the feature isnot enabled by default. From the Options dialog, check Auto Complete toenable it. Uncheck the checkbox to disable the feature.

    Inside the maxSCRIPT Editor window, press the period key to access apop-up list of commonly used attributes.

    As you continue to type normallly, the auto complete feature will select theword 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 autocomplete box without finishing the word.

    You may customize the auto complete attributes list to suit your specificrequirements.

    Metso Aut omation 278588 1-15

  • 7/21/2019 278588 Maxscript A

    24/77

    maxSCRIPT User's Guide

    To add attributes to the auto complete list:

    Select MaxScriptEditor.txt from the Tools menu. When you edit theMaxScriptEditor.txt file it will be placed inC:\Custom\Displays\Operating\Database\. The original MaxScriptEditor.txtfile can be found in the C:\MCS\Setup\ directory and should not be edited.

    Using Line Numbering

    Line numbers permit you to quickly move to a specific area in a file or todebug an error in maxVUE Editor.

    To move directly to a specific line number:

    Select Options from the Tools menu to enable line numbering, if the featureis not already enabled. From the Options dialog, check Line Numbering toenable it. Uncheck the checkbox to disable the feature.

    Press + G. to access the Goto Line dialog box. Enter a line numberand click OK.

    To change the appearance of line numbers:

    Select Options from the Tools menu and under line numbering, check Boldor Italics.

    Using Line Highlighting

    Line highlighting can help to identify the current line being edited by

    coloring the current line yellow.

    To enable or disable line highlighting:

    Select Options from the Tools menu and check Line Highlighting to enablethe feature or uncheck the checkbox to disable the feature.

    Using Syntax Highlighting

    Syntax Highlighting greatly reduces the chance of error by coloringkeywords, operators and StrIngs common to the maxSCRIPT language.Keywords are colored blue, operators red, and StrIngs purple.

    To enable or disable syntax highlighting:

    Select Options from the Tools menu and check Syntax Highlighting to enablethe feature or uncheck the checkbox to disable the feature.

    Metso Aut omation 2785881-16

  • 7/21/2019 278588 Maxscript A

    25/77

    Introduction

    Formatting Files

    Commenting and Uncommenting Text

    To annotate maxSCRIPT with free form comments, notes, specialinstructions, and so forth, begin each comment line with any of thefollowing:

    Rem; Semicolon character' Apostrophe character

    When maxSCRIPT is executed, any text beginning with the above charactersis ignored.

    To comment text automatically:

    Place your cursor on the line to be commented and click the Comment buttonon the formatting toolbar.

    You may also select Comment Block from the Format pull-down menu orpress + I shortcut key.

    To uncomment text automatically:

    Place your cursor on the line to be uncommented and click the Uncommentbutton on the formatting toolbar.

    You may also select Uncomment Block from the Format pull-down menu orpress < + U shortcut key.

    Indenting and Outdenting Text

    To indent a line of text in a script file:

    Place your cursor on the line you wish to indent and click the Indent buttonon the formatting toolbar.

    You may also select Indent Text from the Format pull-down menu, or pressthe key.

    To outdent a line of text in a script file:

    Place your cursor on the line you wish to outdent and click the Outdentbutton on the formatting toolbar.

    Metso Aut omation 278588 1-17

  • 7/21/2019 278588 Maxscript A

    26/77

    maxSCRIPT User's Guide

    You may also select Outdent Text from the Format pull-down menu, or press + TAB.

    Toggling between Upper and Lower Case

    To change text from uppercase to lowercase and vice-versa navigate theFormat menu, click the To Lowercase or To Uppercase buttons on thetoolbar, or by use their + L and + K shortcut keysrespectively.

    Toggling Bookmarks

    To toggle a bookmark at the current line click Toggle Bookmark from theFormat 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 maxVUEEditor to create process graphics and a maxSCRIPT error is generated, themaxSCRIPT file will be opened in maxSCRIPT Editor with a bookmark atthe line with the error.

    Moving through Bookmarks: to move between bookmarks click NextBookmark or Previous Bookmark from the Format menu or use the F2 and + F2 shortcut keys respectively.

    Clear Bookmark: to clear all the bookmarks in the current file click ClearBookmarks from the Format

    Shortcut Keys

    maxSCRIPT Editor has many shortcut keys that make it easy to accesscommon operations. The following table lists the default keystrokes and theirassociated actions.

    New maxSCRIPT File Ctrl-NOpen maxSCRIPT File Ctrl-OSave File Ctrl-S

    New Project Ctrl-JOpen Project Ctrl-RPrint Ctrl-P

    Cut Ctrl-XCopy Ctrl-CPaste Ctrl-VSelect All Ctrl-ASelect Line Ctrl-Alt-F8Undo Ctrl-Z

    Next Word Ctrl-RightArrowPrevious Word Ctrl-LeftArrowDelete Next Word Ctrl-Delete

    Metso Aut omation 2785881-18

  • 7/21/2019 278588 Maxscript A

    27/77

    Introduction

    Delete Previous Word Ctrl-BackspaceDocument Start Ctrl-HomeDocument End Ctrl-EndComment Block Ctrl-IUncomment Block Ctrl-UIndent Tab

    Outdent Shift-TabConvert to Lowercase Ctrl-LConvert to Uppercase Ctrl-KCreate New Line (above) Ctrl-Shift-N

    Next Bookmark F2Previous Bookmark Shift-F2Find Ctrl-FFind Next F3Find Previous Shift-F3Replace Ctrl-HGoto Line Ctrl-GGoto Matching Brace Ctrl-]Set Repeat Count Ctrl-RToggle Whitespace Display Ctrl-Alt-TInsert File Path from Dialog Ctrl-F1Scroll Window Down Ctrl-UpArrowScroll Window Up Ctrl-DownArrowScroll Window Left Ctrl-PageUpScroll Window Right Ctrl-PageDownHelp F1

    Note: Holding down shift when using any of the navigational shortcut keys will select any text that the cursor moves

    through.

    Metso Aut omation 278588 1-19

  • 7/21/2019 278588 Maxscript A

    28/77

  • 7/21/2019 278588 Maxscript A

    29/77

    Chapter 2

    Creating maxSCRIPTsUsing Simple Examples

    Getting Started

    To use the maxSCRIPT control effectively you need to become acquaintedwith the maxSCRIPT scripting language. This simple but powerful scriptlanguage consists of a relatively small number of commands, specialvariables and functions that you may learn with ease. Scriptelements are alllisted in detail in the maxSCRIPT Script Language Reference Guide inChapter 3.

    This chapter shows you how to create a few simple maxSCRIPT controls byexample in three introductory exercises. The firstexercise shows you how todisplay bitmaps based on the state of an analog output. A second exerciseshows you how to implement a similar maxSCRIPT using parameterization.A third exercise demonstrates the use of the Mouseclickvariable.

    The exercises are followed by four examples of script developed for realapplications by Metso Automation engineers. Each example illustrates anaspect of script that you may implement when you compose your own scriptfiles.

    Creating Points to be used in the Following Exercises

    Before getting started, you must first create the temporary points,fuel_flow.pid and air_flow.pid. These points will be used as simulatedcontrollers that you may manipulate throughout these exercises.

    To create simulated points:

    1. From the Startmenu, point to Programs, maxDNA, Utilities, and clickTestSBPto open the TestSBPutility dialog display.

    2. Under Operation, select Write; under Write Type select Empty.

    3. In the Identifier field, type the following:

    _lss.addsvc. fuel_flow.pid

    Metso Aut omation 278588

  • 7/21/2019 278588 Maxscript A

    30/77

    maxSCRIPT User's Guide

    4. Click the Apply button to add this simulated point to the Local StatusServer.

    After you add fuel_flow.pid, follow the same steps to add the secondsimulated point, air_flow.pid.

    When you finish, you will have added two new services to the Local StatusServer. To confirm that the services were added, open the maxDNA PointBrowser. Expand the Servers node under Online Configurations. Thenexpand the _LSS node and finally the PID node. When you select any of thepoints, a list of default attributes appears on the details tabular, including AO.

    Note: when you close maxVUE and shutdown the maxSTATION, these twoservices will be deleted from the Local Status Server.

    Creating and placing a maxSCRIPT ControlBefore demonstrating maxSCRIPT script creation using these examples,Lets get started with the basics, calling out the control.

    To place a maxSCRIPT control in a maxVUE display:

    1. Double click on the maxVUE Editor icon appearing on the Windowsdesktop to open the editor tool.

    2. Click the Newtool button to access the file directory dialog box andenter a file name, such as mydisplay.mn, or any name meaningful to you.

    3. Click the maxSCRIPT Controltool button from the OLE Animatortool bar. Place the cursor on the desired location on the screen and clickbut do not release the button.

    4. Drag the mouse to size the maxSCRIPT display window as desired andrelease the button when satisfied with the dimensions. Remember thiswill be the size and location of the bitmap window.

    5. Click the Select tool button and click on the maxSCRIPT controlyou just created to select it.

    6. Right-click to bring up the Control Menu pop-up and select ControlPropertiesfrom the menu to bring up the control's two property pages,Scriptand Default.

    Metso Automation 2785882-2

  • 7/21/2019 278588 Maxscript A

    31/77

    Creating maxSCRIPTs Using Simple Examples

    7. From the Script tab, click the Newbutton to create a new script and enteran appropriate name for the script. Create a file location under theCustom directory such as C:\Custom\Displays\Operating\Scripts. Anyadditional scripts that you create should be saved to this location.

    8. Click the Savebutton to bring up the maxSCRIPT Editor.

    9. From the maxSCRIPT Editor, enter the desired code and select Savefrom the File menu when you are finished.

    Metso Aut omation 278588 2-3

  • 7/21/2019 278588 Maxscript A

    32/77

    maxSCRIPT User's Guide

    10. From the Default tab, enter an image file or background color that youwant to appear in the control window to replace the standard icon thatappears when you first call out a maxSCRIPT instance.

    This summarizes all the steps required to create a maxSCRIPT control. Nowyou're ready to create scripts based on the examples outlined at the beginning

    of this chapter. Refer to the next sections.

    Exercise 1: Creating a Three-State Valve Condition Using ScriptIn this first exercise, you will create a maxSCRIPT control that displays oneof four bitmaps based on the state of an analog output. The bitmaps mayconsist of graphical representations of a pump valve. Each bitmap depicts anidentical pump valve image, however, the fill colors vary from image toimage. One bitmap may be red, another green, another yellow, and a fourthimage may use a combination of red and yellow. Each color represents a

    different flow state. The following figure shows one version of the pumpvalve bitmap rendered in gray scale.

    The script will consists of three common script language elements, thedimension statement, If, Else conditional statements, and the bitmapcommand. In addition to the maxSCRIPT pump control, you'll be creatinganother maxSCRIPT control containing a button that calls out the control.

    Refer to the "maxSCRIPT Script Language Reference Guide" in Chapter 3for a full listing of script expressions and commands and their syntaxes.

    To create the control:

    Follow the steps in the previous section, "Creating and Placing amaxSCRIPT Control," to call out the control and open a maxSCRIPT Editorsession.

    1. To begin the script enter the following dimension statement:

    Metso Automation 2785882-4

  • 7/21/2019 278588 Maxscript A

    33/77

    Creating maxSCRIPTs Using Simple Examples

    In this dimension statement fuel is a double (floating) in from the tagnamefuel_flow.ao.

    2. The rest of the script uses if, elseconditional expressions that incorporatebitmap commands as shown in the following figure:

    3. Save the script file using maxSCRIPT Editor menu options. In ourexample, the script is named 3-state-vlv.mxs.

    4. From the Controls Property Default Page select a default bitmap todisplay in the maxSCRIPT control window. This should be one of thebitmaps based on valve conditions.

    5. Click on the Savetool button to save the changes to mydisplay.mn,or whatever name you choose.

    Metso Aut omation 278588 2-5

  • 7/21/2019 278588 Maxscript A

    34/77

    maxSCRIPT User's Guide

    Create a screen button using a new instance of maxSCRIPT to displayswap to mydisplay.mn, and close the maxVUE Editor. Type thefollowing script to create a screen button in maxSCRIPT:

    In this suggested script, the following line contains the path name of thetarget display:

    Let di spl ay = "pump\ pump. mn"

    Substitute here the name of your target display containing themaxSCRIPT you created in this exercise.

    Note: exercise 3 discusses the Mouseclick variable at length.

    Testing Exercise 1 in Runtime Mode

    To see if the script you just created actually works, you may open it inmaxVUE Runtime.

    To test your script:

    1. From the Windows desktop, double click on the maxVUE Runtime iconto invoke the application.

    2. Click anywhere on the logo screen to open the Main Menu display.

    3. Click on the maxSCRIPT button you created to display swap to themydisplay.mndisplay.

    4. Selectfuel_flowas the selected point and bring up the faceplate. Increaseor decrease the AO to within the valve condition values specified in themaxSCRIPT. Are the Bitmaps changing based on the AO of the specifiedtag?

    Metso Automation 2785882-6

  • 7/21/2019 278588 Maxscript A

    35/77

    Creating maxSCRIPTs Using Simple Examples

    Exercise 2: Creating a maxSCRIPT Control Using ParametersIn this exercise, you'll create a maxSCRIPT control similar to the one youcreated in Exercise 1, only this time instead of using a specific pointidentifier, you will use parameters. As noted in Chapter 1, parameterizationmakes it possible to create a control once and reuse it again for other screen

    applications. Refer to "Making Scripts Portable Using Parameterization."

    Before you attempt to perform this exercise, review Exercise 1.

    To create a control using parameters:

    1. From the maxVUE Editor open the display you created in Exercise 1.

    2. Click the Select tool button and click on the maxSCRIPT controlyou created in the previous exercise to select it.

    3. Copy and paste the maxSCRIPTinstance somewhere on the display.

    4. Right-click to bring up Control Menu pop-up and select ControlPropertiesfrom the menu to bring up the control's two property pages,Script and Default.

    5. From the Script tab, click the Editbutton to select the script for the 3-state valve condition you created earlier.

    6. In the dimension statement, change fuel to aoas a double (floating) infrom a group parameter instead of a specific point. Replace the pointidentifier (fuel_flow.ao) with (%Param1%.ao). Refer to the revised scriptin the following figure.

    7. From the maxSCRIPT Editor File menu, save the script under a newname, such as 3-state-vlv-param.

    Metso Aut omation 278588 2-7

  • 7/21/2019 278588 Maxscript A

    36/77

    maxSCRIPT User's Guide

    8. Click the Select tool button and click on the maxSCRIPT controlyou created. Right-click to bring up Control Menu pop-up and selectGroupfrom the context menu.

    9. Select the Group, Create New Group From Selected Objectsoption

    to make the maxSCRIPT instance a group.

    10. Select the Group, Edit Group Parametersoption and edit the Param1assignment 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 youcreated in this exercise to select it. Copy and paste the maxSCRIPT instance somewhere on the display.

    12. Edit group parameter 1 of the copied script to air_flow.

    13. Click the Savetool button to save the changes to your mydisplay.mndisplay and close the maxVUE Editor.

    Testing Exercise 2 in Runtime Mode

    To see if the script you just created actually works, you may open it inmaxVUE Runtime.

    To test your script:

    1. From the Windows desktop, double click on the maxVUE Runtime iconto open the application.

    2. Click anywhere on the logo screen to open the Main Menu display.

    3. Edit the screen button you created in the previous exercise to displayswap to mydisplay.mn, and close the maxVUE Editor.

    4. Select fuel_flow as the selected point and bring up the faceplate. Increaseor decrease the AO to within the valve condition values specified in themaxSCRIPT. Now select and manipulate air_flow to view two instancesof a script control operating independently while using the same scriptfile. Are the Bitmaps changing based on the AO of the specified tag?

    Exercise 3: Creating a Navigation Button Using ScriptmaxSCRIPT includes three mouse click variables that you may incorporatein a maxSCRIPT control with other script logic. Using a specific mouse clickvariable, you may design a screen navigation button that responds to a singleleft mouse click, single right mouse click or a double click. The button may

    Metso Automation 2785882-8

  • 7/21/2019 278588 Maxscript A

    37/77

    Creating maxSCRIPTs Using Simple Examples

    use any background including bitmaps and be scaled to any size includingfull screen.

    Refer to the "maxSCRIPT Script Language Reference Guide" in Chapter 3for a listing of Mouseclick variables.

    To create script using a mouse click variable:

    1. With the maxVUE Editor, click on the Newtool button to access thefile directory dialog box and enter a file name, such asmydisplay_exercise3.mnor any name of your choosing.

    2. Click on the maxSCRIPT Control tool button from the OLEAnimator tool bar. Place the cursor on the desired location on the screenand click but do not release the button.

    3. Drag the mouse to size the maxSCRIPT display window as desired and

    release the button when satisfied with the dimensions. Remember thiswill be the size and location of the navigation button.

    4. Click the Select tool button and click on the maxSCRIPT controlyou just created to select it.

    5. Right-click to bring up Control Menu pop-up and select ControlProperties from the menu to bring up the control's two property pages,Script and Default.

    6. From the Script tab, click the Newbutton to create a new script and enteran 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 Savefrom the File menu when you are done. Create a file location under theCustom directory such as C:\Custom\Displays\Operating\Scripts.

    8. The first line of script uses the bitmap command to define thebackground for the display button. Refer to the following figure:

    Metso Aut omation 278588 2-9

  • 7/21/2019 278588 Maxscript A

    38/77

    maxSCRIPT User's Guide

    9. The next two lines set up the conditions for the display swaps based onthe 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 asthe displays you created in the previous exercises containingmaxSCRIPT controls.

    Be sure the correct file path and display name (including file extension)is specified. The file path must begin afterC:\Custom\Displays\Operating. For example, Main\Mainmenu2.MN,Boiler\Boiler.MN, Air\Air.MN, etc. Refer to the following figure:

    Metso Automation 2785882-10

  • 7/21/2019 278588 Maxscript A

    39/77

    Creating maxSCRIPTs Using Simple Examples

    11. End the condition (Endif) and save the script file using the maxSCRIPTEditor menu options.

    Testing Exercise 3 in Runtime ModeTo see if the script you just created actually works, you must open it inmaxVUE Runtime.

    To test your script:

    1. From the Windows desktop, double click on the maxVUE Runtime iconto open the application.

    2. Click anywhere on the logo screen 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.mnor whateveryou chose to call it.

    Studying maxSCRIPT ExamplesAfter completing the proceeding exercises, you're probably ready to look atseveral real examples of maxSCRIPT scripts. The scripts in the followingexamples each incorporate some script coding ideas that you may want toborrow when you create your own scripts.

    Example 1: Calculate an Average, Trigger an Alarm Indicator

    The following script sets off an on-screen yellow alarm indicator when thestate of two alarm attributes associated with two input values become true.

    Metso Aut omation 278588 2-11

  • 7/21/2019 278588 Maxscript A

    40/77

    maxSCRIPT User's Guide

    Bi t map C: \ cust om\ di spl ays\ operat i ng\ common\ bmp\ hi de_bi t map. bmp"

    Di m I nput 1 as I nt I n( %par am1%. out )Di m I nput 2 as I nt I n( %par am2%. out )Di m Output as I ntOut ( %par am1%_avg. out )

    Di m AnyAl arm1 as I nt I n(%par am1%. Anyal arm)Di m AnyAl arm2 as I nt I n(%par am2%. Anyal arm)Di m AnyAl arm as I nt Out ( %par am1%_avg. Anyal arm)

    Let out put = ( I nput 1 + I nput 2 ) / 2

    i f ( AnyAl arm1 = 1 ) or ( AnyAl arm2 = 1 )Let AnyAl arm = 1

    El seLet Anyal ar m = 0

    EndI f

    The script begins with a bitmap command followed by a path name.

    Bi t map "C: \ cust om\ di spl ays\ operat i ng\ common\ bmp\ hi de_bi t map. bmp"

    In this case, the bitmap is only use to hide the maxSCRIPT control on thedisplay. The bitmap command calls out a background color that is identicalto the screen display color, making the control blend in with its backgroundand disappear from view. This is a convenient way to hide the control whenit need not be visible, reducing screen clutter and confusion.

    The next part of the script uses six dimension statements to read and writevalues to the Local Status Server in the Software Backplane.

    Di m I nput 1 as I nt I n( %param1%. out )Di m I nput 2 as I nt I n( %param2%. out )Di m Output as I ntOut ( %par am1%_avg. out )

    Di m AnyAl arm1 as I nt I n(%par am1%. Anyal arm)Di m AnyAl arm2 as I nt I n(%par am2%. Anyal arm)Di m AnyAl arm as I nt Out ( %par am1%_avg. Anyal arm)

    The first two dimension statements are reading two input values from theparameterized tag names %par am1%. out and %par am2%. out .

    The two inputs have two associated attributes for alarming called AnyAlarm1

    and AnyAlarm2. The following dimension statements are reading these twovalues:

    Di m AnyAl arm1 as I nt I n(%par am1%. Anyal arm)Di m AnyAl arm2 as I nt I n(%par am2%. Anyal arm)

    The script uses a Let statement to calculate an average for the two inputvalues, Input1 and Input2. The following dimension statement is used to

    Metso Automation 2785882-12

  • 7/21/2019 278588 Maxscript A

    41/77

    Creating maxSCRIPTs Using Simple Examples

    output the result of this calculation to a location in the Local Status Servercalled %par am1%_avg. out .

    Di m Out put as I ntOut ( %par am1%_avg. out )

    For example, if the group parameter 1 is set to FIC101, a point named

    FIC101_avg with a member .outwill be created. Another control, such as abar control, can use this output via the identifier FIC101_avg.out.

    Finally, the script uses an If expression to test for an alarm state. Theexpression states that if AnyAlarm1 or AnyAlarm2 enters a true state, thenLet an output value, created in maxSCRIPT, called AnyAlarm equal 1. Usinga dimension statement, this value is then passed on to an output tag called%param1%_avg.Anyalarm. This then activities a screen alarm indicator. Seethe following dimension statement:

    Di m AnyAl arm as I ntOut ( %par am1%_avg. Anyal arm)

    Example 2: Working with Text StrIngsUse maxSCRIPT to call out text StrIngs that are treated as constants. In thisscript example, a group of similar displays use the same display title,however, when one of these displays is accessed it needs to show a differenttitle, "Oil Elevation A Front Sequence." This is accomplished with thefollowing script.

    Di m Ti t l eTxt 1 as St r ct l out ( Ti t l e/ Ti t l eTxt 1. t ext )Di m Ti t l eTxt 2 as St r ct l out ( Ti t l e/ Ti t l eTxt 2. t ext )

    Di m DP1 as St rLet DP1 = %dp1%

    I f DP1 = "OI LSEQAF"Let Ti t l eTxt 1 = "Oi l El evat i on A Front Sequence"Let Ti t l eTxt 2 = "Oi l El evat i on A Front Sequence"

    Endi f

    The script begins with two dimension statements that are writing to the Textproperty of two maxVUE Editor static text objects called TitleTxt1 andTitleTxt2. These two objects are in a Group named Title. (Refer to Layersdialog fragment below).

    Metso Aut omation 278588 2-13

  • 7/21/2019 278588 Maxscript A

    42/77

    maxSCRIPT User's Guide

    A third dimension statement is declaring a text string that is set from anymaxVUE display file with the parameterized reference, dp1.

    The script logic following the dimension statements states that if a display isaccessed where dp1 is "OILSEQAF," Let the display title be "Oil ElevationA Front Sequence."

    Example 3: Hiding a Button in a Pop-up DisplayThe following script was written for a pop-up display that is used formultiple screen applications. The display interacts with multiple maxSCRIPTcontrols at any given time, which dynamically change its appearance basedon the state of current inputs.

    ' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -' Thi s scr i pt hi des t he St ate2 command and f eedback

    ' but t on when Numst at e = 2.' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -' Conf i gur e Runt i me Bi t map t o hi de MAXscr i pt . ocxBi t map "S- popback- 1. bmp"

    Di m Numst at e as I nt I n(%dp1%. Numst at e)

    Di m Hei ght _r ect as dbl ct l out ( t ank/ St at e2r ect angl e. hei ght )Di m Hei ght _but t on as dbl ct l out ( t ank/ st at e2. hei ght )

    Di m Wi dt h_r ect as dbl ct l out ( t ank/ St at e2r ect angl e. wi dt h)Di m Wi dt h_but t on as dbl ct l out ( t ank/ st at e2. wi dt h)

    I f Numst at e = 2Let Wi dth_r ect = 0Let Wi dt h_but t on = 0Let Hei ght _r ect = 0Let Hei ght _but t on = 0

    Endi f

    Metso Automation 2785882-14

  • 7/21/2019 278588 Maxscript A

    43/77

    Creating maxSCRIPTs Using Simple Examples

    The pop-up as created contains three buttons that may be assigned differentfunctionality depending on the inputs the pop-up is currently referencing. Incertain specific instances, however, only two buttons are relevant to theapplication that called the pop-up. The script shown here is designed to hidethe third button when an input indicates only two buttons are needed.

    The script begins with several comment lines set off by the initial singlequote or apostrophe character. When the script is compiled, text StrIngs thatfollow a single quote are ignored. The comments summarize the purpose ofthe script, which is to hide the State 2 command and feedback button whenan input called Numstate equals 2.

    The script continues with a bitmap command that displays a pop-up displayfile called S- popback-1.bmp.

    The bitmap command is followed by five dimension statements. The firstdimension statement is reading the attribute Numstate that is associated witha display identifier called dp1. See the following dimension statement:

    Di m Numst at e as I nt I n(%dp1%. Numst at e)

    The four other dimension statements define names to be used to write to thesize attributes of the State2 button. Note that the size attributes include arectangle that refers to the border surrounding the button.

    Note: controls can be renamed using maxVUE Editor Layers button. Clickthe Layers button, locate and select the control of interest, right-click andselect Renamefrom 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 readsan input equaling 2 then write a zero to the size attributes of the button andsurrounding rectangle. This effectively makes the button and button borderdisappear from the display when this script is in effect.

    Note: when you select Test Mode in the maxVUE Editor, scripts can modifythe parameters of other unsaved controls, such as width, height, x or y, orcolor. If you save the graphic after the script is run, these parameters changeswill 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 formultiple purposes, eliminating the need to create multiple displays designed

    to anticipate very specific uses.

    Exercise 4: Using Flashing BitmapsIn addition to the Bitmap command, maxSCRIPT includes the fbitmapcommand, which makes a bitmap image appear to flash repeatedly. The

    Metso Aut omation 278588 2-15

  • 7/21/2019 278588 Maxscript A

    44/77

    maxSCRIPT User's Guide

    following script uses two flashing bitmaps to call attention to a devicedepicted on a displaywhen it enters an alarm state.

    Di m DevSt at e as I nt I n(%par am1%. / #1. DevSt ate)Di m Ovr d1 as I nt I n(%par am1%. / #1. Ovr d1)Di m Ovr d0 as I nt I n(%par am1%. / #1. Ovr d0)

    Di mx Sel Pt as St r Out( _sel _pt . Tagname)

    i f ( Ovrd1 = 1) and (DevState = 2)

    Bi t map "c: \ custom\ di spl ays\ operat i ng\ common\ bmp\ s- cb- a- 1. bmp"f Bi t map "c: \ cust om\ di spl ays\ operat i ng\ common\ bmp\ s- cb- a- 1f l . bmp"

    el sei f ( Ovrd0 = 1) and ( DevStat e = 1)

    Bi t map "c: \ custom\ di spl ays\ operat i ng\ common\ bmp\ s- cb- a- 2. bmp"f Bi t map "c: \ cust om\ di spl ays\ operat i ng\ common\ bmp\ s- cb- a- 2f l . bmp"

    el sei f DevSt ate = 2

    Bi t map "c: \ custom\ di spl ays\ operat i ng\ common\ bmp\ s- cb- a- 1. bmp"f Bi t map ""

    el sei f DevSt ate = 1

    Bi t map "c: \ custom\ di spl ays\ operat i ng\ common\ bmp\ s- cb- a- 2. bmp"f Bi t map ""

    el seBi t map "c: \ custom\ di spl ays\ operat i ng\ common\ bmp\ s- cb- a- 5. bmp"f Bi t map ""

    Endi f

    I f Mousecl i ckLet Mousecl i ck = 0Let Sel Pt = "%param1%"

    Endi f

    I f mousedcl i ckLet mousedcl i ck = 0Let di spl ay = "popups\ zpop- ct - dv2- o- s- c. mn dp1=%par am1%"

    Endi f

    The script uses three dimension statements to define inputs for DevState,Ovrd1, and Ovrd0. The logic that follows the dimension statements reads theinputs for the above attribute values to determine which set of inputs makesany of a series of ifexpressions true.

    For instance if Ovrd1 = 1 and DevState = 2, then the script displays the

    following two bitmaps using these path names:

    "c: \ cust om\ di spl ays\ operat i ng\ common\ bmp\ s- cb- a- 1. bmp""c: \ cust om\ di spl ays\ oper at i ng\ common\ bmp\ s- cb- a- 1f l . bmp"

    The bitmap images are identical but use different shades of the color red. Thefirst bitmap uses a medium red and the second bitmap uses a dark red. Thefirst bitmap is called out using the Bitmap command, while the second

    Metso Automation 2785882-16

  • 7/21/2019 278588 Maxscript A

    45/77

    Creating maxSCRIPTs Using Simple Examples

    bitmap is called out using the fBitmap command. To create the illusion of asingle flashing image, the fBitmap command causes maxVUE in runtimemode to display both bitmaps alternating in rapid succession.

    Note that the script is written to display only one of two flashing bitmapswhen the proceeding ifconditional logic is satisfied. The fBitmap command

    is used in three other places in the script followed by a null text string as inthe following:

    Bi t map "c: \ cust om\ di spl ays\ operat i ng\ common\ bmp\ s- cb- a- 5. bmp"f Bi t map " "

    When a script uses the fBitmap command, you must continue to use thiscommand in other places that call for a bitmap even when a flashing bitmapis not desired. For instances where a flashing bitmap is not desired, use thefBitmap ""script construct to nullify or cancel a flashing bitmap command.

    Also note that the path for the bitmap may be a fully qualified pathname as in

    this example or it may be a partial path as in the Hiding a Button in a PopupDisplay example.

    Metso Aut omation 278588 2-17

  • 7/21/2019 278588 Maxscript A

    46/77

  • 7/21/2019 278588 Maxscript A

    47/77

    Chapter 3

    maxSCRIPT Script LanguageReference Guide

    OverviewThe maxSCRIPT OCX control uses a Basic-like script language, allowingyou to create maxVUE display applications using a more free-formprogramming approach. The script language, developed by Metso

    Automation, uses elements, such as dimension statements, commands,variables, and logical expressions, providing you with a rich codinglanguage. All the elements you may currently include in your script files arelisted in this reference chapter. Each of the following sections describes thescript element and its general syntax, and shows you how the element istypically incorporated in script using basic examples.

    Using Dimension StatementsThe following sections discuss the four basic uses of dimension statements in

    maxSCRIPT.Generally, dimension statements are used to define names thatmay be used to read and write data. Dimension statements may containspecific point identifiers, however, in most cases it is more advantageous touse parameters instead. Refer to "Making Scripts Portable UsingParameterization" in Chapter 1.

    Creating Local Variables

    Local Variables can be created through dimension statements using thefollowing syntax:

    Dim as

    Where:

    any string that uniquely identifies this value in the rest of the script is from

    Dbl double variableInt integer variableStr string variable (string characters such as a description, or tagname)

    Metso Aut omation 278588

  • 7/21/2019 278588 Maxscript A

    48/77

    maxSCRIPT User's Guide

    Notewhen you first create them, double variable (0.0), integer variable (0)and string variable () begin as null values. The following technique can beused to do something on the first pass only:

    Example

    Di m f as I ntI f f = 0Let f = 1. . do somet hi ng

    Endi f

    Creating Objects in the Local Status Server

    Use dimension statements to create objects in the Local Status Server,fromwhich other controls can access information produced by maxSCRIPT.These objects are automatically created and deleted as maxVUE screens arecalled up. Use an Out type Dimension statement at the beginning of the scriptto declare these objects. Because there may be multiple instances of the same

    maxSCRIPT controls on a single graphic, names of output objects must beunique.

    Syntax for Dim statements

    Dim as (.)

    Where:

    any string that uniquely identifies this value in the rest of the script any valid SBP service name any valid SBP extension

    consist of the following in and out types:

    In Types:

    xxxIn types refer to an already existing variable, which is to be used in acalculation.

    DblIn Double precision, floating point numberIntIn Integer variableStrIn String characters such as a description or tagname

    Out Types:

    xxxOut types create (and delete when the screen closes) an LSS object foroutput (as well as input if necessary) so that other controls can access thecalculated results. A is created for the purpose of housing outputsin the Local Status Server. The same service can (and should) be used formultiple members. The members can be of all different types.

    DblOut Double precision, floating point numberIntOut Integer variable

    Metso Automation 2785883-2

  • 7/21/2019 278588 Maxscript A

    49/77

    Creating maxSCRIPTs Using Simple Examples

    StrOut String characters such as a description or tagname

    Examples:

    di m xyz as Dbl Out ( b. condou)di m i 12 as I nt Out ( b. coni nt )

    di m t xt as St r Out ( b. cont xt )

    di m asaw as Dbl I n( saw. ao)di m l ss_ser vi ce_count as I nt I n( _l ss. numsvc)di m now as St r I n( _l ss. t i me)

    Caution:The statement

    Di m A as St r Out ( _sel _pt . t agname)

    has the unfortunate effect of deleting the selected point object when the scriptis terminated. It is up to the script writer not to use existing local status

    variable names in an xxxOut dimension. Use the Dimx statement to write toexisting local status variables:

    Di mx A as St r Out ( _sel _pt . t agname)

    Performing External Writes

    When accessing an existing object (such as _sel_pt) as an output, write thedimension statement as dimx.

    di mx s as St r Out ( _sel _pt . t agname)

    When out types are used with the dimx command, an existing variable isassumed (and not created or deleted).

    Usedimx to write to existing software backplane service members, such asDPU point (service) attributes (members) and LSS service members.

    The function of thexis to prevent script from creating an _lss variable of thename (.), which is deleted when thescript is terminated.

    Dimx is only functional for:

    di mx I nt Out ( . )di mx Dbl Out ( . )di mx St r Out ( . )

    Should you write a dimx statement for xxxIn types, the script will performlike a dim statement without the x. Thexis ignored for inputs.

    di mx I nt I n(. )di mx Dbl I n(. )

    Metso Aut omation 278588 3-3

  • 7/21/2019 278588 Maxscript A

    50/77

    maxSCRIPT User's Guide

    di mx St r I n( . )

    Caution: because there is potential for security bypass or inadvertentoperation, you must exercise great caution when you use the dimx scriptinstruction.

    Syntax

    Dimx as (.)

    Where:

    any string that uniquely identifies this value in the rest of the script any valid SBP service name any valid SBP extension is IntOut, DblOut or StrOut

    Example

    Di mx sel pt as St r Out ( _sel _pt . t agname)Let sel pt = f i c101

    Performing Demand Writes Using Command Statements

    In many situations, maxSCRIPT will need to write the same value multipletimes during a process. For these instances use a dimension statement thatincorporates a command, a type of transaction supported by maxDPU.

    A command is an action that takes place upon a write from the softwarebackplane. Although commands are not readable, you might write the samevalue each time (0, for example).

    Syntax for Dim statements:

    Dim as (.)

    Where:

    any string that uniquely identifies this value in the rest of the script any valid SBP service name any valid SBP extensionconsist of the following out type:

    IntCmdOut Integer variable outputsCmdOut String variable output

    Example

    Di m got oman as I nt CmdOut ( %par am1%. opcmdman)I f Mousecl i ck

    Let got oman = 0Endi f

    Metso Automation 2785883-4

  • 7/21/2019 278588 Maxscript A

    51/77

    Creating maxSCRIPTs Using Simple Examples

    Without the use of the command statement, maxSCRIPT only writes thevalue once, assuming nothing has changed since the last write. The commandstatement, in effect, forces a demand write. maxSCRIPT will perform thewrite regardless of what was written to this command the last time, and itwill not subscribeto the command to update current values.

    Note that the maxSCRIPT variable Display (See Table 1-1 above) uses thesCmdOut command statement on behalf of the user.

    Note that normal outputs DO subscribe to values and can be used as inputs.

    Example:

    di m a as I nt Out ( t est. out )i f a = 5

    Let a = 0Endi f

    Note that acan be read and written by the script.

    Subscribing to Keyboard Groups Using _Keyboard

    Use a dimension statement containing Di mx to access _keyboard, a LocalStatus Server (LSS) member service. This object is used in script to permitapplications, such as displays containing buttons, to respond to keystrokesfrom the operator keyboard.

    The service, _keyboard, is used to buffer keystrokes from the operatorkeyboard. A subscription to the keyboard takes the form:

    Subscribe _KEYBOARD.BUFFER.

    Where indicates the desired key clusters, represented by a singleletter:

    M - odeD - isplayP- anC - ursorZ - oomU - serL -ogic

    S - etpointO - utputA alarm

    For example:

    Subscribe _KEYBOARD.BUFFER.MDP to subscribe to mode, display andpan key clusters.

    Metso Aut omation 278588 3-5

  • 7/21/2019 278588 Maxscript A

    52/77

    maxSCRIPT User's Guide

    Multiple applications can subscribe to a group of keys. All subscribers aresent a data update when a key is pressed. Only the maxSCRIPT of theselected point should respond to the keystroke.

    The following is an example maxSCRIPT that intercepts the Alarm Groupkeys:

    di mx key as i nt out ( _keyboar d. buf f er . a)di mx Al m_Ack as i nt cmdout ( %param1%. Al m_Ack)Di mX Def eat as I nt CmdOut ( %param1%. Def eat )i f key

    i f ( sel pt = "%param1%")i f key = 626l et Al m_Ack = 1

    l et key = 0el sei f key = 627

    Let Def eat = 1Let key = 0

    el sei f key = 628

    Let Def eat = 0Let key = 0

    endi fendi f

    endi f

    The dimension statement in the previous example is subscribing to the userfunction keys:

    _keyboard. buf f er . a

    Finding Keycodes

    Notice that the script in the preceding example references a specific functionkey by its number code, 626. The following script can be used to findkeycodes:

    Di m key as I nt I n( _keyboar d. buf f er . ncpdzuml soai )Di m out as I nt Out ( t est . out )

    Let out = key

    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 alwaysfollowed by a zero around one second after the key has been pressed.

    Interacting with Other maxVUE Controls

    You may use dimension statements that allow a maxSCRIPT control tointeract with other maxVUE controls, such as the Bar Control, List Control,and so forth.

    Metso Automation 2785883-6

  • 7/21/2019 278588 Maxscript A

    53/77

    Creating maxSCRIPTs Using Simple Examples

    Your script may include one of the following out types

    Dblctlout Double precision, floating point number output to themaxVUE object.

    Intctlout Integer number output to the maxVUE object

    Strctlout string characters output to the maxVUE object

    Your script may include one of the following in types

    Dblctlin Double precision, floating point number read from amaxVUE object.

    Intctlin Integer number read from a maxVUE object

    Strctlin string characters read from a maxVUE object

    To interact with other controls on a given maxVUE display, use thefollowing syntax:

    Dim as ctlout(.) or

    Dim as ctlin(.)

    Where:

    is the alias for this parameter within maxSCRIPT is replaced by Dbl, Int or Str; note that the out/in types include thecharacters ctl, indicating the script will interact with other controls. Forexample, Dblctlout. is the name of the object as seen and set in the Layers buttonof the maxVUE Editor is from the list:

    x - the x position in percent of screeny - the y position in percent of screenwidth - the width of the objectheight - the height of the objectcolor - the Fill Color of a maxVUE static objectlinecolor - the Line Color of a maxVUE static objectPropertyName - the Property Name of the control object

    Refer to Appendix A ffor perperty names of standard maxVUE controlobjects.

    Example:

    Metso Aut omation 278588 3-7

  • 7/21/2019 278588 Maxscript A

    54/77

    maxSCRIPT User's Guide

    Di m x as I nt Ct l Out ( obj ect. x)Di m y as I nt Ct l Out ( obj ect. y)Let x = 20Let y = 10

    Note: when you select Test Mode in the maxVUE Editor, scripts can modifythe parameters of other unsaved controls, such as width, height, x or y, orcolor. Be sure to save any unsaved controls prior to testing to prevent this.

    Color is best represented by a dblvalue. The dblvalue should be calculatedas:

    Di m obj col or as Dbl Ct l Out ( obj ect. col or )Di m col or as dblDi m r ed as i ntDi m gr een as i ntDi m bl ue as i ntLet red = ; number f rom 0 to 255

    Let gr een = ; number f r om 0 t o 255

    Let col or =RGB ( r ed, gr een, bl ue)

    Let obj col or = col or

    When creating a maxVUE group with a script interacting with anothercontrol use this syntax:

    I nt Ct l Out ( . )Dbl Ct l Out ( . )St r Ct l Out (