Download - PML Basics Part 1

Transcript
Page 1: PML Basics Part 1

PML Basics Part 1 - 10-25-2006

Alright expert and cvitte71,I did promise to get more involve with pdmsworld. So here we go. I will start adding new thread for those who want to learn PML, starting with the basics (PML 1) working my way to PML2, forms, functions, you get the idea.

To start out, I wanted to introduce the Dollar $ symbol and its meanings

$M = Runs a macro in pdms$! = Evaluate a varieble$. = Terminates a macro$S = Defines a synonym $G = Defines a global synonym$S- = Turns synonyms off$S+ = Turns synonyms On$QS = Queary's the synonyms$H = Help$Q = Another syntax help$P = Prints a line to your command line$$ = Adds a $ symbol$D = Default argument value

$* = Comment line$( = Starts a comment block$) = Ends a comment block

To turn the pml trace on and off I use

$R To turn trace Off$R6 To turn trace On$R109

Another neat trick that I like to use, especially when using the trace isALPHA REQ CLEAR (I will get more into this as I add more and more treads)This command cleans your command line.

I really hope everyone gets involve and If i miss anything please added to the tread.

A query on usage in the field: how much do you use the $ comments (either $* or $(...$) )?

(For those of you at the ISEITs this is to do with Published PML...)

I want to be able to strip comments when publishing the PML, and am wondering just how much trouble to go to with wierdly nested and hidden comments! (I will never mangle anything, but might not strip all the comments if you do really odd things)

I use the $* comments as much as possible. Specially because I'm the kind of person who will write a macro and forget about it and 6 months later someone is asking me to add some new function to the macro. I try to add as much comments for my own personal benefit.If you are new to pml and you want to make life easier. I suggest you try to comment as much as possible. Also, name you macros something that will make since 6months to even years from now. I have spend hours, days even months writing macros only to misplace them. By adding as much comments, you are not only making your life easier but your employeer as well. This go back to the ISEIT meeting.

Page 2: PML Basics Part 1

JCont....mate its simply awesome.....very useful...please keep it up!....

I reckon better add the ALPHA LOG command...where you can take ur logs to a file and not flood ur command line :)

---------------------------------------------------------------------------------------------------------------------Yes I agree.

When using the Tracking, you might want to use the alpha log command first. Try this.

Alpha log /C:/test.txt over By adding the over, I am overwriting any file with the name Test.txt

Turn trace on$R6

Than, using the pull downsModify > Name

The modify name form will come up and your command line filled with text.$RTo turn off the Trace

Alpha log endTo end the log

Open the .txt file and check out some of the code. That is how I learn pml, by reading aveva's code.

Just a note: You are only allowed to have one log file open at the time. Another option will be to use Alpha Files. I'll get to that later.

I just found this and I wanted to pass it on....Enjoy

$R<n>

1 = Tracing to shell window (default)2 = Tracing to requests window4 = Tracing of only input lines executed8 = Tracing of all input lines16 = Tracing without $ expresion (default off)32 = Tracing includes line numbers64 = Tracing of macro/function changes100 = General Debugging102 = capture trace in ALPHA LOG

Can also do $HR at the command line to get all options for $R---------------------------------------------------------------------------------------------------------------------Quote:

Originally Posted by TimSharrock A query on usage in the field: how much do you use the $ comments (either $* or $(...$) )?

(For those of you at the ISEITs this is to do with Published PML...)

I want to be able to strip comments when publishing the PML, and am wondering just how much trouble to go to with wierdly nested and hidden comments! (I will never mangle

Page 3: PML Basics Part 1

anything, but might not strip all the comments if you do really odd things)

Hello Tim,

I use $( and $) for large blocks of comments or for quick trouble shooting. But for individual lines of code / comments, I will normally use -- because I do not need to hold down the SHIFT key to get the -- to appear (quicker commenting for single lines).

From your personal opinion, is there a preference between $* and -- ? Does one single-line commenting method work better than the other? Just curious ...

Have a Blessed Day

If I do not remember wrong, you cannot use -- for inline comments where you can use the $* syntax.

like:handle any $* Taking care of a problem. If I remember correctly you cannot do this with --endhandle

I recall reading somewhere that -- can only be used for commenting whole lines.=====================================================================

Quote:

Originally Posted by TBack If I do not remember wrong, you cannot use -- for inline comments where you can use the $* syntax.

yes that is the case.

Quote:

Originally Posted by proverbs3:6 From your personal opinion, is there a preference between $* and -- ? Does one single-line commenting method work better than the other? Just curious ...

at the start of the line they are treated identically, so no preference

This is the macro I am using to test comments so far - I have lots more odd things to add!

Code:

$P this macro tests comments in various formats$* $P this is an ordinary one-line comment$P this line is not a comment-- $P this is a new-style comment$P this line is not a comment either$( $P a short 'multi-line' comment $)$P I am not a comment - I am a free line!$($P a long multi-line comment$P yes, I mean it$)$P now to test some combinations$P start a new-style -- in the middle of a $P $P start an old-style $* in the middle of a line$P embed a multi-line $(like this$) in the middle of a line

Page 4: PML Basics Part 1

$P try hiding a multi-line with old-style$* $($P I wonder if this will come out$* $)$P try hiding a multi-line with new-style-- $($P I wonder if this will come out instead-- $)$p what about the end of a multiline?$($P this is within a multi-line$* $)$P this is after a hidden closer

