1、Trainer NotesPML2 Training NotesWhats New in PML2Objects and Object methodsForm names are now preceded with !i.e. setup form _fredfollowed by : setup form !fredresults in an error because !fred was already defined in the previous assignmentForms are now loaded dynamicallyreturn error noalert allows
2、an error to be returned without any messagesWhat to avoid in PML2Commands with dollars in $m- $m+ $W25Numbered variables $v1-120The var command var !x name var !x readSynonymsGlobal variablesWhat to avoid in forms and menusDots in gadget namesselector gadgetsUserdataPixmap viewsAlert gadgetsRadiogro
3、upsSimple Textin gadgetsNumbers at the beginning of gadget namesWaiton to show formsDo list/pane/selWhats not changed in PML2In theory, all old PML should work in PDMS11.1. Very little of the old appware has been converted because this would be a waste of resources. Cadcentre policy on converting ap
4、pware to use new facilities is to only upgrade appware when modifications are being made in that area.The only exception to this, is where new facilities in core code supersede or improve functionality and it is necessary to write new code to use the extra functionality.New Environment VariablesPMLL
5、IB /DIRECTORYNAMEThis is a directory which is searched when the system looks for functions and forms PMLTRACE ON/OFFWhen set to ON, PMLTRACE will display a trace of all macros called in the unix command shell. This can also be switched on or off on the command line, so it is probably better to set t
6、he variable to off and use commands to control trace as before.The command in PDMS is - PML TRACE ON/OFFPMLCOMPILE ON/OFFEnvironment variable PMLDEBUG ON will write a trace fileAvailable variable types$v1 old style not recommended!a Named variables both global and local !global !localNOTE: !a is eva
7、luated as text automatically by using $!A (early evaluation)Named variables are now typed variables as one of the followingSTRING Text in quotes or vertical bars up to a Max of 254? charREAL Any numberBOOLEAN TRUE,FALSE These are not text i.e. TRUE,FALSEARRAY Any type including arrays of arrays of a
8、nythingOBJECTS A collection of different variables under a user defined typeVariables can be predefined as a particular type or revert to type when they are setThere are two ways of setting variablesVar !a (25) !a is a string!a = 25 !a is a real!a = xyz !a is a string!a1 = 75 !a1 is a real element o
9、f array !a Note: other elements in the same array can be of any type!a = TRUE !a is BOOLEANBeware Pre version 11 the var command was used to set all variables and it produced a string. Now we dont use var apart from collections.Variables may also be created before they are used using Methods!Answer
10、= real()!textline = String()!test = boolean()!squares = array()All of the above have the value unset There are various ways of testing whether a variable exists or is set:If(undefined(!x)thenIf(defined(!x)thenIf(unset(!x)thenIf(!x.unset()thenIf(set(!x)thenIf(!x.set()thenTo make a variable undefined
11、i.e. empty it.!x.delete()var !x delete Arraysarrays may be sparse i.e. you can set in index order Negative subscripts are not permittedA subscript of zero can be used but is not adviseddo loop from and to variables can now include expressions and even functionsArray methods!arraysize = !arraything.s
12、ize() Replaces var !arraysisze (arraysize(!arraything)Sets the variable arraysize to the number of elements in the array!testarray.clear() Deletes all elements from !testarray!test.removefrom(5, 20) Removes 20 elements from element number 5!new = !test.removefrom(5,20) Removes 20 elements as above a
13、nd creates a new array with the 20 elements inside.!myarray.append(!newdata) acts like var !array append fhjffj!myarray.27.delete() Deletes element 27 of the array the array still exists!myarray.delete() Deletes the array entirely!line = this is a line of text with some funny spaces !line = !line.tr
14、im(lrm) trims the spaces from the variable called !line!line = this is a line of text with some funny spaces !lines = !line.split(!line) Splits the string !line into an array of strings called !lines.Note: we could not use the same variable name because it is a different type!a = !lines.size() gives
15、 the number of elements in the array!a = !lines.width() gives the number of characters in the longest word of the arrayNo result methods.!lines.sort() sorts the array !lines and returns the array in its sorted form!lines.invert() inverts the array order first to last etc. These methods work only on
16、the original array. Attempts to set another array results in an error.i.e. !new = !lines.sort() Gives an error The old method.!ind = !lines.sortedindices() Produces a sorted index without changing the original array. This can be used to sort parallel arrays in the same way as before.!lines = !lines.
17、relindex(!ind) Re-orders an array according to the order of array !indIf applied to the original array, it would have the same effect as a simple sort, its use is to sort parallel arrays.The Current Element variableThere is one global variable which is always set by the system to be the element you
18、are positioned at in the database - this is called !CE. !CE is an object of type DBREF. Its attributes are described as members of the object. e.g.!tem = !ce $* creates a variable which is a copy of !ce1q var !tem $* Queries the attributes of the DBREF pointed to by !item =8196/8 NAME - DA/2000 TYPE
19、 - SITE LOCK - FALSE OWNER - =8196/0 DESC - MAIN REACTOR AREA FUNC - PURP - NUMB - 0 AREA - 0 POS - E 0mm N 0mm U 0mm WRT /* ORI - Y is N AND Z is U WRT /* MODU - ORRF - Unset STMF - Unset :MATERIAL - Carbon Steelq var !item $* gives/DA/2000 $* without all of the other stuff!item $* as a command, do
20、es nothing$!item $* navigates to /DA/2000Querying attributes q var !item.pos $* gives E 0mm N 0mm U 0mm WRT /* ORIGIN =8196/0 UP 0 EAST 0 NORTH 0q var !item.e $*query the east position 0q var !item.pos.origin $* gives all of the attributes of =8196/0 q var !item.pos.origin.lock $* gives the lock of
21、=8196/0q var !item.pos.wrt(=8196/32) $* uses the method WRT(DBREF) to extract a $*position relative to some other database $*referenceMETHODS/FUNCTIONSDifferent data types in pml have associated built in methods which may be used to convert or read data in a particular way. Some methods are similar
22、to the built in functions pre version 11.1 as in the example below:!NCHARS = !MYSTRING.LENGTH() $* THIS IS A METHOD!NCHARS = LENGTH(!MYSTRING) $* THIS IS A FUNCTION CALLThe pre version 11.1 syntax for the function call would have been as follows:VAR !NCHARS LENGTH(|$!MYSTRING|) $* THIS IS A 10.5 FUN
23、CTION CALLThe difference between the 10.5 example and the 11.1 example is that version 11 now returns a typed variable (REAL) where version 10.5 would have returned a string.Methods are built in for various data types and are listed in appendix A of the Customisation guide.Block evaluation of arrays
24、Block evaluation is a method of stepping through each element of an array and performing some action. In effect, it is like a single command do loop.To perform block evaluation, there are two stages:First you need to define the expression which will operate on the array elements Second, you need to
25、apply the expression to an arrayThe expression is stored in a variable and is defined as follows:!EXPRESSIONVAR = OBJECT BLOCK (!ARRAYNAME!EVALINDEX * 2)the !arrayname!evalindex bit is effectively the name of the variable being operated on by the expression. In the example above, the result would be
26、 to multiply all of the numbers in the input array by 2. The variable !evalindex is a special variable used in block evaluation. Any other variable name will not work! To apply the expression is as follows:!newarray = !arrayname.evaluate(!expressionvar)This creates an array called !newarray containi
27、ng the numbers of the original array multiplied by 2. The original array can also be modified using this method:!arrayname = !arrayname.evaluate(!expressionvar)Here are some simple examples !text = this is a line of text!myarray = !text.split()This creates an array called !myarray with six elements!
28、myarray1 = this!myarray2 = is!myarray3 = a!myarray4 = line!myarray5 = of!myarray6 = textNow we can define some blocks!extractchar1 = object block (subs(!myarray!evalindex,1,1)!new = !myarray.evaluate(!extractchar1)This extracts the first character of each word into and array called !newgiving the fo
29、llowing:!new1 = t!new2 = i!new3 = a!new4 = l!new5 = o!new6 = t!extractchar1 = object block (upcase(subs(!myarray!evalindex,1,1)!new = ! myarray.evaluate(!extractchar1)This does the same as before, but also changes the letters to upper case!new1 = T!new2 = I!new3 = A !new4 = L!new5 = O!new6 = T!extra
30、ctchar1 = object block (upcase(subs(!myarray!evalindex,1,1) & |fred|)!new = !myarray.evaluate(!extractchar1)This does as before, but uses the & character to append the string fred to the result!new1 = Tfred!new2 = Ifred!new3 = Afred!new4 = Lfred!new5 = Ofred!new6 = Tfred!extractchar1 = object block (!t
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1