14 Jan 2011 6 Comments
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.



Sep 30, 2011 @ 17:25:05
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…
Sep 30, 2011 @ 17:29:28
did you register the two dll’s I listed in the post?
Sep 30, 2011 @ 17:36:09
Ofcourse I did! It says that the dll file isn’t built yet
Sep 30, 2011 @ 17:41:54
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.
Sep 30, 2011 @ 20:52:30
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?
Oct 03, 2011 @ 15:15:29
Thanx Dave. I did it by referncing several dll files. Thanx for your concern.