$P this is at the end

I didn't know I could comment out part of a line with the $*. !!

awesome!!!

  (#17)

That is the beauty of using the $* comment syntax. You can write them on the same line as the actual code.

Hi gentlemen,

I am used to run a macro loaded with my favourite synonyms when I start PDMS. So I tried to use the command $QS as I saw it in the first post. Now I see in command window the list and I would like to get clear something.

There are synonyms with $S1 before the synonym description. Example :

$S1 AA = add all within volu ce $S1

Then I have here synonyms with $S0 (all my syns + some more). Example :

$S0 FGF =new fla choo all new gask choo all new fla choo all (short sequence for inserting pair of flanges)

And then finally there are some synonyms with $SU1 for running a macro. Example :

$SU1 CALLE =$M/%PDMSUI%/DES/EQUI/$S1

I don't understand the difference between $S0, $S1, $SU1. Is it supposed to be an argument? Are not arguments in general $n - without 'S'? What does it actually do? And why it says :

(47,33) CP: Illegal macro format

When I try to run the macro for myself (in this case : $M/%PDMSUI%/DES/EQUI/$S1 )?

Page 5: PML Basics Part 1

One question...

Why "$*" and "--" are not equivalent?

"$*" works any position in the line, and "--" works only at the beggining of the line.

Why AVEVA designed the comment like that? Any reason?

Possible to use $R5 /FILE.name

PML Basics Part 2 (Creating an Array) - 10-25-2006

What is an Array?The simple answer to me would be a collection.

How to create an Array!Array = Array()This is an empty variable but it has been defined as an array

Page 6: PML Basics Part 1

Adding to the arrayType 1!Array[1] = 'BOB'!Array[2] = 'GEORGE'!Array[3] = 'KELLY'

Type 2!Array.Append('BOB')!Array.Append('GEORGE')!Array.Append('KELLY')

q var !Array

Other Command to know when using an array

!Array.Clear()!Array.Size()!Array.Sort()!Array.SortUnique()!Array.Unique()

You can find out more in the PDMS Manual, Search Array Objects.

wats the difference between type1 and type2......sorry am just starting to learn PML..so forgive me if im asking sumthing verryy basic!

Also I was thinking if u can put some treads with examples......like

1. How can we assign values to elements using PML...e.g. If I have to assign pspec /A300 TO ALL PIPES WITH BORE SIZE 100

2. How do we collect elements and run a macro on them...e.g. collect ALL brances under zone /10LAB and set/change Ispec to /HC

and so on.....

What is the difference between type1 and type2. Now, they are not called type1 and 2, I just added that so everyone can see that you can do more that one way. An array is a collection when you use the [ ] and specify a number, you are telling the exact order you want that item to be in.

For example:

!Array[1] = !!CEI am adding my current element to the first member of the array

When I use type2!Array.Append(!!CE)I am simply adding my current element to the list (The end of the list)

Now, you added 2 questions. I believe that cvitte71 has a hot tread about collections.In order to do what you are asking for we are going to need to use a loop. I'm going to be posting another PML Basics (Loop) and I'll use your questions as examples.

Check out my new thread on loopsPML Basics Part 3 (Creating a Loop)

Page 7: PML Basics Part 1

I added you question as the examples.

PML Basics Part 3 (Creating a Loop) - 10-26-2006

Here we go again. Out of everything that I have learn about pml, I had the most difficulty learning Loops. I didn't understand them, finally after many mistakes I got a handle on loops.

What is a loop?It’s a series of commands that will continue to happen until the loop is broken.

DoThis starts a loop, now one of my first mistakes was that I didn't specify the number of times I wanted the loop to run and I didn't know how to break the command

EnddoFor every "Do" you must have an "Enddo"

Now I know I haven't covered collections but you can check out a nice sticky threat cvitte71 has started. So let’s do a simple macro. This macro will collect all sections, check the gtype to make sure its correct and print any sections that have the incorrect gtype.

var !Coll coll all (SCTN GENSEC) with (Gtype of Catref neq Gtype of Sctn) for $!!CEI know this is not PML2; lets get the basics out first.

Do !x from 1 to !Coll.Size()Now, what does this line mean? I already explained that the "Do" starts the loop.The second parts "!x", is a number any number. In this case from 1 to !Coll.size(). In other words, the first time the loop runs, !x will equal 1 then 2 so on until it reaches !Coll.Size()

What is !coll.size()?It’s the number of items inside the !coll array.

$P $!Coll[$!x] has the wrong Gtype$p is the print command$!Coll[$!x] mean $!Coll[1] which is the first item in the collection

Enddo

$**********************************************with out the comments$**********************************************

var !Coll coll all (SCTN GENSEC) with (Gtype of Catref neq Gtype of Sctn) for $!!CE

Do !x from 1 to !Coll.Size()$P $!Coll[$!x] has the wrong GtypeEnddo

I'll add more example later today.

Hello,you can also use:

Page 8: PML Basics Part 1

var !Coll coll all (SCTN GENSEC) with (Gtype of Catref neq Gtype of Sctn) for $!!CE

Do !x indices !Coll $P $!Coll[$!x] has the wrong GtypeEnddo

or

Do !x values !Coll $P $!x has the wrong GtypeEnddo

Yes Thank you bh0nst. Keep them coming.

When you use the:

Do !x indices !Coll!X is still a number

But when you use:

Do !x values !Coll!x is now the item or an element

More examples, this is a request by 786PDMS

1. How can we assign values to elements using PML...e.g. If you have to assign pspec /A300 TO ALL PIPE WITH BORE SIZE 100

First, You have to do a collection for all Pipe with bore eq 100. Again, cvitte71 has a great thread on collections going on.

Var !PIPE COLL ALL (PIPE) WITH (PARAM[1] OF CATREF OF SPCO EQ 100) FOR $!!CE

Do !x indices !PIPE$!PIPE[$!x]PSPEC /A300Handle Any $* Why did I add a Handle, the pipe could of been claim or locked, this way the macro will continue$pError on $!PIPE[$!x] $*Printing the error so I can identify the element that the pspec was not assignedEndHandleEnddo

2. How do we collect elements and run a macro on them...e.g. collect ALL brances under zone /10LAB and set/change Ispec to /HC

Var !BRANCH COLL ALL BRAN FOR /10LAB

Do !y indices !BRANCH$!BRANCH[$!y]Ispec /HCHandle any$pError on $!BRANCH[$!y]EndHandleEnddo

Page 9: PML Basics Part 1

Are you going to examine OBJECTS, especially the COLLECTION OBJECT. And the use of this object? Like you pointed out in your thread, the other collections thread explores multiple ways to create the collection using both PML1 and PML2. Very intriquing. The multiplicities of options in using PML can be daunting.--------------------------------------------------------------------------------------------------Yes, I'll start getting more into object collect & object collections. Here is another example using a different type of collection

!BRANCH = !!CollectAllFor('BRAN', '', !!CE)

Do !y indices !BRANCH$!BRANCH[$!y]Ispec /HCHandle any$pError on $!BRANCH[$!y]EndHandleEnddo

PDMSGuru, I'm not a piping designer (my back ground is structural) and I got the information on how to queary the pipe bore from a previous threat you answered, could you double check my previous collection. I don't want to give anyone the wrong information. Specially since we are not running pdms out of the box, we have customize pdms to an extreme.================================================================As you get an array of element references directly by using the CollectAllFor function you could also assign the attribute value without first jumping to the element, like:

!BRANCH = !!CollectAllFor('BRAN', '', !!CE)

Do !y indices !BRANCH!BRANCH[!y].Ispec = /HCHandle any$p Error on $!BRANCH[$!y]EndHandleEnddo

The selected element would in this example remain the same also while running through the loop.

jcont20,

Your collection would now have worked.

Var !PIPE COLL ALL (PIPE) WITH (PARAM[1] OF CATREF OF SPCO EQ 100) FOR $!!CE

PIPE Elements do not have CATREF's, in addition, the BORE ATT on a PIPE element is not even an intelligent one.

A way I could accomplish this is

Var !PIPE COLL ALL BRAN MEM WITH (p1 bor EQ 100) FOR CE

Collecting Branch members themselves is the best way I find to work with piping components. Heads and tails may change on branches, and sometimes they don't even reflect what's in the pipe, a head bore may be 100, then the first mem is a reducer, the rest of the branch might then be 150. so working with branch members is better in my humble opinion.

Next, notice I asked for the p1 bore, this guarantees me that I will add an element with at least one side of it matching my criteria, I could add more criteria to guarantee that I get

Page 10: PML Basics Part 1

anything that has 100 as a bore, p1, p2 , p3 etc. But by asking for catalogue parameters, I'm assuming that my catalogue administrator hasn't done anything silly with the first parameter. An event that has undone me in the past.

Also, to clean it up a bit, you don't need the $!!CE, just CE will do.

Tip: on anything that has a SPRE with a CATREF, the CATREF is also available for query from that element. So instead of CATREF of SPRE, (I would not say SPCO, as that is an element, and not a reference), you could just call the CATREF, it is a pseudo attribute.

I've heard some really good things about you jcont20, someone that spoke with you at the Americas Conference in the US says you are doing some great things with Ring Plates. Your company is lucky to have you, and so is PDMSWORLD. Keep up these great posts. I'll comment when you invite me to. I really enjoy reading them.

Thanks for asking me to pitch in, I am honored.

Hi JCont20,

Thank u 4 explaining things much better than the manuals :)....i did try ur and others code and its a good practice as a start...for one of our real projects i have to rename ALL zones with name contaioning -PREM to -PRELIM

