PML Course Iranpiping
PML Course Iranpiping
Programmable Macro
Language
PML & PML2
2
Agenda
Introductions
Objectives
Course Format
Prerequisites
3
Introductions
Who am I?
Who are you?
– Company
– Job Description
– Knowledge of PDMS
– Expectation of course
4
Prerequisites
Text editor
– Notepad
– UltraEdit
– Emacs
PDMS Environment
– PMLLIB work area
– PDMS project
Knowledge of PDMS
PDMS 11.4 or above
5
Objectives
Course Format
Course Contents
Day 1
PML Overview
PML 2 Jargon
P DS Functions Rgr
OO O oup
TH s
ME
Objects
Object Blocks es
PMLLIB am
es Fr
Typ
b le
aria Too
V ltips
c
fl n
lobj .pm
.pm .pmlfrm
13
Features Of PML2
To run a macro
use the PDMS
command line
15
PML1: Synonyms
Exercise 1
Before starting this exercise copy the pmllib
directory identified by your trainer to your C: drive.
Then edit the evars.bat file in the %pdmsexe%
directory to include your c:\pmllib directory in the
%pmllib% environment variable.
Named variables
– !variablename or !!variablename
– single ! Means a local variable
– double !! Means a global variable
variable names may be up to 16 characters long and the
names can contain alpha and numeric characters
NEVER start a variable name with a number
NEVER use ‘.’ (dot or period) In variable names
22
VAR !x ‘NAME’
Sets the variable to the text string NAME
Run this macro on the command line and see the effect:
$m/c:\pmllib\mac1
27
!XLEN = 1000
!YLEN = !XLEN + 100
!ZLEN = !XLEN + 1000
Using PML1:
VAR !Z ( ‘$!X’ + ‘$!Y’ )
NOTE: all PML1 variables are STRING data types
Using PML2:
!Z = !X + !Y
29
Expression operators
–+-/*
– LT GT EQ NE LE GE
– NOT AND OR
– SIN COS TAN SQR POW NEGATE ASIN ACOS
ATAN LOG ALOG ABS INT NINT
!s = 30 * sin(45)
!t = pow(20,2) - raise 20 to the power of 2
!f = (match(name of owner,’LPX’) gt 0)
30
()
*/
+-
EQ NE GT LT GE LE
NOT
AND
OR
Example:
(60 * 2 / 3 + 5) = 45
31
For example:
Remember all PML1 variables are STRINGs so in the above example !Z would be the
STRING value ’96’ not a REAL
33
Arrays
!x[1] = ‘Hello’
An ARRAY variable can contain !x[2] = ‘World’
many values, each of which !y[1] = ‘fred’
is called an array element !y[2] = ‘cup’
!z[1] = !x
An array is created automatically
!z[2] = !y
by creating one of its array elements
q var !z[1][2]
An array element may itself be an array: <string> ‘World’
Multi - dimensional Arrays q var !z[2][2]
<string> ‘cup’
34
Exercise 2
35
Do loops
DO !ppoint FROM 1 TO 6
PDMS/PML Syntax
ENDDO
Open Do Loops:
Do loops (cont’d)
Do loops (cont’d)
DO !X values !ARRAY
!X takes each ARRAY element value
ENDDO
DO !X Index !ARRAY
!X takes a number from 1 to !ARRAY size
ENDDO
38
Do Loops Examples
IF Statements
IF (‘expression’) THEN
PDMS/PML Syntax
ENDIF
40
IF Statements
The ELSEIF statements
allow for further conditions
to be tested. Once the IF
or one of the ELSEIF IF ( ‘expression’ ) THEN
statements has been PDMS/PML Syntax
found to be TRUE, any ELSEIF ( ‘expression’ ) THEN
remaining ones are PDMS/PML Syntax
ignored. ELSE
PDMS/PML Syntax
The ELSE statement is ENDIF
used as a ‘catch-all’, if
none of the IF/ELSEIF
statements was satisfied
the commands in the
ELSE block are used.
41
Branching
Conditional Branching
PDMS/PML Syntax
GOLABEL /FRED IF (!x.eq(100))
More PDMS/PML Syntax
LABEL /FRED
PDMS/PML Syntax
Do !A
$P Processing $!A
do !B to 10
!C = !A * !B
golabel /finished if (!C.gt(100))
$P Product $!C
enddo
enddo
label /finished
$P Finished with processing = $!A Product = $!C
44
Error Handling
/FRED
Handle (2,109) $* Undefined name
-- pml code executed when /FRED does not exist
Elsehandle NONE
-- pml code executed when /FRED does exist and no error occurs
Endhandle
47
$!ItemNameOrRef
Handle (2,107) (2,109) $* Undefined name or reference
-- code to take action if these errors occur
elsehandle any
-- An ANY Handle Block is processed for any errors.
-- In this situation it would handle ANY errors other than (2,107) and (2,109)
elsehandle NONE
-- A NONE Handle Block is processed only if there were no errors
endhandle
48
Day 2
MPIPE
$S CALLP=$M/%PDMSUI%/DES/PIPE/$s1
CALLP MPIPE
51
!BranchHeadBore = !!CE.Hbore
!HeadPosition = !!CE.Hposition
!Easting = !HeadPosition.East
!PosWRTValve = !HeadPosition.WRT(!Valve)
53
!Pos = !!CE.Position
!Pos.Up = 2000
!!CE.Position = !Pos
55
PML2 Functions
Exercise 4
58
Using Methods
Method Concatenation
if ( !Value.ge(99)) then
-- if !value is greater than or equal to 999 then
-- execute this block of PML code
else
-- otherwise execute this block of PML code
endif
61
!GreaterThanZero = !SomeValue.gt(0)
if (!GreaterThanZero ) then
-- some PML code is executed if !SomeValue is greater -- than zero
endif
if ( !!MyFunction() ) then…
62
!MyString = ‘TRUE’
if ( !MyString.Boolean() ) then ...
63
Alert Forms
64
Confirm Alerts
!Answer = !!Alert.Confirm( ‘Are you sure!’ )
Confirm alerts return ‘YES’ or ‘NO’ as strings
Question Alerts
!Answer = !!Alert.Question( ‘OK to delete Site?’ )
Answer alerts return ‘YES’ or ‘NO’ or ‘CANCEL’ as strings
66
Form Definition
To hide a form:
!!Myform.Hide()
Form Gadgets
There are many kinds of form gadgets as you will see on the
following slides.
When you are defining gadgets on a form, there are two
common aims.
– Define the area to be taken up on the form
– Define the action to be taken if the gadget is selected
Each gadget size and position determines the area taken up
The action is defined by the gadget’s CALLBACK
71
!!Myform.myButton.Active = FALSE
!!Myform.myTextField.setFocus()
72
Callbacks
Form OK Callback
A Simple Form
setup form !!hello File:
c:\pmllib\hello.pmlfrm
!this.formTitle = ‘myFirstForm’
paragraph .Message text ‘Hello
world’
button .bye ‘Goodbye’ ok
exit
77
Gadget Positioning
Form Origin
Gadget Origin
78
XMIN
XMAX
At Xmin .apply Ymax - 0.5
at ymin
at xmax .frame1 + 4
Paragraph Gadgets
Button Gadgets
!!ex5.Apply.Background = 2
Frame Gadgets
Text Gadgets
A text input gadget provides a place on a form into which the user
may type a value.
List Gadgets
A list gadget allows the user to make a single or multiple choice
from many alternatives.
Textpane Gadgets
Exercise 5
91
Day 3
Form Creation
92
Exercise 6
93
Array Declaration
!NumberOfNames = !NameStrings.Size()
!MyArray.Clear()
!NewArray = !OldArray.RemoveFrom(5,10)
!OldArray.RemoveFrom(5,10)
Exercise 7
101
Notice the dot ‘.’ separator between the name of the variable
and the name of the method.
To create a tooltip:
Toggle Gadgets
...
Toggle .bold ’Bold’ Call '!this.boldSelect()’
Toggle .italic ‘Italic’ Call '!this.italicSelect()’
Toggle .underline ’Underline' Call '!this.underlineSelect()’
…
105
The value of a toggle gadget is set and used via the .val
member which is a BOOLEAN value:
if (!this.Bold.val.eq(true)) then
-- some pml code
endif
Rgroup Gadgets
Exercise 9
111
Option Gadgets
An option gadget offers a single choice from a list of items.
The items in the list can be either pixmaps or text strings, but
not a mixture. The gadget displays the current choice in the
list.
When the user selects the option gadget, the entire list of
options appear as a drop-down list. The user can then select
the required option with the cursor.
112
!ColourArray[1]=’Black’
…...
!ColourArray[5]=’Blue’
!This.Colour.Dtext = !ColourArray
114
Exercise 10
115
Day 4
The CE button
A CE button typically calls the form initialisation method to
reset the form for the current element in the database.
setup form !!myForm
member .CEREF is DBREF
!this.initcall = |!this.init()|
button .ce ‘ CE ’ callback '!this.init()'
para .cename width 30 height 1
exit
define method .init()
!this.CEREF = !!CE
!this.cename.val = fullname
endmethod
119
The FORMAT object controls the display format for REAL text
gadget values. An example of this is imperial feet&inch units
for distances, or imperial inch units for bores.
Bar Menus
– Execute a callback
– Display a form
– Display a sub-menu
124
Exercise 11
126
These are:
All Variable types, BORE, DIRECTION, DBREF, FORMAT,
MDB, ORIENTATION, POSITION, FILE, PROJECT,
SESSION, TEAM, USER, ALERT, FORM, all form Gadgets
and various graphical aid objects.
PDMS Objects
BORE
DB
DBREF
DIRECTION
MDB
ORIENTATION
POSITION
PROJECT
TEAM
USER
129
ALERT OPTION
ALPHA PARAGRAPH
BAR RGROUP
BUTTON TEXT
FORM TEXTPANE
FMSYS TOGGLE
FRAME VIEW
LIST 2D VIEW
MENU 3D VIEW
130
3D Geometry Objects
ARC
LINE
LINEARGRID
PLANE
PLANTGRID
POINTVECTOR
RADIALGRID
XYPOSITION
131
!line = !input.WriteRecord()
To read all the input file:
!filearray = !input.ReadFile() Files are opened and
To write all of the data to file closed automatically
!output.WriteFile(‘WRITE’,!filearray)
133
Exercise 12
135
()
ta
da
define object VIEWCLIPDATA
ip
cl
member .Pos is POSITION
ew
member .XLen is REAL
vi
ct
member .YLen is REAL
je
ob
member .ZLen is REAL
=
member .Ori is ORIENTATION
ed
endobject
!fr
136
A Constructor METHOD
Method Overloading
Day 5
View Gadgets
Plot View
Exercise 13 (part I)
149
End of Course