PML Basics Part 1

Download PML Basics Part 1

Post on 20-Apr-2015

259 views

Category:

Documents

3 download

Embed Size (px)

TRANSCRIPT

<p>PML Basics Part 1 - 10-25-2006</p> <p>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 is ALPHA 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.</p> <p>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)</p> <p>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.</p> <p>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 :)</p> <p>--------------------------------------------------------------------------------------------------------------------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 downs Modify &gt; Name The modify name form will come up and your command line filled with text. $R To turn off the Trace Alpha log end To 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.</p> <p>I just found this and I wanted to pass it on....Enjoy $R 1 = Tracing to shell window (default) 2 = Tracing to requests window 4 = Tracing of only input lines executed 8 = Tracing of all input lines 16 = Tracing without $ expresion (default off) 32 = Tracing includes line numbers 64 = Tracing of macro/function changes 100 = General Debugging 102 = capture trace in ALPHA LOG</p> <p>Can also do $HR at the command line to get all options for $R</p> <p>--------------------------------------------------------------------------------------------------------------------Quote:</p> <p>Originally Posted by TimSharrock A query on usage in the field: how much do you use the $ comments (either $* or $(...$) )?</p> <p>(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) 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</p> <p>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.</p> <p>=====================================================================Quote:</p> <p>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:</p> <p>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> <p>$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> <p>$) $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 $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</p> <p>I didn't know I could comment out part of a line with the $*. !! awesome!!!(#17)</p> <p>That is the beauty of using the $* comment syntax. You can write them on the same line as the actual code.</p> <p>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?</p> <p>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 )?</p> <p>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</p> <p>PML Basics Part 2 (Creating an Array) - 10-25-2006</p> <p>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 Adding to the array Type 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.</p> <p>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.....</p> <p>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] = !!CE I 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)</p> <p>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 loops PML Basics Part 3 (Creating a Loop) I added you question as the examples.</p> <p>PML Basics Part 3 (Creating a Loop) - 10-26-2006</p> <p>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? Its a series of commands that will continue to happen until the loop is broken. Do This 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 Enddo For 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 lets 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 $!!CE I 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()? Its 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</p> <p>$********************************************** 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 Gtype</p> <p>Enddo I'll add more example later today.</p> <p>Hello, you can also use: 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 Gtype Enddo or Do !x values !Coll $P $!x has the wrong Gtype Enddo</p> <p>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</p> <p>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 /A300 Handle 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 assigned EndHandle Enddo 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</p> <p>Var !BRANCH COLL ALL BRAN FOR /10LAB Do !y indices !BRANCH $!BRANCH[$!y] Ispec /HC Handle any $pError on $!BRANCH[$!y] EndHandle Enddo</p> <p>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.</p> <p>--------------------------------------------------------------------------------------------------</p> <p>Yes, I'll start getting more into object collect &amp; object collections. Here is another example using a different type of collection !BRANCH = !!CollectAllFor('BRAN', '', !!CE) Do !y indices !BRANCH $!BRANCH[$!y] Ispec /HC Handle any $pError on $!BRANCH[$!y] EndHandle Enddo 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.</p> <p>================================================================</p> <p>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 = /HC Handle any $p Error on $!BRANCH[$!y] EndHandle Enddo The selected element would in this example remain the same also while running through the loop.</p> <p>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.</p> <p>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 ma...</p>