e.g. Zone /16CS-UHA-21.4-PREM needs to be renamed to /16CS-UHA-21.4-PRELIM

please review my code below and guide me how to rename the zones as required above...i belive my collection is ok..but only the rename part i need to fix with ur help

define function !!APMCheckLevel()

Var !PRZONE COLL ALL (ZONE) WITH (MATCHW(NAME,'*-PREM*') ) FOR $!!CE

Do !y indices !PRZONE$!PRZONE[$!y]RENAME ....HOW?????Handle any$pError on $!przone[$!y]EndHandleEnddo

endfunction

I'm not in front of PDMS at present (can't afford the software at home)... So I can't check this... Check this in a limited area before running.....

Define Function !!APMCheckLevel()

var !PRZone coll all Zone with (Match (Name of Zone, 'PREM') gt 0) for ce $* I like Match instead of Matchwild

Do !z values !PRZone $* Used Values instead of Index...$!z!NewName = !z.Before('PREM') + 'PRELIM' $* Will take current name z, strip off PREM, and add PRELIMRename $!NewName$p $!z renamed to $!NewName $*Just Prints the old and new to command lineEndDo

Page 11: PML Basics Part 1

EndFunction

Can be done in one row...

Quote:

Originally Posted by 786PDMS Do !y indices !PRZONE!PRZONE[!y].Dbref().Name = !PRZONE[!y].Dbref().Name.Replace('-PREM','-PRELIM')Handle any$p Error on $!przone[$!y]EndHandleEnddo

