100 PML's Tips and Tricks
100 PML's Tips and Tricks
100 PML's Tips and Tricks
AVEVA
AVEVA
PAUSE command allows to make a delay before executing next line of code. Delay is in seconds.
Example. Countdown:
clock init
$P before moment X is left:
do !x from 10 to 1 by -1
$P ... $!x seconds
PAUSE 1
Enddo
$P Moment X has come!
clock read
002. Opening and automatic updating Association Manager form on system start
Variant with file start from folder %pdmsui%\des\start
In the end of the file add the lines:
Show !!associationmanager
!!associationmanager.showAssocs( !!ASSOCIATIONMANAGER.REFRESH, |SELECT| )
In the same way, you can run any other procedure or form
AVEVA
Where
<attribute_name> - attribute name, e.g., TYPE or DESC or DTXR etc.
2. In PML:
var !CPML EVAR CPML
!namespacePath = !CPML + 'library'
!execute = |IMPORT '| + !namespacePath + |'|
$!execute
AVEVA
Q var !var.String('D1')
<STRING> '12.5'
Q var !var.String('D2')
<STRING> '12.46'
Q var !var.String('D3')
<STRING> '12.456'
Here we use String('Dn') function, where n is desired number of digits after the point. Besides system round values according to basic
arithmetics rules.
Other variant:
!draw = object drawlist()
!glbDraw = !draw.Globaldrawlist().Members()
if (!glbdraw.size() EQ 0) then
RETURN
endif
!RT = object array()
do !x from 1 to !glbDraw.Size()
!RT[!x] = !glbDraw[!x].String()
enddo
!BLOCK = OBJECT BLOCK('!RT[!EVALINDEX].DBREF()')
!LIST = !RT.EVALUATE(!BLOCK)
!VOLUME = OBJECT VOLUME(!LIST)
!LIM = OBJECT GPHVIEWS()
!LIM.LIMITS(!!GPH3DDESIGN1.VIEW, !VOLUME)
AVEVA
015. Centring on CE
!!gphAlwaysRotate(!!gph3ddesign1.view, !!ce)
Also, for example, for starting Auto Clash on system start, it is required to add call of xmenuauto (pdmsui\des\clasher) file in
appdesmain.pmlfrm (PMLLIB\design\forms).
Similarly, you can run commands for other modules using file start from modules directories, e.g. dra\admin\start for Draft
module.
AVEVA
019. How to suppress message about exit from pick mode after pressing Esc key
If we run into pick mode with command ID@ and after exit it pressing Esc key, we get a message
This message can stop program executing. For suppressing it we could use the following code:
prompt off
prompt load escape |Pick elements and press Esc|
ID @
HANDLE(61,528)
ENDHANDLE
--Actions
--For example
!name = !!CE.Name
022. Finding out element creator (who created the first session with the element)
Variant 1
--Query history of an element
VAR !allHistory HISTORY
Q var !allHistory
<STRING> '826 825 820 816'
--as we can see, the first session when element appeared is 816
--make array from a string
!historyArray = !allHistory.Split()
q var !historyArray
<ARRAY>
[1] <STRING> '826'
[2] <STRING> '825'
[3] <STRING> '820'
AVEVA
Variant 2
-- Query history of an element and split it into array
VAR !allHistory history
!historyArray = !allHistory.Split()
--Query database name which contains a current element and create database object (DB)
VAR !CEDB DBNAME
!DBO = OBJECT DB(!CEDB)
-- get the last element of the array (it is number of the first session)
!firstSession = !historyArray[!historyArray.Size()]
--and determine author and date
!CreateAuthor = !DBO.Session($!firstSession).Author
!CreateDate = !DBO.Session($!firstSession).Date
Variant 3
--query attributes CRUSER, CRDATE, CRSESS
Or
var ! fullyInVolume collect all EXCLUSIVE within e1000 n1000 d100 to e10000 n 30000 u1000
do !x from 1 to ! fullyInVolume.size()
ADD $! fullyInVolume [$!x]
ENHANCE $!fullyInVolume [$!x] COLOUR GREEN
Enddo
For including elements which partly lie in the given volume remove keyword EXCLUSIVE
AVEVA
Decoding
!coco = !!dehash(889413)
q var !coco
<STRING> 'FAER'
This operation could be required for getting real numeric value of WORD type
034. Using IFTRUE operator
Example output into report brwei value or zero value if brewi couldnt be calculated.
AVEVA
IFTRUE checks the first argument, if its true then it will return the second argument, otherwise the third argument.
035. Difference in element collection methods
There are different element collecting methods
PML1 - method (the simplest):
VAR !items COLLECT ALL ( <itemType> ) FOR CE
037. How to get coordinates of mouse click on element (not Origin point)
To get coordinates of some place on the element where a user clicked you can use command PICK:
VAR !pickMe PICK
After the command system switches to mode of selecting element and after selecting is done make a query:
Q VAR !pickMe
AVEVA
ENDHANDLE
NEW RECT ASDEF @ creating square by picking centre (1) and corner (2)
VAR !GETXLEN XLEN width
VAR !GETYLEN YLEN height
AVEVA
opposite corners
length of side
VAR !GETDEG ADEG angle
VAR !GETLEN LENGTH
AVEVA
Number of rows is defined by NROW attribute and NCOLUMN for columns. Rows and columns have equal size
proportional to table size and its number, i.e. width if column would be equals to ( XLEN / NCOLUMN ), and height of row
equals to ( YLEN / NROW ). Size of row and columns is changed dynamically by changing table size.
NEW DMND DEF @ creating diamond by picking three points: start (1), width (2) and height
(3)
All primitive elements have origin point, that can be queried using:
VAR !GETORIGIN ORIGIN
Q VAR !GETORIGIN
<STRING> 'CENTRE X 366MM Y 195MM'
AVEVA
049. How to move content of view to centre after change size of view
ONPOS 0 0 reset position of centre of view content
AUTOSCALE recalculate scale
UPDATE ALL refresh view
050. How automatically to set size of view by 3D coordinates
AUTOSIZE FROM POSITION1 TO POSITION2 from the first 3D coordinate to the second (two opposite corners)
Or you can use mouse to change size of existing view:
AUTOSIZE FROM @ TO @ - click at any to places in existing view and change its size (usually shrink it)
After changing size you can automatically change scale by AUTOSCALE and refresh a picture by UPDATE ALL
051. How to collect elements of different owners
VAR !GETMEMBERS COLLECT ( ALL SITE MEM ALL ZONE MEM ALL EQUI MEM ) FOR CE collect members of the given elements
AVEVA
2. Open file VARS of module Design (%PDMSUI%/Des/Admin/) and add following lines to the end of it
$S QB = $M/%PMLLIB%\arQB.pmlmac
$U QB
3.Restart PDMS/Marine
Now if you select flange and type command QB in command window, it will execute the code of the macro (which is
linked with the synonym)
It is possible to make synonym available for all users, to do this you should copy changed VARS file to your network
folder %PDMSUI%/module/admin
NB. Code above does not handle any errors, e.g. if bolts do not have references to description or material.
AVEVA
055. How to collect elements with given value of the first member attribute
var !getItems COLLECT ALL SPEC WITH ( STEXT OF FIRST MEM EQ 'INSU' ) collects array of elements, whose attribute of the first
member equals to given value (the given example collect all specification of isolation)
056. How to find enhanced labels and run position alignment
Var !getEnhacedLabels SPLIT ENHANCE get array of labels enhanced by command ENHANCE
SPREAD LOCAL XOFF < XOFF value> YOFF <YOFF value> SELECT ALL FROM !getEnhacedLabels positions labels locally using given offsets
by axis.
If you want to calculate offsets for given length of leader line (radius) and angle, you can use the following expressions:
XOFF value = length of leader line * COS (angle)
YOFF value = length of leader line * SIN (angle)
SPREAD REMOTE OMIT <OMIT value> GAP < GAP value> MARGIN < MARGIN value> SELECT ALL FROM !getEnhacedLabels positions labels
- prevent Labels being placed alongside the specified side OMIT value (combination of LEFT RIGHT BOTTOM TOP)
- minimum gap between two labels GAP value
- rectangle corners around which labels will be positioned X1,X2,Y1,Y2 values
057. Setting view direction for 3D view
!!gphViews.look(!!gph3Ddesign1.view, N90D) plan North
!!gphViews.look(!!gph3Ddesign1.view, S90D) plan South
!!gphViews.look(!!gph3Ddesign1.view, E90D) plan East
!!gphViews.look(!!gph3Ddesign1.view, W90D) plan West
!!gphViews.look(!!gph3Ddesign1.view, N) look at North
!!gphViews.look(!!gph3Ddesign1.view, S) look at South
!!gphViews.look(!!gph3Ddesign1.view, E) look at East
!!gphViews.look(!!gph3Ddesign1.view, W) look at West
!!gphViews.look(!!gph3Ddesign1.view, S45W35D)
ISO1
Next in PML open file C:\temp\screen.txt , read it and split the second line. The first value will be Height , the second
Width
!screenFileObj = object file(!screenInfoFile)
!screenHeight = !screenFileObj.ReadFile()[2].Split()[1].Trim()
!screenWidth = !screenFileObj.ReadFile()[2].Split()[2].Trim()
Q var !screenHeight
Q var !screenWidth
059. How to calculate distance between two points (straight segment length)
Variant 1. Using temporary PINs. Place them into corresponding coordinates and query distance between them using
PML 1 commands:
--pick the first element, get its position, and after that place PIN there
Author: Sergey Lebedev / Vladimir Shebastyuk
AVEVA
ID @
!pos1 = !!CE.Pos.Wrt(WORLD)
PIN 1 AT $!pos1
-- pick the second element, get its position, and after that place PIN there
ID @
!pos2 = !!CE.Pos.Wrt(WORLD)
PIN 2 AT $!pos2
--query distance
VAR !getDistance CONST DIST PIN1 TO PIN2
Q var !getDistance
Examples:
1. Automatic start of project with selected user, MDB and module
pdms.bat DESIGN SAM SYSTEM/XXXXXX /SAMPLE
2. Automatic start of project with selected user, MDB, in non-graphic mode (command line mode) and macro executing,
at that
If macro will manage switching of modules, then module should not be specified in arguments and system will log in
into system database:
pdms.bat TTY SAM SYSTEM/XXXXXX /SAMPLE $M/c:\myMacro.pmlmac
or
pdms.bat BATCH SAM SYSTEM/XXXXXX /SAMPLE $M/c:\myMacro.pmlmac
or
pdms.bat NOGRAPHICS SAM SYSTEM/XXXXXX /SAMPLE $M/c:\myMacro.pmlmac
If you need to enter into specific module, then you should add its name in the beginning:
pdms.bat DESIGN TTY SAM SYSTEM/XXXXXX /SAMPLE $M/c:\myMacro.pmlmac
AVEVA
or
pdms.bat DRAFT BATCH SAM SYSTEM/XXXXXX /SAMPLE $M/c:\myMacro.pmlmac
or
pdms.bat PARAGON NOGRAPHICS SAM SYSTEM/XXXXXX /SAMPLE $M/c:\myMacro.pmlmac
3. Automatic start of project with selected user, MDB and module in read only mode
pdms.bat DESIGN readOnly:True SAM SYSTEM/XXXXXX /SAMPLE
4. Automatic start of project with selected user, MDB and module in integrate schematics and engineering mode (3D
Schematic Integrator licence will be used)
pdms.bat DESIGN INTEGRATEDMODE SAM SYSTEM/XXXXXX /SAMPLE
5. Automatic start of project with selected user, MDB and module without console window
pdms.bat DESIGN NOCONSOLE SAM SYSTEM/XXXXXX /SAMPLE
AVEVA
067. How to draw aid label in the head and in the tail of a branch
--read coordinates of the head and the tail of a current brunch
!getHpos = !!CE.Hpos
!getTpos = !!CE.Tpos
--draw aid labels at these coordinates
AID TEXT 'Head' AT $!getHpos
AID TEXT 'Tail' AT $!getTpos
AVEVA
This form reads attlib.dat file, which contains all system attributes, from installation root. Editing the file is not
permitted.
072. How to query full description of attribute
How to get attribute type, size, full name and etc.
VAR !data ATTDEF attribute NAME RPTX TYPE DEFI SIZE VISI QSET UNIT
Where attribute is a name of analyzed attribute, and arguments written with green are necessary characteristics of the
attribute.
In !data is returned array, which size and order of elements depend on which characteristics and their order were
supplied.
Example of query:
VAR !data ATTDEF POS NAME RPTX TYPE DEFI SIZE VISI QSET UNIT
Q var !data
<ARRAY>
[1] <STRING> 'POS'
[2] <STRING> 'POSITION'
[3] <STRING> '8'
[4] <STRING> '5'
[5] <STRING> '3'
[6] <STRING> 'true'
[7] <STRING> 'true'
[8] <STRING> 'DIST'
List of characteristics:
NAME name of attribute
RPTX full description of attribute (Report Text)
TYPE type of attribute value
0 = All
1 = Integer
2 = Real
3 = Logical
4 = Text
5 = Reference
6 = Word
7 = Orientation
8 = Position
9 = Direction
AVEVA
2 = Dynamic
3 = DDL or Dynamic
4 = Pseudo
5 = DDL or Pseudo
6 = Dynamic or Pseudo
7 = DDL or Dynamic or Pseudo
After that operation array !getAttList will contain all attributes of the system (unordered)
074. How to select rectangle area on drawing
VAR !getWindow RSHPOS @
The coordinates of corners of rectangle area selected by user will be saved in variable !getWindow
075. How to select labels on drawing using area selecting
--select area
VAR !getWindow RSHPOS @
--split to coordinates values
var !LeftX PART(|$!getWindow|,2)
var !RightX PART(|$!getWindow|,6)
var !LeftY part(|$!getWindow|,4)
var !RightY part(|$!getWindow|,8)
--check how clicks were done (left to right or right to left)
if (($!LeftX) GT ($!RightX)) then
var !TMP |$!LeftX|
var !LeftX |$!RightX|
var !RightX |$!TMP|
endif
if (($!LeftY) gt ($!RightY)) then
var !TMP |$!LeftY|
var !LeftY |$!RightY|
var !RightY |$!TMP|
endif
--select labels
ENHANCE ALL (GLAB SLAB) WITH (xyps[1] GE ($!LeftX) AND xyps[1] LE ($!RightX) AND xyps[2] GE ($!LeftY) AND xyps[2] LE ($!RightY)) FOR VIEW
--get array of selected labels
VAR !getEnhanced SPLIT ENHANCE
AVEVA
Where !FILE variable is set as the name of the appropriate file with default settings
079. How to get list of global and local variables
Q VAR LOC shows the list of local variables for current session
Q VAR GLO - shows the list of global variables
080. How to determine whether a variable exists or not
VAR !checkVar DEFINED ( !someVar )
Queries existence of variable with name !someVar. If it exists then the variable !checkVar will be returned as true,
otherwise as false
081. How to do different types of sorting
Lets have the following array !array
[1] <STRING> 'Camel'
[2] <STRING> 'Zebra'
AVEVA
[3]
[4]
[5]
[6]
<STRING> 'Wolf'
<STRING> 'Pig'
<STRING> 'Dog'
<STRING> 'Giraffe'
Result:
As you can see in array !SortIndex were put indices of elements of array !Array according to alphabetical order
2. Sorting of element indices according to descending alphabetical order of elements
VAR !SortIndex SORT !ARRAY DESCENDING
Result:
It should be considered that method sort() sorts original array and after sorting is done you cannot get original order
back. Therefore if you need to save original array you should define additional variable and assign value of original array
to it:
!newArray = !array
!newArray.Sort()
Then the original array will remain as it was, and the new one will be sorted.
082. How to check if value is set
Author: Sergey Lebedev / Vladimir Shebastyuk
AVEVA
Command $M- inside macro gets a signal to the system to pause execution and allows a user to make some actions.
To resume macro execution from the line where it was stopped use command $M+
085. How to handle error
Usually errors stop code execution, but sometimes it is necessary to resume work of macro even if an error occurs.
Example:
-- create new element with a given name
NEW EQUI /EquiName
--handle error, which occurs if such a name already exists
HANDLE (41,12)
$P Name already exists
DELETE EQUI
--if there is no error, then execute another code
ELSEHANDLE NONE
$P Created
ENDHANDLE
AVEVA
If there are some opened (and not closed) files, then their names will be returned.
088. How to convert text file to UTF-8
!FileToConvert = 'c:\temp\textfile.txt'
!ConverterPath = 'C:\AVEVA\Plant\PDMS12.1.SP4\Transc.exe'
SYSCOM 'CMD /C $!ConverterPath 0 "$!FileToConvert" 65001 -s -b &'
Convert to UTF-8
!FileToConvert = 'c:\temp\textfile.txt'
!ConverterPath = 'C:\AVEVA\Plant\PDMS12.1.SP4\Transc.exe'
SYSCOM 'CMD /C $!ConverterPath 0 "$!FileToConvert" 65001 -s -n &'
At that macro XAUTO (PDMSUI\des\clasher) is called, which calls DCLASHER by the command CALLCL DCLASHER $!SYSTEM
$!FORCE
092. How to display message in the bottom left corner of the program window
PROMPT 'Message in bottom left corner'
To hide it use:
PROMPT DISMISS
AVEVA
We need to climb from SPCO level to SPEC level, at the same time collecting some attributes of SPCO elements of the
way.
AVEVA
The command returns colour of a current element, if it was found in Autocolour Rules.
097. How to execute .Net command
import 'PDMSCommands'
handle (1000,0)
endhandle
using namespace 'Aveva.Pdms.Presentation.PDMSCommands'
!commandManager = object PMLNETCOMMANDMANAGER()
!commandManager.executeCommand('Aveva.Pdms.Presentation.HistoryBackwardCommand')
You can see the list of build-in .Net commands if you open Customisation form (right click in toolbar and select
Customization) and selecting any Command look at its Command attribute:
AVEVA
098. How to find out colour and translucency of element, which were set by Autocolour,
or selected manually
--get Drawlist
!getDrawlist = !!gphDrawlists.drawlist(!!GPH3DDESIGN1.VIEW)
--query colour. item_id is Dbref
!getColour = !getDrawlist.colour(item_id)