make money

Award Winning Plant Industry Community

How To: Loop through all project piperuns using filters with Smartplant P&ID automation and VB6

By on January 14, 2011 in Programming, Smartplant, SPPID, Tutorial with 8 Comments

Programming using Smartplant P&ID’s Logical Automation Layer is actually very easy and intuative after you do it a few times.  This example of a what I start with a lot. What this little routine will do is loop through all the active (non stockpile) piperuns in your project and print their ItemTags in the immediate window. You could easily print them out to a txt file or excel spreadsheet too. For this to work you must have your desired project active.

Create a new .exe in VB6

Next, add your references (Project > References) – in this case we will need :

Intergraph Smartplant P&ID Automation and Intergraph SmartPlant Logical Model Automation

Create a new button on your form and double click it to open the code.  Paste the following in it:

Dim datasource As LMADataSource
Set datasource = New LMADataSource
Dim objFilter As LMAFilter
Dim criterion As LMACriterion

Set criterion = New LMACriterion
Set objFilter = New LMAFilter
'set the filters
criterion.SourceAttributeName = "ItemStatus"
criterion.ValueAttribute = "1"
criterion.Operator = "="
objFilter.ItemType = "Piperun"
objFilter.Criteria.Add criterion
Dim piperun As LMPipeRun
Dim piperuns As LMPipeRuns
Set piperuns = New LMPipeRuns
piperuns.Collect datasource, Filter:=objFilter
Debug.Print "Total Piperuns found:  " & piperuns.Count
datasource.BeginTransaction
'loop through each piperun
For Each piperun In piperuns
debug.print piperun.Attributes("ItemTag").Value
End If
Next
datasource.CommitTransaction
Set datasource = Nothing
Set objFilter = Nothing
Set criterion = Nothing
Set piperun = Nothing
Set piperuns = Nothing

If you wanted to loop through all the piping components all you would have to do is change

Dim piperun As LMPipeRun
Dim piperuns As LMPipeRuns

to

Dim pipecomp As LMPipingComp
Dim pipecomps As LMPipingComps

and then change your filter type to

objFilter.ItemType = “PipingComp”

voilla, you are now looping through all the piping components.

Tags: , , , , ,

About the Author

About the Author: Dave Tyner is a 3DS Max 2013 Certified Professional working as a visualization artist for one of the worlds largest EPC firms. dave@davetyner.com @davetyner3D www.davetyner.com .

Subscribe

If you enjoyed this article, subscribe now to receive more just like it.

There Are 8 Brilliant Comments

Trackback URL | Comments RSS Feed

  1. Bhaskar says:

    Hi,

    I’m working as SmartPlant PID administrator. I’m new at automation part. When I connect the process Intergraph Smartplant P&ID Automation and Intergraph SmartPlant Logical Model Automation, it doesn’t works properly. The program does not identify even Llama.dll . I’ve already tried unregistering and registering Llama.dll, but in vain. I’ve tried it on smartplant pid 2009 as well as 4.3.

    Plz let me know how can I resolve the problem.
    Thanks in advance…

  2. dave says:

    did you register the two dll’s I listed in the post?

  3. Bhaskar says:

    I read in smartplant install guide that we need to upgrade the Llama.dll for version above 4.1. Is it so,I always need to build my own class and object for automation it is very time consuming. I believe Llama will reduce the work a lot.

  4. dave says:

    Bhaskar, sorry you’re having trouble. Can I suggest you post here:

    http://www.davetyner.com/forum/forumdisplay.php?71-Intergraph-SmartPlant-VB-VBA

    in greater detail and with some sample code?

  5. Bhaskar says:

    Thanx Dave. I did it by referncing several dll files. Thanx for your concern.

  6. pbp says:

    Hi,
    Which API do you use to access LMADataSource etc in VB?
    can you please provide steps.
    Thanks,

Post a Comment

Your email address will not be published. Required fields are marked *

Top