Guyz thankz a bunch.....

@Tbacktried ur code and it works beautiful!!.....

@ccottoni'll also try urs and see how it goes....just wondering wats the diff b/w

Match and MatchWDo values and Do Indices

Quote:

Originally Posted by 786PDMS

just wondering wats the diff b/w

Match and MatchWDo values and Do Indices

Match(NAME OF ZONE, |ABC|)NEQ(0) $*If somewhere in the name of the zone the letters ABC appear then this expression is TrueMatch(NAME OF ZONE, |ABC|)EQ(0) $*If the letters ABC does not appear then the expression is True

Matchw(NAME OF ZONE, |*ABC|)$*Let say the name is /123-ABC, then this expression is True$*Let say the name is /ABC-123, then this expression is False. It works like windows search. In order to make this expression true, it would have to read like this.MatchW(NAME OF ZONE, |*ABC*|)

$* !Coll is an arrayDo !x values !coll$!X $* in this case, X is a reference number

Do !x indice !coll$!X $* in this case, X is a number (1,2,3, you get the point)

Page 12: PML Basics Part 1

Hope this help, sorry it took me so long, I have been out of the country and extreamly busy...But I guess everyone is busy now and days...

Hi I'm new in the forum and I hope somebody can help me because I want to make an array checker, that compare every element of the array and delete the elements repeated from the array.

HELLO,there is especial commands for work with arrays in the PDMS manuals.you can use "UNIQUE" for delete the duplicate values.more info: PDMS Software Customisation Guide 6-9 Version 11.6SP1 bye.

Hi JCont20The GTYPE macro is brilliant...one of my colleuges was just talking about that discrepancy the other day...

Would it be much mor ework to actually correct that discrepancy ?

SURE, YOU CAN FIX IT. I HAVE A SCHEDULE TASK THAT TAKES CARE OF IT FOR THE USER.WORKS SOMETHING LIKE THIS.

Code:

!SCTN = !!CollectAllFor('SCTN' , 'Gtype of sctn neq Gtype of Catref', World)

Do !x INDICE !SCTN IF !SCTN[$!x].CATREF.UNSET() Then $P$!SCTN[$!X].NAME is unset skip EndIf

!SCTN[$!x].GTYPE = !SCTN[$!x].CATREF.GTYPE HANDLE ANY $PError with sctn $!SCTN[$!x].Name ENDHANDLEENDDO

Regarding JCont20's macro...

var !Coll coll all (SCTN GENSEC) with (Gtype of Catref neq Gtype of Sctn) for $!!CE

Do !x from 1 to !Coll.Size()$P $!Coll[$!x] has the wrong GtypeEnddo

Just starting to look at PML and macros..

Could anyone tell me if i'm correct on my assumptions..

To break down the first line...

var !Coll - this defines a local object of this name

Page 13: PML Basics Part 1

coll - is this a commmand to make a collection ?

$!!CE - this is a global object of this name

$P $!Coll[$!x] has the wrong Gtype - what do the square brackets do [] ?

Thanks for the help...Neil

!Coll is array of sections's and gensecs's names whose gtype not equal gtype of catref. It is collection from current element ($!!CE).Coll - you are right, this is command to make collection and to store it in array !Coll.$!!CE gives reference number of CE.$P $!Coll[$!x] - in [] number of array's element is indicates, in this case $!x is number of current cycle of the loop.

Alright, Sorry I have been gone for so long, I have been extremely busy like everyone else in the PDMS community.

Here is a small simple macro to using a do loop.

Multiple copy command for draft

Code:

Define Function !!MultiCopy()

!CS = Current SessionIf !CS.Module().NEq('DRAFT') Then returnEnddo

!element = !!ceDo New $!Element.Type copy prev On ID @ Handle Any refresh return EndHandleEnddo

EndFunction

Hello!Im a newbie and Im trying to make a loop that collects the names of all sheets in a specific regi and writes them to a logfile. Can anybody tell me what im doing wrong?

/PIPELAYOUT/

var !sheename collect all SHEE for REGI

!File = object file('C:/Plots/names.log')

Page 14: PML Basics Part 1

!Array = object Array()

var !sheename collect all SHEE for REGIdo !i INDEX !sheenameVAR 1 NAME$!Array.Append($V1)

enddo!File.writefile('overwrite',!Array)

The array dont seem to be accessible inside the do loop

Change " $!Array.Append($V1)" to "!Array.Append(V1)" and you should be OK.

Thanks for the quick response. But it didnt work. Quite confusing with all the $ !. This is my code at the momentONERROR CONTINUE

/PIPELAYOUT/

!File = object file('C:/Plots/names.log')!Array = object Array()

var !sheename collect all SHEE for REGIdo !i INDEX !sheenameVAR 1 NAME !Array.Append(V1) enddo!File.writefile('overwrite',!Array)

Slight modification then. Change your do-loop to this:do !i INDEX !sheename!name = name!Array.Append(!name)enddo

