PML For Starters and Beginners
PML For Starters and Beginners
DISLAIMER
This tutorial is for those who are using AVEVA PDMS in their day-by-day work and wants to know the
system deeper and automate work and make the system do whatever they wants.
This is for the starters who don’t know about programming at all and for the beginners who can already do
some simple tasks. Those who are experienced PML gurus probably also find something useful.
And for sure this is for any PDMS administrators who must have PML knowledge for better doing their
duties. Enjoy!
Any questions please send – [email protected] (I’ll try to reply everyone but apologies beforehand for
any delay ).
This tutorial should not be used as a training guide or as a training material. It is only to give a basic
explanation of what is PML, simple constructions etc. User should be trained on a PML training course
provided by AVEVA to get full knowledge needed on starting to make programs.
This tutorial is explaining only the concept and basic of PML but will not be explaining how to create own
forms and functions and complex methods or how to set some environments. This will be described in
another tutorial.
INTRODUCTION
PML (Programmable Macro Language) so called macro-language of PDMS is a PDMS built-in interpreted
programming language which:
Does most of the actions user run thru PDMS interface – it’s a PML supplied with installation of
PDMS (For example when user press some button then it is PML code executed and do
something)
Used in any user-defined macros or functions that could be developed by ANY user to create for
example some function that not exist in standard supply but needed for user. (For example user
can create its own GUI – Graphical User Interface like forms, special functions etc)
Could automate nearly every action, which is repeated by user from day to day and takes much
time to perform – (we will call it “Quick Macro” and use QM abbreviation further in this tutorial)
The main manual describing the PML called Software Customisation Guide for PML basics and Software
Customisation Reference Manual for PML2 objects and their members and methods. Both manuals
supplied with the system
In general every user can learn PML as far as there is no need to have any deep programming skills but
just understanding of:
User who wants to know and use PML should have a basic knowledge of PDMS and be familiar with
described points. For example, user should not be scared of word EQUI or ZONE level or Attributes or P-
Point etc. This knowledge could be given on AVEVA’s training course. Contact your nearest AVEVA’s
representative - http://www.aveva.com/en/Contact/Worldwide_Offices.aspx - for training proposal.
In addition, it is needed to know the meaning of simple terms like variable, if statement or do loop. It is
also will be explained here in simple words.
There are two versions of PML language – more ‘old’ called PML1 and a ‘new’ called PML2. We will not
be explaining the difference except that PML2 is object-oriented programming language but will mostly
use PML2 constructions as far as this is more modern language and most GUI is done with it. However
there could be some constructions which are better to be done with PML1 – will be marked.
To write any PML code you should use comfortable for you text editor with feature to show line
numbers and better to syntax highlighting. Author uses Freeware Notepad++. For instructions how
switch on syntax highlighting please email author.
Warning: You should never modify the original PML files, so that you can always revert to using these if
things go wrong.
Warning: Please consider the naming convention for macro files in order to easy navigate and prevent
any conflict with existing files. Some recommended rules for naming:
Always use a unique prefix in file name. For example author uses his initials (lsa) like
lsamymacro.pmlmac to make the files unique
or another example - a company name like xyzmymacro.pmlmac
Although it is not mandatory but it is recommended to use extension .pmlmac in macro files
Starting from PDMS version 12.1 all macroses should be saved in UTF-8 format (Unicode)
PROGRAMMING BASICS
1.Variables
Variables are used to store values.
Variables have names.
The value that is stored can be changed but the name of the variable is fixed once it is defined.
You choose the names and decide what is stored by each variable.
Values can have different types like Integer or String.
Values with different types should be converted to same before processing.
By analogy, the variable could be interpreted as a ‘box’ where you put something to or take something from. And this ‘box’ has
a name to clearly identify what is stored inside. And boxes with same type of content could interact to each other.
Names of variables in PML should start with ‘!’ symbol and have meaningful name.
Examples:
!boxHeight
!boxDescription
!equipName
etc
To assign a value to variable (to put something in a ‘box’) you have to decide what type of data it will be.
Most used types are:
<STRING> - the value should be put within single quotes or vertical bars, could not be used in
arithmetical expressions unless converted to <REAL>
<REAL> - any integer value, could be used I arithmetical expressions. Could not be used in string
operations unless converted to <STRING>
<DBREF> - this is a special PDMS type pointed to an object in database with all its attributes
!equipName = /E1201
Here we created variable called !equipName and assign a value /E1201 with no single quotes but with a slash in front, so it means variable
!equipName will have a <DBREF> type
NB. Pointing the slash as a first symbol will automatically give to the system a signal that you try to refer to some item with this name. So if
there is no item with such name then it will be an error.
Now we have three variables of different types. So what can we do with them? Lets review some
arithmetical operations… Like it was said before only variables with type <REAL> can be involved into
these operations. All others should be converted to <REAL> (if possible) before.
The following example will be used to find a volume (V) of a box with known different sides (a,b,c)
V = a*b*c
!aSide = 1000
!bSide = 500
!cSide = 300
Now we have to create an arithmetical expression for calculation and result should be stored in another
variable. Normally it could be done like:
!boxVolume = !aSide * !bSide * !cSide
So we defined variable !boxVolume which will store result of calculations of several variables
Let check it in PDMS.
Create a file called regarding your naming conventions (in my case it will lsaPML1.pmlmac) in any folder
you have access (in my case it will be c:\temp\pmlexamples\) with following code:
!aSide = 1000
!bSide = 500
!cSide = 300
q var !boxVolume
The last command means to query (q) early-defined variable (var) with some name. Result of querying
will be output to PDMS’s command line.
Now try to run this. Open command line and type - $M/path_to_your_file
In my case it will be - $M/C:\temp\pmlexamples\lsaPML1.pmlmac
NB.Nearly every variable storing non-<STRING> type of data can be converted to <STRING>
Only digits stored as a <STRING> can be converted to <REAL>
Alert – is a message popping up on a screen and asking user to interact. In our case we will use Input
dialog. Let see how it works.
Imagine the situation when our volume has 2 constant sides (a,b) and one which could vary by user
input. Then our code will look like:
!aSide = 1000
!bSide = 500
!aSide = 1000
!bSide = 500
!cSide = !!Alert.Input(‘Please input the C-side’,’300’)
q var !boxVolume
Save this code to next macro file and run in PDMS like it was done previously with $M/
Using ‘.’ and some method we can do some operation applying it to variables of different type. In
example we used method .Real() applied to <STRING> variable to convert it into <REAL>. Full list of
methods listed in Software Customisation Reference Guide
2.IF statements
IF statement is used to let the system compare two values and by the result of comparison we can select
what to do.
Normally values of variables are compared.
<REAL> should be compared with <REAL>, <STRING> with <STRING> etc.
Result of comparison is TRUE (statement is TRUE) or FALSE (if statement is FALSE)
By analogy, remember our ‘variable-box’? Imagine that one ‘box’ contains an apple and other ‘box’ contains a peach. You want
to eat an apple but you don’t know which ‘box’ stores it. You have to check. So you put your arm into one box and IF you find an
apple THEN you eat it ELSE (peach) you do nothing.
Now we will compare the value of the input with 2. Not forgetting to convert input to <REAL>
If (!userVariable.Real() EQ 2) then
!!Alert.Message(‘You have input correct value’)
Else
!!Alert.Message(‘You have input incorrect value. Please put 2’)
RETURN
endif
Here we used IF statement to check if our input variable is EQual to 2. We have used EQ operator to check for equality. If result of statement is
FALSE then we un another message and quir from the program execution by using command RETURN. We user another type of Alert –
Message to output a simple message on a screen)
Quick examples of comparisons. Imagine we have two variable one is called !realVariable which stores
some <REAL> value and the other is !stringVariable which stores some <STRING> value. And we will
compare them to some values.
3.DO LOOP
DO LOOP is used to perform actions over multiple (collection) items
Usually collection is an ARRAY variable each cell of which contains some data of particular type like
ARRAY of <STRING>s or ARRAY of <REAL>s.
By analogy, remember our ‘variable-box’? Imagine that this ‘box’ contains 10 apples and we have to check if all ten are fresh.
We can do it by picking them up one by one and do check. DO LOOP is doing the same – you have a collection and one by one
you doing same actions on each item in collection
As a result, you will get 5 messages on a screen. One by one until DO LOOP ends on 5
4.COMBINATIONS
You can now combine IF statement and DO LOOP.
--To get the Size we will introduce another variable for storing this values can use a method called .Size() applied to earlier defined ARRAY
--Here it is:
!digitArraySize = !digitArray.Size()
--To understand if the value is even or odd we have to take value and try to divide by 2
--if result of the division will contain a decimal point then value was odd otherwise it was even
--lets do it
--first make a division (remember in each iteration !x will have a next value) and this is <REAL> type
!resultOfDivision = !x / 2
--check for point. We will use MATCHWILD method which is applied to STRING object to find if there something we’d like to find
--so we also will be converting result of division stored in previous variable to <STRING> type
!isThereAPoint = !resultOfDivision.String().Matchwild(‘*.*’)
--so previous variable will store TRUE if variable !resultOfDivision contain point and FALSE – if not
Enddo
!digitArraySize = !digitArray.Size()
Do !x from 1 to !digitArraySize
!resultOfDivision = !x / 2
!isThereAPoint = !resultOfDivision.String().Matchwild('*.*')
Enddo
Do !x from 1 to !digitArray.Size()
!resultOfDivision = !x / 2
!isThereAPoint = !resultOfDivision.String().Matchwild('*.*')
If (!resultOfDivision.String().Matchwild('*.*').Not()) THEN
!!Alert.Message('Value is ' + !x.String() + ' and its even.')
Else
SKIP
endif
Enddo
Or even shorter
--put number in a <STRING> then split it and get array
!stringNumber = ‘1 2 3 4 5’
!digitArray = !stringNumber.Split()
Do !x from 1 to !digitArray.Size()
!resultOfDivision = !x / 2
!isThereAPoint = !resultOfDivision.String().Matchwild('*.*')
If (!resultOfDivision.String().Matchwild('*.*').Not()) THEN
!!Alert.Message('Value is ' + !x.String() + ' and its even.')
Else
SKIP
endif
Enddo
TO BE CONTINUED…