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

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

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
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.