thanksI thank for all this kind of posts, because i'm getting startiing in PML and it's very usefull to get this info...

Quote:

Originally Posted by dit02lbt Thanks for the quick response. But it didnt work. Quite confusing with all the $ !. This is my code at the momentONERROR CONTINUE

/PIPELAYOUT/

!File = object file('C:/Plots/names.log')!Array = object Array()

var !sheename collect all SHEE for REGIdo !i INDEX !sheenameVAR 1 NAME

Page 15: PML Basics Part 1

!Array.Append(V1) enddo!File.writefile('overwrite',!Array)

unless I am very much mistaken (and I could be) as you havent navigated to the sheet name the var 1 name will always be the same.Personally I would do it this way (its a bit more PML2 like as well)

!Coll = !!collectallfor('shee','',!!ce) - assuming you are at the RegiDo !A indices !Coll!Array.append(!Coll[$!A].name)

*and of course at this point I cant recall if its ].name)or ].name()) - old age!

Enddo

that way you dont navigate (as you dont need to)

!File.writefile('overwrite',!Array)

Matt

u are not misstaking. Ive added another row to the code $!SHEENAME[$!i].I must say your solution looks better but mine works. Thanks anyway

hELLO EVERYONE

I'm Having trouble with a usefull macro (for me) wich is intended to change an attribute to all the elements for (inside) the ce. The arguments of this macro are:

$1 = type of elements that are going to be changed$2 = the attribute that is going to be changed$3 = the new value of the attribute

the idea is, if i need to change the section's justification line inside the ce (a framework) i write:

$m membs sctn jusl tos

if i need to change the specification of the sections i write:

$m membs sctn spref /icha/H_300x200

so, this is supposed a multifunction macro :-)

this is my code (based on what's exposed here)

Quote:

$* PRETENDE HACER UNA MACRO QUE CAMBIE UN ATRIBUTO A TODOS LOS ELEMENTOS$* $1 DEL CURRENT ELEMENT.$*$* $1 = TIPO DE ELEMENTOS EN LOS QUE APLICA LA MACRO$* $2 = ATRIBUTO

Page 16: PML Basics Part 1

$* $3 = VALOR DEL ATRIBUTO FINAL$*

$* CREA UN ARRAY "COLECCION" QUE RECOLECTA TODOS LOS $* ARGUMENTOS $1 PARA EL CE.$*---------------------------------------------$* mAKES AN ARRAY "COLECCION" AND COLLECT ALL THE $1 IN THE CEVAR !COLECCION COLL ALL $1 FOR $!!CE

$* ALMACENA EN !y LOS INDICES DE "COLECCION" Y GENERA UN LOOP$*---------------------------------------------$* MAKES A LOOPDO !Y INDICES !COLECCION

$* $!COLECCION[$!Y]

$* CAMBIA EL ATRIBUTO $2 Y LE ASIGNA EL VALOR $3$*---------------------------------------------$* CHANGES THE ATTRIBUTE $3 WITH THE NEW VALUE $3$2 $3

$* CONTROL DE ERRORES, $*---------------------------------------------$* CONTROL ERRORHANDLE ANY

$* MUESTRA UN MENSAJE DE ERROR EN LA LINEA DE COMANDOS $PERROR ON $!COLECCION[$!Y]

ENDHANDLE

ENDDO

i HAVE TRIED WITH THE ALTERNATIVES THAT YOU SHOW HERE LIKE

Quote:

$* PRETENDE HACER UNA MACRO QUE CAMBIE UN ATRIBUTO A TODOS LOS ELEMENTOS$* $1 DEL CURRENT ELEMENT.$*$* $1 = TIPO DE ELEMENTOS EN LOS QUE APLICA LA MACRO$* $2 = ATRIBUTO$* $3 = VALOR DEL ATRIBUTO FINAL$*

!COLECCION = !!COLLECTALLFOR('$1','',!!CE)

$* ALMACENA EN !y LOS INDICES DE "COLECCION"DO !Y INDICES !COLECCION

$* SE SITUA EN EL ELEMENTO QUE SE DESEA CAMBIAR!COLECCION[!Y].$2 = $3

$* CONTROL DE ERRORES, HANDLE ANY

Page 17: PML Basics Part 1

$* MUESTRA UN MENSAJE DE ERROR EN LA LINEA DE COMANDOS $PERROR ON $!COLECCION[$!Y]

ENDHANDLE

ENDDO

BUT IT DIDN'T WORK... I THINK THAT IS BECAUSE THE CE IS A FRMW AND THE SENTENCE "!COLECCION[!Y].$2 = $3" TRY TO CHANGE THE ATTRIBUTE TO THE FRMW INSTEAD OF THE SCTN (I HAVE PROVED WITH "!COLECCION[!Y].JUSL = TOS" TOO)... am I right?

WOULD YOU HELP ME, PLEASE?

Christiansen,

try this....

Code:

!ATTRIBUTE = $2 !COLECCION = !!COLLECTALLFOR('$1','',!!CE)DO !Y INDICES !COLECCION

!COLECCION[!Y].$!ATTRIBUTE = $3HANDLE ANY $PERROR ON $!COLECCION[$!Y]ENDHANDLE

ENDDO

i've tried with your code but it returns an error (i.e. if i try to change all the sections in a framework, i have to be in the framework, so, the program return line 1 !ATTRIBUTE = $2 and a message: "a framework does not have attribute jusl")

thanks

Thats right, its a string

Code:

!ATTRIBUTE = '$2'

it works...

the final program isQuote:

!ATTRIBUTE = '$2'

!COLECCION = !!COLLECTALLFOR('$1','',!!CE)DO !Y INDICES !COLECCION

Page 18: PML Basics Part 1

!COLECCION[!Y].$!ATTRIBUTE = $3HANDLE ANY$PERROR ON $!COLECCION[$!Y]ENDHANDLE

ENDDO

one consideration is to specify the third argument ($3) as string when it's necesary, por example

If you want to change all the JUSL of the sections in a framework you type:

$M /memb sctn jusl 'tos'

where:

sctn is the type of the element you want to changejusl is the attribute you want to change and'tos' is the new value of the attribute... in this case marqued between ' ' because is a text

If you want to change all the spref of the sections in a framework you type:

$M /memb sctn jusl /ICHA/H_300x200

and the new spref value without the ' ', because it's not a string

I forgot ..

memb is the name of the file who contais the macro

(i explain this because someone could need it and don't know what i'm talking about)

thanks a lot for your help

i will keep on disturbing your tra=nquility ;-)

Just a suggestion, add a handle to take care of it...

Code:

!ATTRIBUTE = '$2'

!COLECCION = !!COLLECTALLFOR('$1','',!!CE)DO !Y INDICES !COLECCION

!COLECCION[!Y].$!ATTRIBUTE = $3HANDLE (2,794) !COLECCION[!Y].$!ATTRIBUTE = '$3'ELSEHANDLE ANY $PERROR ON $!COLECCION[$!Y]ENDHANDLE

ENDDO

Page 19: PML Basics Part 1

hello guys i need to rename all branches for given pipe

how should i start for this query?

thx for your support, let me explain my problem

this is old line number pipe: /2"-24-1512-A1A-520-A01BRANCH NAME :/2"-24-1512-A1A-520-A01/B1/2"-24-1512-A1A-520-A01/B2/2"-24-1512-A1A-520-A01/B3....NOW MY LINE NO CHANGES TO PIPE :/2"-24-2500-A1A-520-A01SO I WANT TO CHANGE MY BRANCJ NAME TO BRANCH NAME :/2"-24-2500-A1A-520-A01/B1/2"-24-2500-A1A-520-A01/B2/2"-24-2500-A1A-520-A01/B3IT LIKE WHEN YOU TRY TO RENAME PIPE NAME BRANCH NAME SHOULD AUTOMATICALLY CHANGE AS PER FEED DATA.I HOPE THIS WILL CLEAR IDEA OF VIEWER

Code:

RENAME All /2"-24-1512-A1A-520-A01 /2"-24-2500-A1A-520-A01

Thx Jcont220

It Helps Me A Lot

Actually I WROTE A MACRO

FIND IN THE ATTACHMENT

IN THE SAME WAY I WROTE ANOTHER MACRO

WHICH MODIFY THE PIPE NAME BUT BRANCH REMAIN AS ORIGINAL.

BUT NOW WITH YOUR SUGGESTION EVERY PROBLEM IS SOLVED

THX ONCE AGAIN

1) Pipe form macro These file contain pipe form which will create a pipe as per project set-up (admin have to define)

& simultaneously set attributes :lsize duty :lproc :lsno Pspec Ispec Tspec :Areacode :lsuf :Isoref :Mtoref :Mtodrwg :MtoareaAs per project philosophy

Procedure:

Go to respective zone click ‘new pipe’ button then feed the value & then apply

If insulation or tracing spec if not defined in line number don’t leave blank put ‘unset’

& if insulation or tracing spec is defined put spec name following forward slash ‘/’

Page 20: PML Basics Part 1

For e.g.

OUTPUT OF THE MACRO

Page 21: PML Basics Part 1

PML Basics Part 4 (Expressions and IF statements)

Well, I have coved Arrays and Loops. Now I want to start getting in to expressions and If statements.

Before we get started writing our own expressions. I remember when I was first learning expressions, I turn to the manuals. If you have a chance, please check it out. But, since I know most people don't really open the manual, I'm going to post the part on expressions.

we need to know some Operator:

1. Brackets ()2. * / 3. + -4. EQ, NEQ, LT, LE, GE, GT5. NOT6. AND7. OR

Now, when writing an expression, think back to high school math or even middle school math when you learn how to solve nested expressions.(4 * (POWER(PARA[1], 2) + POWER(PARA[2] , 2) )

You have several different types of expressions:

Logical expressions

PDMS attributes

Logical constantsTRUE, ON, YES for trueFALSE, OFF, NO for false

Page 22: PML Basics Part 1

Logical OperatorsConparator operators (EQ, NEQ, LT, GT, LEQ, GEQ)Boolean operators (NOT, AND, OR)

Logical functionsBADREF DEFINED, UNDEFINEDCREATEDELETEDEMPTYMATCHWILDMODIFIEDUNSETVLOGICAL

Logical array expressions

PDMS attributesEx: XLEN YLEN POHE POSITION ORIENTATION

The keyword PI(3,142)

Numeric operator+ Add- Subtract* Multiply/ Divide

Numeric functionI'm not going to list all of them but some of them are:ABS, ACOS, ASIN, ATAN, SIN, COS, TAN, MATCH, MAX, SQRT..

Real expressionsSee numeric funtions

Real array expressions

Text expressions

A text string

PDMS attributes

Text operators

Text fuctions

__________________________________________________ _________________

Ok, lets start creating some If statements using some of this expressions. This is an example I like to use a lot.When users descover that they can create sctns using syntax, sometimes they forget to change all the attributes. One of those attributes will be the GTYPE. So a simple expression will be:

!Catref = Gtype of Catref!Sctn = Gtype of Sctn

If (!Catref neq !Sctn) ThenGtype $!Catref

Page 23: PML Basics Part 1

Handle any $* I try to add a handle anywhere I think I might have a problem, in this case, the section could be claimEndHandleElse$PSctn has correct GtypeEndIf

The If statements can get nasty, here is a simple one.

If !!CE.Type.Eq('PIPE') or !!CE.Type.Eq('STRU') or !!CE.Type.Eq('EQUI) Then

or

If ((Type of CE eq 'PIPE') or (Type of CE eq 'STRU') or (Type of CE eq 'EQUI')) Then

Its, getting late and my wife is ready to use the computer. If anyone has any request or question, please ask. I'll continue this tomorrow.

I tend not to use the !!ce as you have to navigate to it within PDMS, I find it safer to create say an array of items (which will be dbrefs) then query or assign accordingly e.g.

$* assign some variables!File = object file('%pdmsuser%/log/logfile.log')!Array = object Array()

$* collect some items!Coll = !!collectallfor('elbo','',world)

$* action the collectionDo !A indices !CollIf (!Coll[$!A].catref.upcase() ne 'XXXX') then$P we missed this one -- $!Coll[$!A]!Array.appned(!Coll[$!A].name)Elsesome other actionEndifEndoo

$* see if we found any data errors, if so output to a file and advise userIf (!Array.size() gt 0)thne$P we have an out put error/log file!File.writefile('overwrite',!Array)Else$P it all went wellEndif

$* get user to acknowledge the macro has finished!!Alert.message('You have now finished')

Hello,I'm a new PDMS/PML user, I'm just learning.Can anybody help me in macro writing?I would like to make a macro in PML1, which is counts the valves and elbows in a current site

Page 24: PML Basics Part 1

and write the result in a file.

I try to make it since two days, but it isn't works. Please help me, if you can ...

I'd use the inbuilt "collect" function

!Valve = !!collectallfor('valv','',!!ce) --- !!ce ==> ce, in this case the site you want to collect valves from!Elbow = !!collectallfor('elbo','',!!ce) --- !!ce ==> ce, in this case the site you want to collect elbows from!ValveSize = !Valve.size()!ElbowSize = .......

Do the same for other components then create an array!Items[1] = ('number of valves ' & !ValveSize)!Items[2] = ('number of elbows & !ElbowSize)etc

!File = object file('%pdmsuser%/filename.out')!File.writefile('overwrite',!Items)

If you want to do it for a number of sites then collect the sites into an arraye.g. !Sites = !!collectallfor('site','',world)

and create a do loop

Do !A indices !Sites$!Sites[$!A]<the do the collection above><write to the file - !File.writefile('append',!Items)Enddo

But why not just use the Reports facility.

Quote:

Originally Posted by csigusz Thank you Matt!

(I can do it with report facilities, but I'd like to learn the PML programming)

Thanks again!

Lóri

Seems fair. In the !File.writefile() part you have the option to either 'overwrite' or 'append'. If I was using a DO loop I would delete the file first (!File.deletefile() ) before I started the DO loop, that way you know you are starting with a cleab file.In the !!Collectallfor(...) funcntion, you have three options, the first is a String and you supply what you are looking for, teh second is a conditional string i.e. if you only want the first string to match an attribute, the third is a dbref, so !!ce or world work (or any other dbref variable)

If I wanted elbows from sites that were piping site I would set all my FUNC attrributes on the Piping sites to PIP and then collect in this way!Els = !!collectallfor('elbo','Func of site eq |PIP|',World)

Matt

Page 25: PML Basics Part 1

Please be noted that CORRECT object, !!Collect() function, !!CollectAllFor() function, !!CollectAllWithin() function, !!CollectMembersOf() function, are not real built in object/function!!All those are defined by PML2 macro using "VARIABLE !VARNAME COLLECT ~~~" command. Those consumes more processing time for converting search result from String to DBRef.

If you are familier with "VAR !VARNAME COLLECT ~~~" and "VAR !VARNAME EVALUATE~~~", and some sort operation, I don't see any benefit to use those objects/functions.

Note that PML2 style couldn't be always good!

Sorry to say that I'm happy with PML2 and don't really see to much of this processing time. I do some heavy collections and I really don't see a big proccess time, not at lease something to complain about. If I use pml collecting var !coll coll, the collection is a string and I really don't want to be converting or adding extra lines to convert it into a dbref(), the smaller the macro, the easier to understand. That's the way I see it.

I agree, var !coll collect all ( ELBO ) for CE (or name of element research),and next:var !collname eval name for all from !coll(for evaluate name of all of previous list)

Why not !C = object collection()!C.scope(!!ce)!C.filter( object EXPRESSION( 'true' )!C.type('ELBO')!Names = object ARRAY()!Dbrefs = !C.results()do !Dbref values !Dbrefs!Names.append(!Dbref.flnm)enddo

Few more lines but much better code

I agree that PML2 style is good for peoples who already familier with the other programming language, and I know that it is mandatory to know PML2 with PDMS 12 .net programming.

If everybody satisfy with current condition, it is fine.But, I believe that if nobody complain about bad thing with PDMS, it will never be improved.

Everybody should know that if the PDMS user is waiting for 10 sec. macro processing time, he will do nothing, just wait for the operation is done.You'll see what will happen if this operation is iterrated many times , done by many peoples, every day.

Anyway, now we have PDMS 12... We can use Visual Studio for customization. Many of problems will be disappeard.Hope to see the world we don't need "variable" command anymore.I tired to explain both PML1 and PML2 commands in my training course...

11-14-2007

Ignore my previous comment PLEASE!!! I didn't find that modern PC is really fast!!! :-)Complained too much. I'm getting old!(I replaced my P4 PC to new Core2Duo machine last month, and I didn't realise how much

Page 26: PML Basics Part 1

fast this is...)

I will try to put small tip of PML at here, instead of complaining about things.Here is an example of basic report with DB element collection.With my experience, the following PML1/PML2 combination is fastest way for coding to collect DB elements and attributes, especially for some quick data fix and data listing. Often GUI report is not enogh to produce required information.(the difficult bit is not in this example. Give me time.)

See a bit old style of basic PML programming!This example is using good point of PML1 and PML2. It's very simple.-------First, start from PML1 style---------if type eq |WORL| thenvar !for ||elsevar !for | for ce|endifvar !comp collect all bran mem with type neq |INST| and type neq |FILT| $!for $* Remove instrument and SP itemvar !type eval type for all from !compvar !p1bor eval p1bor for all from !compvar !dtxr eval dtxr for all from !compvar !sort sort !type ciascii !p1bor numeric !dtxr ciasciivar !output append |TYPE,P1BOR,DTXR|do !i indices !sortvar !output append |$!type[$!i],$!p1bor[$!i],$!dtxr[$!i]|enddo!file = object file(|c:\temp\list.txt|) $*this is PML2 style, this is useful.!file.writefile(|OVER|,!output)-----------------------------------------With PML1 style, no need to declare variable type.The "var <var> evaluate <attribute>" does not work if the BRAN MEM has bad SPREF.(In the real project operation, often we see piping components which looses SPREF.)so I modified the code like; (try to use more PML2 command in here!)----------------!type = object array()!bore = object array()!dtxr = object array()if !!ce.type eq |WORL| then!for = ||else!for = | for ce|endifvar !comp collect all bran mem $!fordo !v values !comp$!vif badref(!!ce.spref) then$P $!v has bad SPREF $* We can't use " write 'text' " command in tty mode. This is why I use this.skipendif!type.append(!!ce.type)!p1bore = !!ce.p1bore $* this line may be wrong.. could be !!ce.bore[1]?!bore.append(!p1bore.real().string()) $*You'll know why we need this.!dtxr.append(!!ce.spref.detre.rtext) $* does this work???enddovar !sort sort !type ciascii !bore numeric !dtxr ciascii $* all the sort key value must be string type.!output[1] = |TYPE,P1BOR,DTXR| *$ put first array element instead of declare this as array object

Page 27: PML Basics Part 1

do !i indices !sort!output.append(!type[!i] & |,| & !p1bor[!i] & |,| &!dtxr[!i])enddo!file = object file(|c:\temp\list.txt|)!file.writefile(|OVER|,!output)-----------------------------------------Not so good code, but more practical than the first example... I didn't test the above macro yet, cause I'm in home. I still have no good idea to use .sortedindices() method for an array variables which contains mixed sort key type, I mean string, real, and so on.

Anyway, wait for PDMS 12...Have a nice day!

11-14-2007

Back to basic;

Useful function

defined(!variable) returns (boolean) true if the variable is defined."defined" means the variable has any value, or "unset" value.

undefined(!variable) returns opposite value to defined()

set(!variable) ----returns if the variable has non "unset" value.unset(!variable)----returns opposite value to set().

set() and unset() is also available as method style.

You can say;

!variable.set()!variable.unset()

The "defined" value is the same status just after you declare a variable.PDMS variable has intermidiate condition before you load concreate value to the variable. This status will be called as "defined".Once the variable is defined, you can check the variable has cocreate value (not an unset value" by using set()/unset().

try the following examle to see the result.----Start----------------------------!result = defined(!variable)$P Not yet defined-result of defined = $!result!result = undefined(!variable)$P Not yet defined-result of undefined = $!result

!variable = object string()!result = defined(!variable)$P Defined-result of defined = $!result!result = undefined(!variable)

Page 28: PML Basics Part 1

$P Defined-result of undefined = $!result

!result = set(!variable)$P Defined but has no value -result of set = $!result!result = unset(!variable)$P Defined but has no value -result of set = $!result

!variable = |ABC|!result = set(!variable)$P Defined and has value -result of set = $!result!result = unset(!variable)$P Defined and has value -result of unset = $!result

So when we see defined/undefind, set/unset condition with variable?

Please try to copy the attribute value to your variable, and use the function/method above.I recommend you to use "!variable = [attribute name]" command to get what type of object will be loaded to your variable. if we use "var !variable [attribute name]" command, we always get string value, and this will be the same value as we see by "Q [attribute name]" ([attribute name] can be "POSITION", "ORIENTATION", "FUNCTION", etc.

Please be noted that the "empty" text string and "unset" value is different."empty" text string will be recognized as "set" value.

Also better to test the DB search command result.


Top Related