0% found this document useful (0 votes)
39 views139 pages

SmartPlant P&ID Automation Labs Guide

SPAutomationCourseLabsV4

Uploaded by

pablo77024
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views139 pages

SmartPlant P&ID Automation Labs Guide

SPAutomationCourseLabsV4

Uploaded by

pablo77024
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd

SMARTPLANT P&ID

V4.3

AUTOMATION COURSE

LABS
SmartPlant P&ID Automation Labs

Labs

GENERAL INSTRUCTIONS FOR LABS:


1. You will need to reference following dlls for your lab programs, which are located at “…\
Program Files\SmartPlant\P&ID Workstation\Program”.
(1) Intergraph SmartPlant P&ID Logical Model Automation – [Link]
(2) Intergraph SmartPlant P&ID Placement Automation – [Link]
(3) Intergraph SmartPlant P&ID Automation – [Link]
(4) Intergraph SmartPlant PID Foreign Calculation Adapter - [Link]

2. Most labs expect a Boolean variable to be defined to indicate user’s choice of using
PIDDatasource or New LMADatasource
Private blnUsePIDDatasource As Boolean

3. Some constants need to be defined to hold SP_ID of some items, of course you need to place
these items first. I provide an assembly for you to place into a drawing at the beginning of this
course. Examples are:

Private Const CONST_SPID_ModelItem As String = "C76EF274525A4345A6ACE1D179362899"

Private Const CONST_SPID_ItemNote As String = "9A3B02C271754A8BB46DC4D02F9F0954"

Private Const CONST_SPID_OPC As String = "A8EC5233227A4F3AB480E9AB39205BCC"

Private Const CONST_SPID_Vessel As String = "C76EF274525A4345A6ACE1D179362899"

Private Const CONST_SPID_PipeRun As String = "8B283FA8472F4E3BABB6AF573DF161F4"

Private Const CONST_SPID_PipingComp As String =


"59D6251324574734B9883C8E89E57B4E"

Private Const CONST_SPID_OfflineInstrument As String =


"7EAB72658BA04FD8BD67CFEB4D96DD37"

Private Const CONST_SPID_InlineInstrument As String =


"BC21A415E803496EBDA87129F5F5F540"

Private Const CONST_SPID_LabelPersist As String =


"B9E88D821E8145269E5B398B858555A8"

2
SmartPlant P&ID Automation Labs

3
SmartPlant P&ID Automation Labs

1. INITIALIZE LMADATASOURCE

a) Purpose
To initialize LMADataSource with different methods and access some properties of it.
b) Problem Statement
Write a standalone application to initialize the LMADataSource with New LMADatasource and
PIDDatasource, then access some properties of it, such as ProjectNumber, SiteNote, etc.
c) Solution
1. Using Set new LMADataource or PIDDataSource to initialize LMADataSource.
2. Use [Link] method to print out the required properties.

 Example Code
Dim datasource As LMADataSource

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If

[Link] [Link]
[Link] [Link]
[Link] [Link]
[Link] [Link]

Set datasource = Nothing

4
SmartPlant P&ID Automation Labs

2. CHANGE SITE AND PLANT

a) Purpose
To change active site and active plant within LLAMA program.
b) Problem Statement
Place a Vessel into active drawing, then close the drawing. Then switch the smartplant to another
site and another place.
c) Solution
Change the site and plant within your program to get access to that Vessel.
 Example code
Dim datasource As LMADataSource

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If

[Link] [Link]
[Link] [Link]

Dim objVessel As LMVessel


Set objVessel = [Link](CONST_SPID_Vessel)
[Link] [Link]("ItemTag").Value

[Link] = "C:\HostSite\[Link]"
[Link] = "Lin_Plant3"

Set objVessel = [Link]("C76EF274525A4345A6ACE1D179362899")


[Link] [Link]("ItemTag").Value

Set datasource = Nothing


Set objVessel = Nothing

5
SmartPlant P&ID Automation Labs

3. ACCESS ALL ITEMTYPES

a) Purpose
To access all ItemTypes within a Plant
b) Problem Statement
Access to an LMADatasource, then print out all Item Types within that LMADatasource.
There are total 41 Item Types in V4, which includes:

AreaBreak
Drawing
DrawingProject
DrawingVersion
EquipComponent
Equipment
EquipmentOther
Exchanger
GlobalDrawing
History
InstrLoop
Instrument
ItemNote
Label
LabelPersist
Mechanical
ModelItem
ModelItemClaim
ModelItemClaimOffline
ModelItemClaimRep
ModelItemLookup
Note
Nozzle
OPC
Package
PipeRun
Pipeline
PipingComp
PipingPoint
PlantItem
PlantItemGroup
PlantItemGroupOther
Representation
RepresentationLookup
SafetyClass
SignalPoint
SignalRun
System
Task
TaskItemProperty
Vessel

c) Solution
1. Get object LMADatasource

6
SmartPlant P&ID Automation Labs

2. Loop through [Link]


 Example code
Dim datasource As LMADataSource
Dim i As Integer

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If
[Link] "Total ItemTypes: " & [Link]
For i = 1 To [Link]
[Link] [Link](i)
Next

Set datasource = Nothing

7
SmartPlant P&ID Automation Labs

4. IDENTIFY AN ITEM IN THE DATABASE USING SP_ID AND READ ITS


PROPERTIES

a) Purpose
To access a vessel using SP_ID values and read its properties
b) Problem Statement
Place a vessel. Write a standalone application to retrieve the following properties of the vessel:
SP_ID, EquipmentSubClass, EquipmentType, aabbcc_code, Class, Item TypeName,
volumeRating, and volumeRating in SI units.
c) Solution
2. Dim a LMVessel object and get the object using [Link] method.
3. Use [Link] method to print out the required properties.

 Example code
Dim datasource As LMADataSource

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If

Dim objVessel As LMVessel


Set objVessel = [Link](CONST_SPID_Vessel) 'get objVessel by id

'print out some objVessel's properties


[Link] "objVessel ID = " & [Link]
[Link] "Equipment Subclass = " & [Link]("EquipmentSubclass").Value
[Link] "Equipment Type = " & [Link]("EquipmentType").Value
[Link] "aabbcc code = " & [Link]("aabbcc_code").Value
[Link] "Class = " & [Link]("Class").Value
[Link] "Item TypeName = " & [Link]("ItemTypeName").Value
[Link] "Volume Rating =" & [Link]("VolumeRating").Value
[Link] "Volume Rating in SI units = " & [Link]("VolumeRating").SIValue

Set datasource = Nothing


Set objVessel = Nothing

8
SmartPlant P&ID Automation Labs

5. IDENTIFY AN ITEM IN THE DATABASE AND MODIFY ITS PROPERTIES

a) Purpose
To modify its properties of items in the database
b) Problem Statement
Place a vessel. Write a standalone application to modify the following property of the vessel:
Name
c) Solution
1. Dim a LMVessel object and get the object using [Link] method.
2. Change the value of required properties
3. Use [Link] to commit the change to database

 Example code
Dim datasource As LMADataSource

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If

[Link]

Dim objVessel As LMVessel


Set objVessel = [Link](CONST_SPID_Vessel) 'get vessel by id
[Link]("Name").Value = "Vessel 7" 'assign value to vessel name
[Link]("DesignBy").Value = "By B"
[Link]

[Link]

Set objVessel = Nothing


Set datasource = Nothing

9
SmartPlant P&ID Automation Labs

6. INIT OBJECTS READ ONLY

a) Purpose
To use property of LMADatasource: InitObjectsReadonly
b) Problem Statement
Place a Piperun. Write a standalone application to get LMPiperun, then set the
InitObjectsReadonly to True, and check if the property “Name” can be changed with drawing
close and New LMADatasource is used.

c) Solution

Example code

Dim datasource As LMADataSource


Dim objPipeRun As LMPipeRun

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If

[Link] = True

[Link]

Set objPipeRun = [Link](CONST_SPID_PipeRun) 'get PipeRun by id


[Link]("Name").Value = "TEST1" 'assign value to PipeRun name
[Link]

[Link]

Set objPipeRun = Nothing


Set datasource = Nothing

10
SmartPlant P&ID Automation Labs

7. ROLLBACK

a) Purpose
To rollback a transaction by automation program
b) Problem Statement
Place a Piperun. Write a standalone application to get LMPiperun, then change the property
“Name” of the piperun and CommitTransaction, then change the property “Name” again, but this
time RollbackTransaction, check which value is commited.

c) Solution
1. Dim a LMVessel object and get the object using [Link] method.
2. Dim a LMEquipment object and get the object using [Link] method.
3. Use [Link] and [Link] method to transfer to
LMAItem.

 Example code

Dim datasource As LMADataSource


Dim objPipeRun As LMPipeRun

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If

[Link]

Set objPipeRun = [Link](CONST_SPID_PipeRun) 'get PipeRun by id


[Link]("Name").Value = "TEST1" 'assign value to PipeRun name
[Link]
[Link]

[Link]
[Link]("Name").Value = "TEST2" 'assign value to PipeRun name
[Link]
[Link]

Set objPipeRun = Nothing


Set datasource = Nothing

11
SmartPlant P&ID Automation Labs

8. PROPAGATION

a) Purpose
To set propagation to True or False from automation program
b) Problem Statement
Place a PipeRun, then place couple branch PipeRuns to this piperun. Write a standalone
application to modify the property “SupplyBy” of the first PipeRun with Propagation set to True
and modify the property “CleaningReqmts” with Propagation set to False.
c) Solution

Example code

Dim datasource As LMADataSource


Dim objPipeRun As LMPipeRun

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If

[Link]

Set objPipeRun = [Link](CONST_SPID_PipeRun) 'get PipeRun by id

[Link] = True
[Link]("SupplyBy").Value = "By D" 'assign value to PipeRun Supply By
[Link]

[Link] = False
[Link]("CleaningReqmts").Value = "CC1" 'assign value to PipeRun
Supply By
[Link]

[Link]

Set objPipeRun = Nothing


Set datasource = Nothing

12
SmartPlant P&ID Automation Labs

9. GET LMAITEM FROM LMVESSEL

a) Purpose
To get LMAItem from LMAVessel and LMAEquipment
b) Problem Statement
Place a vessel. Write a standalone application to get LMVessel and LMEquipment, then transfer
them to LMAItem, and compare the difference
c) Solution
3. Dim a LMVessel object and get the object using [Link] method.
4. Dim a LMEquipment object and get the object using [Link] method.
3. Use [Link] and [Link] method to transfer to
LMAItem.

 Example code
Dim datasource As LMADataSource

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If

Dim objVessel As LMVessel


Dim objItem1 As LMAItem
Dim objEquipment As LMEquipment
Dim objItem2 As LMAItem

Set objVessel = [Link](CONST_SPID_Vessel) 'get vessel by id


Set objItem1 = [Link]
Set objEquipment = [Link](CONST_SPID_Vessel) 'get equipment by id
Set objItem2 = [Link]

'print out some properties of objItem1 and objItem2


[Link] "ItemType = " & [Link]
[Link] "VolumeRating = " & [Link]("VolumeRating").Value
[Link] "ItemType = " & [Link]
[Link] "VolumeRating = " & [Link]("VolumeRating").Value

Set datasource = Nothing


Set objVessel = Nothing
Set objItem1 = Nothing
Set objEquipment = Nothing
Set objItem2 = Nothing

13
SmartPlant P&ID Automation Labs

10. ACCESS LMAATTRIBUTES COLLECTION

a) Purpose
To access LMAAttributes collection of LLAMA object.
b) Problem Statement
Place a Vessel and get the LMVessel object, then loop through its Attributes collection.
c) Solution
 Example code
Dim datasource As LMADataSource

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If

Dim objVessel As LMVessel

Set objVessel = [Link](CONST_SPID_Vessel) 'get vessel by id

Dim objAttr As LMAAttribute


[Link] "Total attributes for Vessel: " & [Link]
For Each objAttr In [Link]
[Link] "Attribute Name=" & [Link] & Space(50 - Len([Link])) & "
Value=" & [Link]
Next

[Link] [Link]("[Link]").Value
[Link] "Total attributes for Vessel: " & [Link]
For Each objAttr In [Link]
[Link] "Attribute Name=" & [Link] & Space(50 - Len([Link])) & "
Value=" & [Link]
Next

Set datasource = Nothing


Set objVessel = Nothing
Set objAttr = Nothing

14
SmartPlant P&ID Automation Labs

11. ACCESS ITEMATTRIBUTIONS IN DETAILS

a) Purpose
To access ItemAttributions of different items in details
b) Problem Statement
Place all kinds of SmartPlant P&ID items, such as Vessel, Mechanical, Heat Exchanger, then
print their ItemAttributions information in details in format of Excel, which includes attribution
format, index if codelist, calculation ProgID and validation ProgID

c) Solution
1. Get Items
2. Needs access [Link]
3. Print result in Excel
 Example code
Dim datasource As LMADataSource
Dim i As Integer
Dim objAttr As LMAAttribute
Dim vValue As Variant
Dim objVessel As LMVessel

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If

Dim objExcel As [Link]

Set objExcel = CreateObject("[Link]")


[Link] = True

Dim xlWorkbook As [Link]


Set xlWorkbook = [Link]

Dim xlWorksheet As [Link]


Set xlWorksheet = [Link]("SHEET1")

Dim Row As Long


Dim CodeListCount As Long

Row = 1

[Link](Row, 1) = "ItemType"

[Link](Row, 2) = "Attribute Name"

[Link](Row, 3) = "Format"

[Link](Row, 4) = "IsCodeList"

[Link](Row, 5) = "CodeList Index"

15
SmartPlant P&ID Automation Labs

[Link](Row, 6) = "Calculation ProgID"

[Link](Row, 7) = "Validation ProgID"


Row = Row + 1

Set objVessel = [Link](CONST_SPID_Vessel)


[Link](Row, 1) = "Total attributions for Vessel: " & [Link]
Row = Row + 1
For Each objAttr In [Link]
[Link](Row, 1) = [Link]
[Link](Row, 2) = [Link]
[Link](Row, 3) = [Link]
On Error Resume Next
CodeListCount = 0
CodeListCount = [Link]
On Error GoTo 0
If CodeListCount > 0 Then
[Link](Row, 4) = "True"
Else
[Link](Row, 4) = "False"
End If
[Link](Row, 5) = [Link]
[Link](Row, 6) = [Link]
[Link](Row, 7) = [Link]
Row = Row + 1
Next

Row = Row + 1
On Error Resume Next
vValue = [Link]("[Link]")
On Error GoTo 0
[Link](Row, 1) = "Total attributions for Vessel: " & [Link]
Row = Row + 1
For Each objAttr In [Link]
[Link](Row, 1) = [Link]
[Link](Row, 2) = [Link]
[Link](Row, 3) = [Link]
On Error Resume Next
CodeListCount = 0
CodeListCount = [Link]
On Error GoTo 0
If CodeListCount > 0 Then
[Link](Row, 4) = "True"
Else
[Link](Row, 4) = "False"
End If
[Link](Row, 5) = [Link]
[Link](Row, 6) = [Link]
[Link](Row, 7) = [Link]
Row = Row + 1
Next

Dim strFileName As String


strFileName = Environ("TEMP") & "\[Link]"
[Link](1).SaveAs (strFileName)

16
SmartPlant P&ID Automation Labs

[Link] True
[Link]

MsgBox "Done"

Set datasource = Nothing


Set objVessel = Nothing
Set xlWorksheet = Nothing
Set xlWorkbook = Nothing
Set objExcel = Nothing

17
SmartPlant P&ID Automation Labs

12. COLLECT ITEMS FROM THE DATABASE USING FILTERS

a) Purpose
To access objects created through SPPID using filters
b) Problem Statement
Place a piperun and give it a TagSuffix value. Retrieve the piperun by filtering on the TagSuffix
value = “P” and populate the Name property with value “P-Run”
c) Solution
1. Dim LMAFilter and LMACriterion
2. Add LMACriterion to LMAFilter
3. Call [Link] method by using the LMAFilter
 Example code
Dim datasource As LMADataSource

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If

Dim objFilter As LMAFilter


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

[Link] = "TagSuffix"
[Link] = "P"
[Link] = "="
[Link] = "PipeRun"
[Link] criterion

Dim piperun As LMPipeRun


Dim piperuns As LMPipeRuns
Set piperuns = New LMPipeRuns
[Link] datasource, Filter:=objFilter

[Link] "Number of Piperuns retrieved = " & [Link]


[Link]
For Each piperun In piperuns
[Link] [Link]("TagSuffix").Value

[Link] "Piperun ID = " & [Link]


[Link]("Name").Value = "P-Run"
[Link]
Next
[Link]
Set datasource = Nothing
Set objFilter = Nothing
Set criterion = Nothing
Set piperun = Nothing
Set piperuns = Nothing

18
SmartPlant P&ID Automation Labs

13. COLLECT ITEMS FROM THE DATABASE USING FILTERS WITH


MULTIPLE CRITERIA

a) Purpose
To access objects created through SPPID using filters with multiple criteria
b) Problem Statement
Place three piperuns and set OperFluidCode=”KD” for one piperun, TagSuffix = “PT” for another
pipe run and Name=”V” for another pipe run. Retrieve the three piperuns by filtering using
Multiple Criteria.
c) Solution
1. Dim LMAFilter and LMACriterion
2. Add multiple LMACriterion to LMAFilter
3. Call [Link] method by using the LMAFilter
 Example code
Dim datasource As LMADataSource

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If

Dim objFilter As LMAFilter


Set objFilter = New LMAFilter

[Link] ("FirstOne")
[Link]("FirstOne").SourceAttributeName = "ItemTag"
[Link]("FirstOne").ValueAttribute = "%K%"
[Link]("FirstOne").Operator = "like"
[Link] = "PipeRun"

[Link] ("SecondOne")
[Link]("SecondOne").SourceAttributeName = "TagSuffix"
[Link]("SecondOne").ValueAttribute = "P_"
[Link]("SecondOne").Operator = "like"
[Link]("SecondOne").Conjunctive = False

[Link] ("ThirdOne")
[Link]("ThirdOne").SourceAttributeName = "Name"
[Link]("ThirdOne").ValueAttribute = Null
[Link]("ThirdOne").Operator = "!="
[Link]("ThirdOne").Conjunctive = False

Dim piperun As LMPipeRun


Dim piperuns As LMPipeRuns
Set piperuns = New LMPipeRuns
[Link] datasource, Filter:=objFilter

[Link] "Number of piperuns filtered = " & [Link]


For Each piperun In piperuns

19
SmartPlant P&ID Automation Labs

[Link] "ID = " & [Link]


[Link] "ItemTag = " & [Link]("ItemTag").Value
[Link] "TagSuffix = " & [Link]("TagSuffix").Value
[Link] "Name = " & [Link]("Name").Value
Next

Set datasource = Nothing


Set objFilter = Nothing
Set piperun = Nothing
Set piperuns = Nothing

20
SmartPlant P&ID Automation Labs

14. USING FILTERS WITH CRITERIA ON SELECT LIST DATA

a) Purpose
To access objects created through SPPID using filters with multiple criteria
b) Problem Statement
Place two piperuns and set NominalDiameter=2” for the piperuns. Then delete one piperun from
model. Retrieve the active piperun by filtering using Criteria on ItemStatus and NominalDiameter.
c) Solution
Need to find the index for ItemStatus=”Active” and NominalDiameter=2”.
 Example code
Dim datasource As LMADataSource

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If

Dim objFilter As LMAFilter


Set objFilter = New LMAFilter

[Link] ("FirstOne")
[Link]("FirstOne").SourceAttributeName = "ItemStatus"
[Link]("FirstOne").ValueAttribute = "1"
[Link]("FirstOne").Operator = "="
[Link] = "PipeRun"

[Link] ("SecondOne")
[Link]("SecondOne").SourceAttributeName = "NominalDiameter"
[Link]("SecondOne").ValueAttribute = "5064" '2"
[Link]("SecondOne").Operator = "="
[Link]("SecondOne").Conjunctive = True

Dim piperun As LMPipeRun


Dim piperuns As LMPipeRuns
Set piperuns = New LMPipeRuns
[Link] datasource, Filter:=objFilter

[Link] "Number of piperuns filtered = " & [Link]


For Each piperun In piperuns
[Link] "ID = " & [Link]
[Link] "ItemStatus = " & [Link]("ItemStatus").Value
[Link] "NominalDiameter = " & [Link]("NominalDiameter").Value
Next

Set datasource = Nothing


Set objFilter = Nothing
Set piperun = Nothing
Set piperuns = Nothing

21
SmartPlant P&ID Automation Labs

15. USING COMPOUND FILTER

a) Purpose
To access objects created through SPPID using compound filter
b) Problem Statement
Place six piperuns and set NominalDiameter=1”, 2”, and 3” for the piperuns. Then, delete three
piperuns from model. Retrieve the piperuns with ItemStatus=”Active” and NominalDiameter
equals 1” or 2” by using compound filter.
c) Solution
Comound allows conjunctive as both “And” and “Or”.
 Example code
Dim datasource As LMADataSource

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If

Dim objFilter As LMAFilter


Dim objChildFilter1 As LMAFilter
Dim objChildFilter2 As LMAFilter

Set objFilter = New LMAFilter


Set objChildFilter1 = New LMAFilter
Set objChildFilter2 = New LMAFilter

[Link] = "PipeRun"
[Link] = "Filter 1"
[Link] ("FirstOne")
[Link]("FirstOne").SourceAttributeName = "ItemStatus"
[Link]("FirstOne").ValueAttribute = "1"
[Link]("FirstOne").Operator = "="

[Link] = "PipeRun"
[Link] = "Filter 2"
[Link] ("FirstOne")
[Link]("FirstOne").SourceAttributeName = "NominalDiameter"
[Link]("FirstOne").ValueAttribute = "5032" '1"
[Link]("FirstOne").Operator = "="

[Link] ("SecondOne")
[Link]("SecondOne").SourceAttributeName = "NominalDiameter"
[Link]("SecondOne").ValueAttribute = 5064 '2"
[Link]("SecondOne").Operator = "="
[Link]("SecondOne").Conjunctive = False

[Link] = "PipeRun"
[Link] = 1 '1 for compound filter, 0 for simple filter
[Link] objChildFilter1
[Link] objChildFilter2

22
SmartPlant P&ID Automation Labs

[Link] = True

Dim piperun As LMPipeRun


Dim piperuns As LMPipeRuns
Set piperuns = New LMPipeRuns
[Link] datasource, Filter:=objFilter

[Link] "Number of piperuns filtered = " & [Link]


For Each piperun In piperuns
[Link] "ItemStatus = " & [Link]("ItemStatus").Value
[Link] "NominalDiameter = " & [Link]("NominalDiameter").Value
Next

Set datasource = Nothing


Set objFilter = Nothing
Set objChildFilter1 = Nothing
Set objChildFilter2 = Nothing
Set piperun = Nothing
Set piperuns = Nothing

23
SmartPlant P&ID Automation Labs

16. COLLECT FILTERS FROM DATASOURCE

a) Purpose
To collect all filters in SPPID from datasource
b) Problem Statement
Write a standalone application to retrieve all filters in SPPID from datasource. Display the Item
Type and the first Criterion (if one exists) in the filter for those of ItemType = “Instrument”.
c) Solution
1. Dim LMAFilter
2. Call [Link] method to get all LMAFilters in database
3. Use For … Next to loop through the LMAFilters and print out required properties
 Example code
Dim datasource As LMADataSource
If Not blnUsePIDDatasource Then
Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If
Dim objFiltersCollection As Collection
Set objFiltersCollection = [Link]

[Link] "Number of filters = " & [Link]


Dim objFilter As LMAFilter
For Each objFilter In [Link] 'objFiltersCollection
If [Link] = "Instrument" Then
If Not [Link] Is Nothing Then
If [Link] >= 1 Then
[Link] "Filter item type = " & [Link] & Space(20 -
Len([Link])) _
& "Filter name = " & [Link] & Space(50 - Len([Link])) _
& [Link](1).SourceAttributeName & Space(30 -
Len([Link](1).SourceAttributeName)) _
& [Link](1).Operator & Space(5) _
& [Link](1).ValueAttribute & Space(40 -
Len([Link](1).ValueAttribute))
End If
End If
End If
Next

'use the pre-defined filter


Set objFilter = [Link]("Active Equipment")
Dim objEquipments As LMEquipments
Set objEquipments = New LMEquipments
[Link] datasource, Filter:=objFilter
[Link] [Link]

Set datasource = Nothing


Set objFilter = Nothing
Set objFiltersCollection = Nothing
Set objEquipments = Nothing

24
SmartPlant P&ID Automation Labs

17. ACCESS SELECTLIST DATA

a) Purpose
To get familiar with LMAEnumAttList and LMAEnumratedAttributes objects in LLAMA.
b) Problem Statement
Write a standalone application to retrieve all Select List Data in SPPID from datasource. Display
properties, such as ListName, DependName, DependID. Then loop through all Select List Value
of each Select List Data, display properties, such as Name and Index.

c) Solution
 Example code
Dim datasource As LMADataSource

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If

Dim objEnum As LMAEnumAttList


Dim objEnums As LMAEnumAttLists
Dim objEnumAttr As LMAEnumeratedAttribute
Dim objEnumAttrs As LMAEnumeratedAttributes

Set objEnums = [Link]

[Link] "Total Select List Data found: " & [Link]

For Each objEnum In objEnums


[Link] ""
[Link] "Select List Name = " & [Link] & Space(40 -
Len([Link])) _
& "DependName = " & [Link] & Space(30 - Len([Link])) _
& "DependID = " & [Link]
Set objEnumAttrs = [Link]
For Each objEnumAttr In objEnumAttrs
[Link] "Name = " & [Link] & Space(65 - Len([Link])) _
& "Index = " & [Link]
Next
Next

Set datasource = Nothing


Set objEnum = Nothing
Set objEnums = Nothing
Set objEnumAttr = Nothing
Set objEnumAttrs = Nothing

25
SmartPlant P&ID Automation Labs

18. READ HISTORY PROPERTY OF MODELITEM

a) Purpose
To read the history data belongs to a modelitem.
b) Problem Statement
Place a Vessel. Write a standalone application to read the history data belongs to this Vessel.
c) Solution
 Example code
Dim datasource As LMADataSource

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If

Dim objModelItem As LMModelItem


Set objModelItem = [Link](CONST_SPID_ModelItem)

Dim objHistory As LMHistory


Dim objHistories As LMHistories
Dim objAttribute As LMAAttribute
Set objHistories = [Link]

[Link] [Link]

For Each objHistory In objHistories


For Each objAttribute In [Link]
[Link] "Name: " & [Link] & Space(20 - Len([Link])) & "Value:
" & [Link]
Next
Next

Set datasource = Nothing


Set objModelItem = Nothing
Set objHistory = Nothing
Set objHistories = Nothing
Set objAttribute = Nothing

26
SmartPlant P&ID Automation Labs

19. READ STATUS PROPERTY OF MODELITEM

a) Purpose
To read the Status datas belongs to a modelitem
b) Problem Statement
Place a Vessel with some Status data populated. Write a standalone application to read the
status data belongs to this Vessel.
c) Solution
 Example code
Dim datasource As LMADataSource

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If

Dim objModelItem As LMModelItem


Set objModelItem = [Link](CONST_SPID_ModelItem)

Dim objStatus As LMStatus


Dim objStatuses As LMStatuses
Set objStatuses = [Link]

[Link] [Link]

Dim objAttribute As LMAAttribute


For Each objStatus In objStatuses
For Each objAttribute In [Link]
[Link] "Name: " & [Link] & Space(20 - Len([Link])) & "Value:
" & [Link]
Next
Next

Set datasource = Nothing


Set objModelItem = Nothing
Set objStatus = Nothing
Set objStatuses = Nothing
Set objAttribute = Nothing

27
SmartPlant P&ID Automation Labs

20. READ CASE PROPERTY OF MODELITEM

a) Purpose
To read Case data of a modelitem
b) Problem Statement
Place a Vessel with some Case data populated. Write a standalone application to read the case
data belongs to this Vessel.
c) Solution
 Example code
Dim datasource As LMADataSource

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If

Dim objModelItem As LMModelItem


Set objModelItem = [Link](CONST_SPID_ModelItem)

Dim objCase As LMCase


Dim objCases As LMCases
Set objCases = [Link]
[Link] [Link]

Dim objAttribute As LMAAttribute


Dim objCaseProcess As LMCaseProcess
Dim objCaseControl As LMCaseControl
For Each objCase In objCases
For Each objAttribute In [Link]
[Link] "Name: " & [Link] & Space(20 - Len([Link])) & "Value:
" & [Link]
Next
[Link] [Link]
For Each objCaseProcess In [Link]
For Each objAttribute In [Link]
[Link] "Name: " & [Link] & Space(20 - Len([Link])) &
"Value: " & [Link]
Next
Next
[Link] [Link]
For Each objCaseControl In [Link]
For Each objAttribute In [Link]
[Link] "Name: " & [Link] & Space(20 - Len([Link])) &
"Value: " & [Link]
Next
Next
Next

Set datasource = Nothing


Set objModelItem = Nothing

28
SmartPlant P&ID Automation Labs

Set objCase = Nothing


Set objCases = Nothing
Set objAttribute = Nothing
Set objCaseProcess = Nothing
Set objCaseControl = Nothing

29
SmartPlant P&ID Automation Labs

21. ACCESS ITEMNOTE

a) Purpose
To access an ItemNote.
b) Problem Statement
Place an ItemNote. Write a standalone application to read the properties of this ItemNote.
c) Solution
 Example code
Dim datasource As LMADataSource

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If

Dim objItemNote As LMItemNote


Set objItemNote = [Link](CONST_SPID_ItemNote)

Dim objAttribute As LMAAttribute


For Each objAttribute In [Link]
[Link] "Name: " & [Link] & Space(40 - Len([Link])) & "Value: "
& [Link]
Next

Dim objNote As LMNote


[Link] [Link]

For Each objNote In [Link]


For Each objAttribute In [Link]
[Link] "Name: " & [Link] & Space(40 - Len([Link])) & "Value:
" & [Link]
Next
Next

Set datasource = Nothing


Set objItemNote = Nothing
Set objNote = Nothing
Set objAttribute = Nothing

30
SmartPlant P&ID Automation Labs

22. ACCESS OPC

a) Purpose
To access an OPC
b) Problem Statement
Place an OPC and its PairOPC in another drawing. Write a standalone application to read the
properties of this OPC and its PairOPC.

c) Solution
 Example code
Dim datasource As LMADataSource

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If

Dim objOPC As LMOPC


Set objOPC = [Link](CONST_SPID_OPC)

Dim objAttribute As LMAAttribute


For Each objAttribute In [Link]
[Link] "Name: " & [Link] & Space(20 - Len([Link])) & "Value: "
& [Link]
Next

Dim objPairOPC As LMOPC


Set objPairOPC = [Link]

For Each objAttribute In [Link]


[Link] "Name: " & [Link] & Space(20 - Len([Link])) & "Value: "
& [Link]
Next

Set datasource = Nothing


Set objOPC = Nothing
Set objPairOPC = Nothing
Set objAttribute = Nothing

31
SmartPlant P&ID Automation Labs

23. FILTER FOR HISTORIES

a) Purpose
To filter for histories by TimeStamp and ItemType
b) Problem Statement
Set the active plant with some items placed. Write a standalone application to filter Histories.

c) Solution
 Example code
Dim datasource As LMADataSource

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If

Dim objFilter As LMAFilter


Set objFilter = New LMAFilter

[Link] ("FirstOne")
[Link]("FirstOne").SourceAttributeName = "TimeStamp"
[Link]("FirstOne").ValueAttribute = "7/19/04 8:00:00 AM"
[Link]("FirstOne").Operator = ">"
[Link] = "History"

[Link] ("SecondOne")
[Link]("SecondOne").SourceAttributeName = "[Link]"
[Link]("SecondOne").ValueAttribute = 29 '29 is the index for 'Plant Item'
[Link]("SecondOne").Operator = "="
[Link]("SecondOne").Conjunctive = True
Dim objHistories As LMHistories

Set objHistories = New LMHistories


[Link] datasource, Filter:=objFilter

[Link] [Link]

Dim objHistory As LMHistory

For Each objHistory In objHistories


[Link] [Link]("TimeStamp").Value
[Link] [Link]("ModelItemType").Value
Next

Set datasource = Nothing


Set objFilter = Nothing
Set objHistories = Nothing
Set objHistory = Nothing

32
SmartPlant P&ID Automation Labs

24. CHANGE PROPERTIS AT DIFFERNET OBJECT LEVELS

a) Purpose
To access “Name” property at different object level.
b) Problem Statement
Place a vessel. Write a standalone application to change “Name” property at Equipment object
level, and see how it changes the output for Vessel object
c) Solution
1. use [Link] and [Link] methods to obtain object
Vessel and Equipment with same SP_ID
[Link] property “Name” value of Equipment object, then obtain Vessel object again to see how
it changes the property “Name” value of Vessel
 Example code
Dim datasource As LMADataSource

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If
[Link]
Dim objVessel As LMVessel
Dim objEquipment As LMEquipment
Set objVessel = [Link](CONST_SPID_Vessel)
Set objEquipment = [Link](CONST_SPID_Vessel)

Dim objAttr As LMAAttribute


[Link] "Total attributes for Vessel: " & [Link]
For Each objAttr In [Link]
[Link] "Attribute Name : Value " & [Link] & " : " & [Link]
Next

[Link] "Total attributes for Equipment: " & [Link]


For Each objAttr In [Link]
[Link] "Attribute Name : Value " & [Link] & " : " & [Link]
Next

[Link] [Link]
[Link] [Link]

[Link]("Name").Value = "Lab-12"
[Link]
Set objVessel = [Link](CONST_SPID_Vessel)
[Link] [Link]
[Link] [Link]

[Link]
Set datasource = Nothing
Set objVessel = Nothing
Set objEquipment = Nothing
Set objAttr = Nothing

33
SmartPlant P&ID Automation Labs

25. READ CASEPROPERTY OF VESSEL

a) Purpose
To access case properties of Vessel.
b) Problem Statement
Place a vessel. Populate the some case property value of the vessel. Write a standalone
application to access the case and caseprocess of the vessel and read properties of the case.
c) Solution
1. Dim LMVessel
2. Vessel is associated several LMCases, if Case Class is Case Process, then this Case can
have two CaseProcesses associated with it, depends on Quality, which can be Maximun or
Minimum, then a one to one filtered relationship is found for the Vessel and Case property
 Example code
Dim datasource As LMADataSource

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If
Dim objVessel As LMVessel
Set objVessel = [Link](CONST_SPID_Vessel)

[Link] "[Link] = " &


[Link]("[Link]").Value

Set datasource = Nothing


Set objVessel = Nothing

34
SmartPlant P&ID Automation Labs

26. READ FLOW DIRECTION OF PIPERUN

a) Purpose
To obtain Flow Direction of Piperun
b) Problem Statement
Place a Piperun. Write a standalone application to obtain Flow Direction information about the
Piperun.
c) Solution
 Example code
Dim datasource As LMADataSource

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If
Dim objPiperun As LMPipeRun
Set objPiperun = [Link](CONST_SPID_PipeRun)

[Link] "Flow Direction = " & [Link]("FlowDirection").Value

Set datasource = Nothing


Set objPiperun = Nothing

35
SmartPlant P&ID Automation Labs

27. ACCESS PIPING POINT

a) Purpose
To access a Piping Point.
b) Problem Statement
Place a Valve. Write a standalone application to access PipingPoint belongs to this Valve.
c) Solution
 Example code
Dim datasource As LMADataSource

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If

Dim objPipingComp As LMPipingComp


Set objPipingComp = [Link](CONST_SPID_PipingComp)

Dim objAttribute As LMAAttribute


Dim objPipingPoint As LMPipingPoint
[Link] [Link]

For Each objPipingPoint In [Link]


For Each objAttribute In [Link]
[Link] "Name: " & [Link] & Space(25 - Len([Link])) & "Value:
" & [Link]
Next
Next

Set datasource = Nothing


Set objPipingComp = Nothing
Set objPipingPoint = Nothing
Set objAttribute = Nothing

36
SmartPlant P&ID Automation Labs

28. ACCESS SIGNAL POINT

a) Purpose
To access a Signal Point.
b) Problem Statement
Place an offline Instrument. Write a standalone application to access PipingPoint belongs to this
offline Instrument.
c) Solution
 Example code
Dim datasource As LMADataSource

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If

Dim objInstrument As LMInstrument


Set objInstrument = [Link](CONST_SPID_OfflineInstrument)

Dim objAttribute As LMAAttribute


Dim objSignalPoint As LMSignalPoint
[Link] [Link]

For Each objSignalPoint In [Link]


For Each objAttribute In [Link]
[Link] "Name: " & [Link] & Space(20 - Len([Link])) & "Value:
" & [Link]
Next
Next

Set datasource = Nothing


Set objInstrument = Nothing
Set objSignalPoint = Nothing
Set objAttribute = Nothing

37
SmartPlant P&ID Automation Labs

29. IMPLIEDITEM

a) Purpose
To navigate the relationship between Implied item and its parent item.
b) Problem Statement
Place a Instrument off-line with implied item. Write a standalone application to obtain any items in
the database that are Implied Item
c) Solution
1. Dim LMPlantItem, LMACriterion and LMAFilter
2. Implied item would have property “PartOfType” is equal to “Implied”, which has the index
number is 2.
 Example code
Dim datasource As LMADataSource

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If

Dim objFilter As LMAFilter


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

[Link] = "PartOfType"
[Link] = "2" 'implied item
[Link] = "="
[Link] = "PlantItem"
[Link] criterion

Dim objPlantItem As LMPlantItem


Dim objPlantItems As LMPlantItems
Set objPlantItems = New LMPlantItems
[Link] datasource, Filter:=objFilter
[Link] "Number of Implied Items retrieved = " & [Link]

For Each objPlantItem In objPlantItems


[Link] "PartOfType = " & [Link]("PartOfType").Value
[Link] "Parent Item Type = " &
[Link]("ItemTypeName").Value
Next

Set datasource = Nothing


Set objFilter = Nothing
Set criterion = Nothing
Set objPlantItem = Nothing
Set objPlantItems = Nothing

38
SmartPlant P&ID Automation Labs

30. PARTOFPLANTITEM RELATIONSHIPS

a) Purpose
To navigate the relationship between item and its parent item.
b) Problem Statement
Place a Instrument off-line with implied item, two nozzles, two trays, TEAM ends Write a
standalone application to find all the items that have parent item in the database
c) Solution
1. Dim LMPlantItem, LMACriterion and LMAFilter
2. Implied item would have property “SP_PartOfID” is not NULL
 Example code
Dim datasource As LMADataSource

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If

Dim objFilter As LMAFilter


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

[Link] = "SP_PartOfID"
[Link] = Null
[Link] = "!="
[Link] = "PlantItem"
[Link] criterion

Dim objPlantItem As LMPlantItem


Dim objPlantItems As LMPlantItems
Set objPlantItems = New LMPlantItems
[Link] datasource, Filter:=objFilter
[Link] "Number of child items retrieved = " & [Link]

For Each objPlantItem In objPlantItems


[Link] "PartOfType = " & [Link]("PartOfType").Value
[Link] "Parent Item Type = " &
[Link]("ItemTypeName").Value
Next

Set datasource = Nothing


Set objFilter = Nothing
Set criterion = Nothing
Set objPlantItem = Nothing
Set objPlantItems = Nothing

39
SmartPlant P&ID Automation Labs

31. ACCESS INSTRUMENT LOOP

c) Purpose
To get familiar with relationship between PlantItemGroup and PlantItem
d) Problem Statement
Use LMAFilter to search for Instrument Loops, then check how many PlantItems are associated
with the Instrument Loop. At the end, try to associate an Instrument with this Instrument Loop.
c) Solution

 Example code
Dim datasource As LMADataSource

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If

Dim objFilter As LMAFilter


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

[Link] = "ItemTag"
[Link] = "L-101L"
[Link] = "="

[Link] = "InstrLoop"
[Link] criterion

Dim objInstrLoops As LMInstrLoops


Dim objInstrLoop As LMInstrLoop
Set objInstrLoops = New LMInstrLoops
[Link] datasource, Filter:=objFilter 'get InstrLoop by filter
If [Link] > 0 Then
Set objInstrLoop = [Link](1)
Else

Set datasource = Nothing


Set objFilter = Nothing
Set criterion = Nothing
Set objInstrLoop = Nothing
Set objInstrLoops = Nothing
Exit Sub
End If

Dim objPlantItem As LMPlantItem


Dim objPlantItems As LMPlantItems
Set objPlantItems = [Link]

[Link] "Number of plant items in the InstrLoop = " & [Link]

40
SmartPlant P&ID Automation Labs

'print plantitems in the instrument loop


Dim i As Integer
i=1
For Each objPlantItem In objPlantItems
[Link] "ItemTypeName No. " & i & " " & [Link] & " ID =" &
[Link]
i=i+1
Next

'add an instrument to the instrument loop


Dim objInstr As LMInstrument
Set objInstr = [Link](CONST_SPID_OfflineInstrument)
[Link] "Number of PlantItemGroups that are associated with this instrument= " &
[Link]
[Link] [Link]
'[Link]
[Link] "Number of PlantItemGroups that are associated with this instrument= " &
[Link]

Set datasource = Nothing


Set objFilter = Nothing
Set criterion = Nothing
Set objInstrLoops = Nothing
Set objInstrLoop = Nothing
Set objPlantItems = Nothing
Set objPlantItem = Nothing
Set objInstr = Nothing

41
SmartPlant P&ID Automation Labs

32. LOADINSTRUMENTS

a) Purpose
To navigate the relationship between Instrloop and Instrument through LoadInstruments method.
b) Problem Statement
Place couple instrloops, and couple instruments, then make association between them. Write a
standalone application to find instruments associated with instrloops through LoadInstruments
method.
c) Solution

 Example code
Dim datasource As LMADataSource
Dim objInstrLoops As LMInstrLoops
Dim objInstrLoop As LMInstrLoop
Dim objInstruments As LMInstruments
Dim objInstrument As LMInstrument

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If

Set objInstrLoops = New LMInstrLoops


[Link] datasource

[Link] [Link]

Set objInstruments = [Link]

[Link] [Link]

For Each objInstrument In objInstruments


[Link] [Link]("ItemTag").Value
[Link] [Link](1).Attributes("ItemTag")

Next

For Each objInstrLoop In objInstrLoops


[Link] [Link]("ItemTag").Value
If Not [Link] Is Nothing Then
[Link] [Link]
End If

Next

Set objInstrLoops = Nothing


Set objInstrLoop = Nothing
Set objInstruments = Nothing
Set objInstrument = Nothing
Set datasource = Nothing

42
SmartPlant P&ID Automation Labs

33. IDENTIFY NOZZLE AND EQUIPMENT

a) Purpose
To access nozzles on a vessel by navigating the relationship between nozzles and vessels.
b) Problem Statement
Place a vessel. Place two different nozzles on the vessel. Write a standalone application to
retrieve the following properties of the nozzle:
SP_ID, aabbcc code, ID of equipment that the nozzle is connected to, Flowdirection, Nozzle type.
c) Solution
1. obtain Vessel object by SP_ID
2. use [Link] to get a collection of nozzle belong to this Vessel

 Example code
Dim datasource As LMADataSource

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If

Dim vessel As LMVessel


Set vessel = [Link](CONST_SPID_Vessel)

Dim nozzles As LMNozzles


Set nozzles = [Link]

[Link] [Link]
Dim nozzle As LMNozzle

For Each nozzle In nozzles


[Link] "Nozzle ID = " & [Link]
[Link] "Nozzle's aabbcc code = " & [Link]("aabbcc_code").Value
[Link] "ID of equipment that the nozzle is connected to = " & [Link]
[Link] "Nozzle's flow direction = " & [Link]("FlowDirection").Value

[Link] "Nozzle type = " & [Link]("NozzleType").Value


[Link]
Next

Set datasource = Nothing


Set vessel = Nothing
Set nozzles = Nothing
Set nozzle = Nothing

43
SmartPlant P&ID Automation Labs

34. PIPINGCOMP AND INLINECOMP

a) Purpose
To navigate the relationship between PipingComp and InlineComp.
b) Problem Statement
Place a Valve. Write a standalone application to navigate from pipingcomp to piperun and from
piperun to pipingcomp through InlineComp.
c) Solution
1. use [Link]
2. loop [Link]
3. use [Link]

 Example code
Dim datasource As LMADataSource

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If

Dim objPipingComp As LMPipingComp


Dim objPiperun As LMPipeRun
Dim objInlineComp As LMInlineComp

Set objPipingComp = [Link](CONST_SPID_PipingComp)

If [Link] = 1 Then
Set objPiperun = [Link](1).PipeRunObject

[Link] "PipeRun ItemTag: " & [Link]("ItemTag").Value

For Each objInlineComp In [Link]


Set objPipingComp = Nothing
Set objPipingComp = [Link]
If Not objPipingComp Is Nothing Then
[Link] "PipingComp Type: " &
[Link]("PipingCompType").Value
End If
Next
End If

Set datasource = Nothing


Set objPipingComp = Nothing
Set objPiperun = Nothing
Set objInlineComp = Nothing

44
SmartPlant P&ID Automation Labs

35. INSTURMENT AND INLINECOMP

a) Purpose
To navigate the relationship between Inline-Instrument and InlineComp.
b) Problem Statement
Place a Instrument Valve. Write a standalone application to navigate from inline-instrument to
piperun and from piperun to inline-instrument through inlinecomp.
c) Solution
1. use [Link]
2. loop [Link]
3. use [Link]

 Example code
‘be aware of that only inline instrument associate with InlineComp object.

Dim datasource As LMADataSource

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If

Dim objInstrument As LMInstrument


Dim objPiperun As LMPipeRun
Dim objInlineComp As LMInlineComp

Set objInstrument = [Link](CONST_SPID_InlineInstrument)

If [Link]("IsInline").Value = True Then


Set objPiperun = [Link](1).PipeRunObject

[Link] "PipeRun ItemTag: " & [Link]("ItemTag").Value

For Each objInlineComp In [Link]


Set objInstrument = Nothing
Set objInstrument = [Link]
If Not objInstrument Is Nothing Then
[Link] "Instrument Type: " & [Link]("InstrumentType").Value
End If
Next
End If

Set datasource = Nothing


Set objInstrument = Nothing
Set objInlineComp = Nothing

45
SmartPlant P&ID Automation Labs

36. OFFLINE INSTRUMENT AND SIGNALRUN

a) Purpose
Explore the relationship between offline instrument and SignalRun.
b) Problem Statement
Place an offline instrument, and then place couple singalruns connected with it. Write a
standalone application to navigate from offline-instrument to signalrun.
c) Solution
 Example code
Dim datasource As LMADataSource

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If

Dim objInstrument As LMInstrument


Dim objSignalRun As LMSignalRun

Set objInstrument = [Link](CONST_SPID_OfflineInstrument)


Set objSignalRun = [Link]
[Link] [Link]("SignalType").Value

[Link] [Link]
For Each objInstrument In [Link]
[Link] [Link]("InstrumentType").Value
Next

Set datasource = Nothing


Set objInstrument = Nothing
Set objSignalRun = Nothing

46
SmartPlant P&ID Automation Labs

37. ACCESS INSTRUMETN FUNCTIONS

a) Purpose
Explore the relationship between instrument and its functions
b) Problem Statement
Place an instrument, and populate properties for its functions. Write a standalone application to
access instrument functions.
c) Solution
 Example code
Dim datasource As LMADataSource

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If

Dim objInstrument As LMInstrument


Dim objInstrFailMode As LMInstrFailMode
Dim objInstrFunction As LMInstrFunction
Dim objInstrOption As LMInstrFunction
Dim objAttribute As LMAAttribute

Set objInstrument = [Link](CONST_SPID_OfflineInstrument)


[Link] [Link]
For Each objInstrFailMode In [Link]
For Each objAttribute In [Link]
[Link] "Attribute Name=" & [Link] & Space(50 - Len([Link]))
& " Value=" & [Link]
Next
Next

[Link] [Link]
For Each objInstrFunction In [Link]
For Each objAttribute In [Link]
[Link] "Attribute Name=" & [Link] & Space(50 - Len([Link]))
& " Value=" & [Link]
Next
Next

[Link] [Link]
For Each objInstrOption In [Link]
For Each objAttribute In [Link]
[Link] "Attribute Name=" & [Link] & Space(50 - Len([Link]))
& " Value=" & [Link]
Next
Next

Set datasource = Nothing


Set objInstrument = Nothing
Set objInstrFailMode = Nothing

47
SmartPlant P&ID Automation Labs

Set objInstrFunction = Nothing


Set objInstrOption = Nothing
Set objAttribute = Nothing

48
SmartPlant P&ID Automation Labs

38. IDENTIFY CONNECTORS OF A PIPERUN

a) Purpose
To traverse the relationships from the Model DataModel to the Drawing DataModel
b) Problem Statement
Place a piperun between two nozzles and place two valves on it. Populate the ItemTag of the
piperun with a value (eg. 15L – GCD). Retrieve the piperun by filtering for the piperun’s ItemTag
and locate all of its representations and connector representations.
c) Solution
1. Dim LMPipeRun, LMConnector, LMRepresentation
2. LMConnector is subclass of LMRepresentation, and its RepresentationType is “Connector”.

 Example code
Dim datasource As LMADataSource

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If

Dim objFilter As LMAFilter


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

[Link] = "ItemTag"
[Link] = "01110-GCD"
[Link] = "="
[Link] = "PipeRun"
[Link] criterion

Dim piperun As LMPipeRun


Dim piperuns As LMPipeRuns
Set piperuns = New LMPipeRuns
[Link] datasource, Filter:=objFilter

Dim connector As LMConnector


Dim representation As LMRepresentation

For Each piperun In piperuns


For Each representation In [Link]
If [Link] = "Connector" Then
Set connector = [Link]([Link])
[Link] [Link]("ItemStatus").Value
[Link] "Model itme type = " &
[Link]("ItemTypeName").Value
End If
Next

49
SmartPlant P&ID Automation Labs

Next

Set datasource = Nothing


Set objFilter = Nothing
Set criterion = Nothing
Set piperuns = Nothing
Set piperun = Nothing
Set connector = Nothing
Set representation = Nothing

50
SmartPlant P&ID Automation Labs

39. FIND FILE NMAE OF A SYMBOL

a) Purpose
Find file name of a symbol
b) Problem Statement
Place a vessel, then navigate from vessel to symbol, and get the file name of the vessel from the
symbol object.
c) Solution
 Example code
Dim datasource As LMADataSource

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If

Dim objVessel As LMVessel


Dim objSymbol As LMSymbol

Set objVessel = [Link](CONST_SPID_Vessel)


Set objSymbol = [Link]([Link](1).ID)
[Link] [Link]("FileName").Value

'if you are required to find file name of a piperun, what should you do?
Set datasource = Nothing
Set objVessel = Nothing
Set objSymbol = Nothing

51
SmartPlant P&ID Automation Labs

40. FIND X, Y COORDINATES OF SYMBOL

a) Purpose
Find X, Y Coordinates of symbol
b) Problem Statement
Place a vessel, then navigate from vessel to symbol, and get the X, Y Coordinates of the vessel
from the symbol object.

c) Solution
 Example code
Dim datasource As LMADataSource

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If

Dim objVessel As LMVessel


Dim objSymbol As LMSymbol

Set objVessel = [Link](CONST_SPID_Vessel)


Set objSymbol = [Link]([Link](1).ID)
[Link] "XCoordinate = " & [Link]("XCoordinate").Value
[Link] "YCoordinate = " & [Link]("YCoordinate").Value

Set datasource = Nothing

52
SmartPlant P&ID Automation Labs

41. FIND X, Y COORDINATES OF PIPERUN

a) Purpose
Find X, Y Coordinates of Piperun
b) Problem Statement
Place a Piperun, then navigate from Piperun to Connector, and get the X, Y Coordinates of the
Piperun from Connector object.

c) Solution
 Example code
Dim datasource As LMADataSource

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If

Dim objPiperun As LMPipeRun


Dim objRep As LMRepresentation
Dim objConnector As LMConnector
Dim objConnectorVertex As LMConnectorVertex
Dim objSymbol As LMSymbol

Set objPiperun = [Link](CONST_SPID_PipeRun)

For Each objRep In [Link]


If [Link]("RepresentationType").Value = "Connector" And
[Link]("ItemStatus").Value = "Active" Then
Set objConnector = [Link]([Link])
For Each objConnectorVertex In [Link]
[Link] "XCoordinate = " & [Link]("XCoordinate").Value
[Link] "YCoordinate = " & [Link]("YCoordinate").Value
Next
End If
Next

'if the X, Y Coordinates are on the symbol that is connected with the Connector, what should
you do?
Set datasource = Nothing
Set objPiperun = Nothing
Set objRep = Nothing
Set objConnector = Nothing
Set objConnectorVertex = Nothing
Set objSymbol = Nothing

53
SmartPlant P&ID Automation Labs

42. FIND LABELS OF A SYMBOL

a) Purpose
Find labels on a symbol
b) Problem Statement
Place a vessel, then place couple labels on it, then navigate from Vessel to Representation, then
find labels on the Vessel.
c) Solution
 Example code
Dim datasource As LMADataSource

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If

Dim objVessel As LMVessel


Dim objSymbol As LMSymbol
Dim objLabelPersist As LMLabelPersist
Dim objAttr As LMAAttribute
Dim objLeaderVertex As LMLeaderVertex

Set objVessel = [Link](CONST_SPID_Vessel)


Set objSymbol = [Link]([Link](1).ID)

[Link] "Total labels on this symbol: " & [Link]

For Each objLabelPersist In [Link]


For Each objAttr In [Link]
[Link] "Attribute Name=" & [Link] & Space(50 - Len([Link])) & "
Value=" & [Link]
Next
For Each objLeaderVertex In [Link]
[Link] "XCoordinate = " & [Link]("XCoordinate").Value
[Link] "YCoordinate = " & [Link]("YCoordinate").Value
Next
Next

'if you are required to find labels of a piperun, what should you do?
Set datasource = Nothing
Set objVessel = Nothing
Set objSymbol = Nothing
Set objLabelPersist = Nothing
Set objAttr = Nothing
Set objLeaderVertex = Nothing

54
SmartPlant P&ID Automation Labs

43. FIND PARENT REPRESENTATION OF A LABEL

a) Purpose
Find Parent Representation of a label.
b) Problem Statement
Place a label on to a vessel, get label object first, then navigate from label to find Representation
it labels, then navigate from the Representation to ModelItem.
c) Solution
 Example code
Dim datasource As LMADataSource

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If

Dim objLabelPersist As LMLabelPersist


Dim objRep As LMRepresentation
Dim objModelItem As LMModelItem
Dim objAttr As LMAAttribute

Set objLabelPersist = [Link](CONST_SPID_LabelPersist)


Set objRep = [Link]
Set objModelItem = [Link]

[Link] "Total labels on this symbol: " & [Link]

For Each objAttr In [Link]


[Link] "Attribute Name=" & [Link] & Space(50 - Len([Link])) & "
Value=" & [Link]
Next

'if parent is piperun, what should you do?


Set datasource = Nothing
Set objLabelPersist = Nothing
Set objRep = Nothing
Set objModelItem = Nothing
Set objAttr = Nothing

55
SmartPlant P&ID Automation Labs

44. FIND PARENT DRAWING FOR A SYMBOL

a) Purpose
Find parent drawing of a symbol.
b) Problem Statement
Place a vessel on a drawing. Write a standalone application to find drawing this vessel is on.
c) Solution
 Example code
Dim datasource As LMADataSource

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If

Dim objVessel As LMVessel


Dim objSymbol As LMSymbol

Set objVessel = [Link](CONST_SPID_Vessel)


Set objSymbol = [Link]([Link](1).ID)

Dim objDrawing As LMDrawing


Set objDrawing = [Link]
[Link] [Link]("Name").Value

Set datasource = Nothing


Set objVessel = Nothing
Set objSymbol = Nothing
Set objDrawing = Nothing

56
SmartPlant P&ID Automation Labs

45. FIND ACTIVE DRAWING AND PLANTITEMS IN IT

a) Purpose
Directly find the active drawing not through an item first, then find all PlantItems in it.
b) Problem Statement
Open a drawing. Write a standalone application to find what active drawing is and how many
PlantItems in it.
c) Solution
 Example code
Dim datasource As LMADataSource

'have to user PIDDatasource


Set datasource = PIDDataSource

Dim objDrawing As LMDrawing


Set objDrawing = [Link]([Link])
[Link] [Link]("Name").Value

Dim objFilter As LMAFilter


Set objFilter = New LMAFilter

[Link] ("FirstOne")
[Link]("FirstOne").SourceAttributeName = "[Link]"
[Link]("FirstOne").ValueAttribute = [Link]("Name").Value
[Link]("FirstOne").Operator = "="
[Link] = "PlantItem"

[Link] ("SecondOne")
[Link]("SecondOne").SourceAttributeName = "ItemStatus"
[Link]("SecondOne").ValueAttribute = 1
[Link]("SecondOne").Operator = "="
[Link]("SecondOne").Conjunctive = True

Dim objPlantItems As LMPlantItems


Set objPlantItems = New LMPlantItems
[Link] datasource, Filter:=objFilter

[Link] "Number of plantitems in active drawing: " & [Link]

Set datasource = Nothing


Set objDrawing = Nothing
Set objFilter = Nothing
Set objPlantItems = Nothing

57
SmartPlant P&ID Automation Labs

46. FILTER FOR ITEMS IN PLANT STOCKPILE

a) Purpose
To filter for all items in plant stockpile.
b) Problem Statement
Write a standalone application to get all items in plant stockpile.
c) Solution
 Example code
Dim datasource As LMADataSource

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If
Dim objFilter As LMAFilter
Set objFilter = New LMAFilter
[Link] ("FirstOne")
[Link]("FirstOne").SourceAttributeName = "ItemStatus"
[Link]("FirstOne").ValueAttribute = 1
[Link]("FirstOne").Operator = "="
[Link] = "Vessel"

[Link] ("SecondOne")
[Link]("SecondOne").SourceAttributeName = "[Link]"
[Link]("SecondOne").ValueAttribute = 2 '2 is index stands for True
[Link]("SecondOne").Operator = "="
[Link]("SecondOne").Conjunctive = True

[Link] ("ThirdOne")
[Link]("ThirdOne").SourceAttributeName = "Representation.SP_DrawingId"
[Link]("ThirdOne").ValueAttribute = 0 '0 stands Plant Stockpile
[Link]("ThirdOne").Operator = "="
[Link]("ThirdOne").Conjunctive = True

Dim objVessels As LMVessels


Set objVessels = New LMVessels
[Link] datasource, Filter:=objFilter

[Link] [Link]

Dim objVessel As LMVessel


For Each objVessel In objVessels
[Link] [Link]("ItemTag").Value
[Link] [Link](1).Attributes("InStockpile").Value
Next

Set datasource = Nothing


Set objFilter = Nothing
Set objVessels = Nothing
Set objVessel = Nothing

58
SmartPlant P&ID Automation Labs

47. IDENTIFY ITEMS CONNECTED TO A PIPERUN

a) Purpose
To traverse the relationships from LMConnector to LMSymbol
b) Problem Statement
Place a piperun between two nozzles and place two valves on it. Populate the ItemTag of the
piperun with a value (eg. unit1100-GCD). Retrieve the piperun by filtering for the piperun’s
ItemTag. Identify all of the items connected to the ends of the connectors of the piperun.
c) Solution
1. Dim LMPipeRun, LMConnector, LMRepresentation
2. LMConnector has properties “ConnectItem1SymbolObject” and
“ConnectItem2SymbolObject”, that returns the symbol object connected to
the Connector

 Example code
Dim datasource As LMADataSource

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If

Dim objFilter As LMAFilter


Dim criterion As LMACriterion

Set criterion = New LMACriterion


Set objFilter = New LMAFilter

[Link] = "ItemTag"
[Link] = "01110-GCD"
[Link] = "="
[Link] = "PipeRun"
[Link] criterion

Dim piperun As LMPipeRun


Dim piperuns As LMPipeRuns
Set piperuns = New LMPipeRuns
[Link] datasource, Filter:=objFilter

Dim connector As LMConnector


Dim representation As LMRepresentation
For Each piperun In piperuns
For Each representation In [Link]
If [Link] = "Connector" Then
Set connector = [Link]([Link])
If Not connector.ConnectItem1SymbolObject Is Nothing Then
[Link] [Link]
_
& " - ID: " & [Link]
End If

59
SmartPlant P&ID Automation Labs

If Not connector.ConnectItem2SymbolObject Is Nothing Then


[Link] [Link]
_
& " - ID: " & [Link]
End If
End If
Next
Next

Set datasource = Nothing


Set objFilter = Nothing
Set criterion = Nothing
Set piperuns = Nothing
Set piperun = Nothing
Set connector = Nothing
Set representation = Nothing

60
SmartPlant P&ID Automation Labs

48. IDENTIFY THE PIPERUN ASSOCIATED WITH THE PIPINGCOMP

a) Purpose
To traverse the relationships from LMPipingComp to LMPipeRun
b) Problem Statement
Place a piperun, then place a valve in the middle of the piperun. Assume you only know the
SP_ID of the valve. Write a standalone application to obtain the PipeRun on which the valve is
sitting, then read properties (ID and Name) of the piperun.
c) Solution
1. Dim LMPipingComp, LMSymbol, LMPipeRun
2. LMSymbol has a property “Connect1Connectors”, that returns the collection
of LMConnector object connected to the Symbol, then from
[Link], returns the ModelItemID of the Connector, which
is the SP_ID of the PipeRun.
3. Alternate, LMPipingComp has method “InlineComps”, which returns the collection of
LMInlineComps associated with the PipingComp, then, LMInlineComp has a property
“PipeRunID”, which returns the SP_ID of the PipeRun, on which the PipingComp is sitting.

 Example code
Dim datasource As LMADataSource

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If

Dim objPipingComp As LMPipingComp


Set objPipingComp = [Link](CONST_SPID_PipingComp)

Dim objPipingCompSym As LMSymbol


Set objPipingCompSym = [Link]([Link](1).ID)

Dim objPiperun As LMPipeRun


Set objPiperun =
[Link]([Link](1).ModelItemID)
'or you can obtain PipeRun as following
'Set objPipeRun = '[Link]([Link](1).PipeRunID)
[Link] "PipeRun ID = " & [Link]
[Link] "PipeRun ItemTag = " & [Link]("ItemTag").Value
'Note they are the same item
[Link] "PipingComp ID = " & [Link]
[Link] "InlineComp ID = " & [Link](1).ID

Set datasource = Nothing


Set objPipingComp = Nothing
Set objPipingCompSym = Nothing
Set objPiperun = Nothing

61
SmartPlant P&ID Automation Labs

49. NAVIGATE ITEMS TO GET PARENT ITEM

a) Purpose
To navigate items such as PipeRun, Connectors, nozzles, to get the parent item of nozzle –
Equipment.
b) Problem Statement
Place a vessel with a nozzle on it, then place a piperun connected to the nozzle, then place a
valve in the piperun. Write a standalone application to navigate from the piperun, through the
piperun’s connectors and the nozzle to arrive at the vessel. Print out some properties of the
vessel.
c) Solution
1. Dim LMAFilter, LMACriterion, LMPipeRuns
2. From [Link], obtain LMConnector, whose RepresentationType is
“Connector”, then, from LMConnector.ConnnectItem1SymbolObject or
LMConnector.ConnecItem2SymbolObject find the Symbol object connect to
the Connector, then, from [Link] find the SP_ID of the symbol, then the Nozzle
object is located, and LMNozzle has a property “EquipmentObject”, which returns the
LMEquipment object, which is connected to the Nozzle

 Example code
Dim datasource As LMADataSource

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If

Dim objFilter As LMAFilter


Dim criterion As LMACriterion

Set objFilter = New LMAFilter


Set criterion = New LMACriterion
[Link] = "ItemTag"
[Link] = "01110-GCD"
[Link] = "="
[Link] = "PipeRun"
[Link] criterion

Dim piperun As LMPipeRun


Dim piperuns As LMPipeRuns
Set piperuns = New LMPipeRuns
[Link] datasource, Filter:=objFilter

[Link] "Number of Piperuns retrieved = " & [Link]

Dim representation As LMRepresentation


Dim connector As LMConnector
Dim nozzle As LMNozzle
Dim objEquipment As LMEquipment

62
SmartPlant P&ID Automation Labs

For Each piperun In piperuns


For Each representation In [Link]
If [Link] = "Connector" Then
Set connector = [Link]([Link])
If Not connector.ConnectItem1SymbolObject Is Nothing Then
If [Link] =
"Nozzle" Then
Set nozzle =
[Link]([Link])
Exit For
End If
End If
If Not connector.ConnectItem2SymbolObject Is Nothing Then
If [Link] =
"Nozzle" Then
Set nozzle =
[Link]([Link])
Exit For
End If
End If
End If
Next
Next

Set objEquipment = [Link]


[Link] "ID = " & [Link]
[Link] "EquipmentType = " & [Link]
[Link] "ItemTag = " & [Link]("ItemTag").Value
[Link] "Nozzles belong to the vessel = " & [Link]

Set datasource = Nothing


Set objFilter = Nothing
Set criterion = Nothing
Set objEquipment = Nothing
Set nozzle = Nothing
Set connector = Nothing
Set representation = Nothing
Set piperuns = Nothing
Set piperun = Nothing

63
SmartPlant P&ID Automation Labs

50. NAVIGATE THROUGH BRANCHPOINT

a) Purpose
To navigate through branch point on a piperun.
b) Problem Statement
Place a vessel with two nozzles on it with ItemTags N10 and N20 respectively. Generate the
itemtag for the vessel by assigning a TagPrefix. Place a straight piperun starting from the nozzle
(N10) and end it in space with no connection. Start a branch piperun from some point on the first
piperun, and extend it to the second nozzle (N20). Write a standalone application to navigate
from the first nozzle (N10), through the piperun connectors and the second nozzle to arrive back
at the vessel.
c) Solution
1. Dim LMAFileter, LMACriterion, LMSymbol, LMPipeRun
2. BranchPoint is a Symbol Representation of the PipeRun on which it is sitting, BranchPoint’s
RepresentationType is “Branch”
 Example code
Dim datasource As LMADataSource

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If

Dim objFilter As LMAFilter


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

[Link] = "ItemTag"
[Link] = "N10"
[Link] = "="
[Link] = "Nozzle"
[Link] criterion

Dim nozzle As LMNozzle


Dim nozzles As LMNozzles
Set nozzles = New LMNozzles
[Link] datasource, Filter:=objFilter
'make sure only one nozzle is obtained
If [Link] = 1 Then
Set nozzle = [Link](1)
Else

Set datasource = Nothing


Set nozzles = Nothing
Set nozzle = Nothing
Exit Sub
End If

'get nozzle symbol

64
SmartPlant P&ID Automation Labs

Dim symbol1 As LMSymbol


Set symbol1 = [Link]([Link](1).ID)

'check nozzle symbol's connect1connectors & connect2connectors information to find a


connector
'connected to the nozzle
Dim Tconnector As LMConnector
Dim connector As LMConnector
If [Link] >= 1 Then
For Each Tconnector In symbol1.Connect1Connectors
If [Link] = "Active" Then
If [Link] = "PipeRun" Then
Set connector = Tconnector
End If
End If
Next
End If

If connector Is Nothing And [Link] >= 1 Then


For Each Tconnector In symbol1.Connect2Connectors
If [Link] = "Active" Then
If [Link] = "PipeRun" Then
Set connector = Tconnector
End If
End If
Next
End If

'once the connector is found, check connectitem1symbolobject and connectitem2symbolobject


information
'to find the BranchPoint.
'The modelitem for the BranchPoint symbol is the piperun, but the representationtype is
"Branch"
Dim branchsymbol As LMSymbol
If Not connector.ConnectItem1SymbolObject Is Nothing Then
If [Link] = "PipeRun"
Then
If [Link] =
"Branch" Then
Set branchsymbol = connector.ConnectItem1SymbolObject
End If
End If
End If
If branchsymbol Is Nothing And Not connector.ConnectItem2SymbolObject Is Nothing Then
If [Link] = "PipeRun"
Then
If [Link] =
"Branch" Then
Set branchsymbol = connector.ConnectItem2SymbolObject
End If
End If
End If

'After the BranchPoint is located, use again the connect1connectors & connect2connectors
method to locate

65
SmartPlant P&ID Automation Labs

'the connector connected to the BranchPoint, and make sure this connector is point back to the
new piperun
Dim connector2 As LMConnector
Dim connector3 As LMConnector
If [Link] >= 1 Then
For Each connector2 In branchsymbol.Connect1Connectors
If [Link] <> [Link] Then
Set connector3 = connector2
Exit For
End If
Next
End If

If connector3 Is Nothing And [Link] >= 1 Then


For Each connector2 In branchsymbol.Connect2Connectors
If [Link] <> [Link] Then
Set connector3 = connector2
Exit For
End If
Next
End If

'After second connector is located, check connectitem1symbolobject &


connectitem2symbolobject to find
'the second nozzle
Dim nozzle2 As LMNozzle
If Not connector3.ConnectItem1SymbolObject Is Nothing Then
If [Link] = "Nozzle" Then
Set nozzle2 =
[Link]([Link])
End If
End If
If nozzle2 Is Nothing And Not connector3.ConnectItem2SymbolObject Is Nothing Then
If [Link] = "Nozzle" Then
Set nozzle2 =
[Link]([Link])
End If
End If

'Print out two nozzles' name and itmetag of the vessel they attached
[Link] "Nozzle2 itemtag = " & [Link]("ItemTag").Value
[Link] "Nozzle itemtag = " & [Link]("ItemTag").Value
[Link] "vessel nozzle2 attached = " &
[Link]("ItemTag").Value
[Link] "vessel nozzle attached =" & [Link]("ItemTag").Value
Set datasource = Nothing
Set objFilter = Nothing
Set criterion = Nothing
Set nozzle = Nothing
Set nozzles = Nothing
Set nozzle2 = Nothing
Set connector = Nothing
Set connector2 = Nothing
Set connector3 = Nothing
Set branchsymbol = Nothing

66
SmartPlant P&ID Automation Labs

51. NAVIGATE THROUGH OPC

a) Purpose
To get familiar with navigation through OPC
b) Problem Statement
Place an OPC, then place its pair OPC into another drawing, and connected the pair OPC to a
piperun with itemtag populated. Then write a standalone application to navigate for OPC to its
pairOPC, and print out the itemtag of piperun that the pair OPC is connected with.
c) Solution

 Example code
Dim datasource As LMADataSource

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If

Dim objFilter As LMAFilter


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

[Link] = "[Link]"
[Link] = "unit2d"
[Link] = "="
[Link] = "OPC"
[Link] criterion

Dim objOPC As LMOPC


Dim objOPCs As LMOPCs
Dim objpairOPC As LMOPC
Dim objRep As LMRepresentation
Dim objPiperun As LMPipeRun
Dim objSym As LMSymbol
Dim objConnector As LMConnector

Set objOPCs = New LMOPCs


[Link] datasource, Filter:=objFilter

[Link] "Total OPCs were found: " & [Link]

For Each objOPC In objOPCs


Set objpairOPC = [Link]
For Each objRep In [Link]
If [Link] > 0 Then
[Link] "pairOPC is on drawing: " &
[Link]("Name").Value
End If

67
SmartPlant P&ID Automation Labs

Set objSym = [Link]([Link])


For Each objConnector In objSym.Connect1Connectors
Set objPiperun = [Link]([Link])
[Link] "pairOPC is connected to Piperun: " &
[Link]("ItemTag").Value
Next
For Each objConnector In objSym.Connect2Connectors
Set objPiperun = [Link]([Link])
[Link] [Link]("ItemTag").Value
Next
Next
Next

Set datasource = Nothing


Set objOPCs = Nothing
Set objOPC = Nothing
Set objpairOPC = Nothing
Set objRep = Nothing
Set objSym = Nothing
Set objPiperun = Nothing
Set objConnector = Nothing

68
SmartPlant P&ID Automation Labs

52. ACCESS RELATIONSHIP FROM REPRESENTATION

a) Purpose
To access relationship object from representation object.
b) Problem Statement
Place piperun, then place a valve on the piperun. Write a standalone application to obtain the
valve, then get the relationship objects belong to this valve.
c) Solution
 Example code
Dim datasource As LMADataSource

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If

Dim objPipingComp As LMPipingComp


Dim objRepresentation As LMRepresentation
Dim objRelationships As LMRelationships
Dim objRelationship As LMRelationship
Dim objAttribute As LMAAttribute

Set objPipingComp = [Link](CONST_SPID_PipingComp)


Set objRepresentation = [Link](1)
Set objRelationships = objRepresentation.Relation1Relationships
For Each objRelationship In objRelationships
If Not objRelationship.Item1RepresentationObject Is Nothing Then
[Link]
[Link]
End If
If Not objRelationship.Item2RepresentationObject Is Nothing Then
[Link]
[Link]
End If
For Each objAttribute In [Link]
[Link] "Name: " & [Link] & Space(20 - Len([Link])) & "Value:
" & [Link]
Next
Next

Set objRelationships = objRepresentation.Relation2Relationships


For Each objRelationship In objRelationships
If Not objRelationship.Item1RepresentationObject Is Nothing Then
[Link]
[Link]
End If
If Not objRelationship.Item2RepresentationObject Is Nothing Then
[Link]
[Link]
End If

69
SmartPlant P&ID Automation Labs

For Each objAttribute In [Link]


[Link] "Name: " & [Link] & Space(20 - Len([Link])) & "Value:
" & [Link]
Next
Next

Set datasource = Nothing


Set objPipingComp = Nothing
Set objRepresentation = Nothing
Set objRelationships = Nothing
Set objRelationship = Nothing
Set objAttribute = Nothing

70
SmartPlant P&ID Automation Labs

53. ACCESS INCONSISTENCY

a) Purpose
To access the Inconsistency.
b) Problem Statement
Write a standalone application to get all relationship objects belong to a drawing, then access the
Inconsistency from relationship.
c) Solution
 Example code
Dim datasource As LMADataSource

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If

Dim objFilter As LMAFilter


Dim criterion As LMACriterion

Set criterion = New LMACriterion


Set objFilter = New LMAFilter

[Link] = "Name"
[Link] = "Automation1"
[Link] = "="
[Link] = "Drawing"
[Link] criterion

Dim objDrawing As LMDrawing


Dim objDrawings As LMDrawings
Set objDrawings = New LMDrawings
[Link] datasource, Filter:=objFilter

Dim objRelationships As LMRelationships


Dim objRelationship As LMRelationship
Dim objInconsistencies As LMInconsistencies
Dim objInconsistency As LMInconsistency
Dim objAttribute As LMAAttribute

For Each objDrawing In objDrawings


Set objRelationships = [Link]
For Each objRelationship In objRelationships
Set objInconsistencies = [Link]
For Each objInconsistency In objInconsistencies
For Each objAttribute In [Link]
[Link] "Name: " & [Link] & Space(20 - Len([Link])) &
"Value: " & [Link]
Next

71
SmartPlant P&ID Automation Labs

Next
Next
Next

Set datasource = Nothing


Set objDrawings = Nothing
Set objDrawing = Nothing
Set objRelationships = Nothing
Set objRelationship = Nothing
Set objInconsistencies = Nothing
Set objInconsistency = Nothing

72
SmartPlant P&ID Automation Labs

54. ACCESS RULEREFERENCE

a) Purpose
To access the RuleReference.
b) Problem Statement
Write a standalone application to get all relationship objects belong to a drawing, then access the
RuleReference from relationship.
c) Solution
 Example code
Dim datasource As LMADataSource

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If

Dim objFilter As LMAFilter


Dim criterion As LMACriterion

Set criterion = New LMACriterion


Set objFilter = New LMAFilter

[Link] = "Name"
[Link] = "Automation1"
[Link] = "="
[Link] = "Drawing"
[Link] criterion

Dim objDrawing As LMDrawing


Dim objDrawings As LMDrawings
Set objDrawings = New LMDrawings
[Link] datasource, Filter:=objFilter

Dim objRelationships As LMRelationships


Dim objRelationship As LMRelationship
Dim objRuleReferences As LMRuleReferences
Dim objRuleReference As LMRuleReference
Dim objAttribute As LMAAttribute

For Each objDrawing In objDrawings


Set objRelationships = [Link]
For Each objRelationship In objRelationships
Set objRuleReferences = [Link]
For Each objRuleReference In objRuleReferences
For Each objAttribute In [Link]
[Link] "Name: " & [Link] & Space(20 - Len([Link])) &
"Value: " & [Link]
Next

73
SmartPlant P&ID Automation Labs

Next
Next
Next

Set datasource = Nothing


Set objDrawings = Nothing
Set objDrawing = Nothing
Set objRelationships = Nothing
Set objRelationship = Nothing
Set objRuleReferences = Nothing
Set objRuleReference = Nothing

74
SmartPlant P&ID Automation Labs

55. ACCESS PLANTGROUP FROM PLANTITEM

a) Purpose
To access the PlantGroup to which the PlantItem belongs.
b) Problem Statement
Place a vessel. Write a standalone application to get the plantgroup to which the PlantItem is
associated.
c) Solution
 Example code
Dim datasource As LMADataSource

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If

Dim objVessel As LMVessel


Set objVessel = [Link](CONST_SPID_Vessel)

Dim objPlantGroup As LMPlantGroup

'get the plantgroup just above the drawing, in our case, should be unit
Set objPlantGroup = [Link]
[Link] "PlantGroup Name = " & [Link]("Name").Value

Dim strParentID As String


strParentID = [Link]("ParentID").Value

Dim objParentPlantGroup As LMPlantGroup


Set objParentPlantGroup = [Link](strParentID)
[Link] "Parent PlantGroup Name = " & [Link]("Name").Value

Set datasource = Nothing


Set objVessel = Nothing
Set objPlantGroup = Nothing
Set objParentPlantGroup = Nothing

75
SmartPlant P&ID Automation Labs

56. ACCESS PLANTGROUP FROM DRAWING

a) Purpose
To access the PlantGroup to which the Drawing belongs.
b) Problem Statement
Place a vessel. Write a standalone application to obtain the drawing associated with the vessel.
Get the plantgroup to which the drawing belongs.
c) Solution
 Example code
Dim datasource As LMADataSource

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If

Dim objVessel As LMVessel


Set objVessel = [Link](CONST_SPID_Vessel)

Dim objPlantGroup As LMPlantGroup

'get the plantgroup just above the drawing, in our case, should be unit
Set objPlantGroup = [Link](1).[Link]
[Link] "PlantGroup Name = " & [Link]("Name").Value

Dim strParentID As String


strParentID = [Link]("ParentID").Value

Dim objParentPlantGroup As LMPlantGroup


Set objParentPlantGroup = [Link](strParentID)
[Link] "Parent PlantGroup Name = " & [Link]("Name").Value

Set datasource = Nothing


Set objVessel = Nothing
Set objPlantGroup = Nothing
Set objParentPlantGroup = Nothing

76
SmartPlant P&ID Automation Labs

57. ACCESS CUSTOMIZED PLANTGROUP

a) Purpose
To access the customized property of a user defined PlantGroup type.
b) Problem Statement
Create a new PlantGroup type, “SubArea”, in SmartPlant Engineering Manager, then create a
new Hierarcy template using this new PlantGroup. Then create a new plant using this new
Hierarcy template, after creation of new plant, add a new property “T1” to the new PlantGroup.
Write a standalone application to read this new property “T1”.
c) Solution
 Example code
Dim datasource As LMADataSource

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If

Dim objVessel As LMVessel


Set objVessel = [Link](CONST_SPID_Vessel) 'get objVessel by id
[Link] [Link]("T1")
[Link] [Link]("SPMSubArea", [Link]).Attributes("T1")

Set datasource = Nothing


Set objVessel = Nothing

77
SmartPlant P&ID Automation Labs

58. ACCESS WORKSHARE STIE

a) Purpose
To get familiar with the workshare site object in LLAMA.
b) Problem Statement
Place a Vessel, find the workshare site to which this vessel belongs. Print out properties of the
workshare site. Browser relateionship between workshare site and other entities, such as
PlantGroup, PlantItemGroup, OPC, and DrawingSite.
c) Solution

 Example code
Dim datasource As LMADataSource

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If

Dim objVessel As LMVessel


Set objVessel = [Link](CONST_SPID_Vessel)

Dim objDrawing As LMDrawing


Set objDrawing = [Link]([Link](1).DrawingID)

Dim objPlantGroup As LMPlantGroup


'get the plantgroup just above the drawing, in our case, should be unit
Set objPlantGroup = [Link]

Dim objWSSite As LMWSSite

Set objWSSite = [Link]

Dim objAttr As LMAAttribute


[Link] "How many attributes? " & [Link]
For Each objAttr In [Link]
[Link] "Attribute Name: " & [Link] & " Attribute Value: " & [Link]
Next

Dim objOPC As LMOPC


[Link] "Total OPCs in WS Site: " & [Link]
For Each objOPC In [Link]
[Link] [Link]("OPCTag").Value
[Link] [Link]("Name").Value
Next

Dim objPlantItemGroup As LMPlantItemGroup


[Link] "Total PlantItemGroups in WS Site: " & [Link]
For Each objPlantItemGroup In [Link]
[Link] [Link]("PlantItemGroupType").Value

78
SmartPlant P&ID Automation Labs

[Link] [Link]("Name").Value
Next

[Link] "Total PlantGroups in WS Site: " & [Link]


For Each objPlantGroup In [Link]
[Link] [Link]("PlantGroupType").Value
[Link] [Link]("Name").Value
[Link] [Link]("Name").Value
Next

Dim objDrawingSite As LMDrawingSite


[Link] "Total DrawingSites in WS Site: " & [Link]
For Each objDrawingSite In [Link]
[Link] [Link]("Name").Value
[Link] [Link]("Name").Value
Next

Set datasource = Nothing


Set objVessel = Nothing
Set objDrawing = Nothing
Set objPlantGroup = Nothing
Set objAttr = Nothing
Set objOPC = Nothing
Set objPlantItemGroup = Nothing
Set objDrawingSite = Nothing

79
SmartPlant P&ID Automation Labs

59. ACCESS DRAWINGSITE

a) Purpose
To get familiar with the drawingsite object in LLAMA.
b) Problem Statement
Get a drawingsite object, the print out properties of the drawingsite.
c) Solution

 Example code
Dim datasource As LMADataSource

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If
Dim objVessel As LMVessel
Set objVessel = [Link](CONST_SPID_Vessel)

Dim objDrawing As LMDrawing


Set objDrawing = [Link]([Link](1).DrawingID)

Dim objDrawingSite As LMDrawingSite


Set objDrawingSite = [Link](1)

Dim objAttr As LMAAttribute


[Link] "How many attributes? " & [Link]
For Each objAttr In [Link]
[Link] "Attribute Name: " & [Link] & " Attribute Value: " & [Link]
Next

Dim objDrawingSubscriber As LMDrawingSubscriber


[Link] "Total drawing subscriber: " & [Link]
For Each objDrawingSubscriber In [Link]
[Link] [Link]("Name").Value
[Link] [Link]("Name").Value
Next

[Link] [Link]("Name").Value
[Link] [Link]("Name").Value
If Not [Link] Is Nothing Then
[Link] [Link]("Name").Value
End If
[Link] [Link]("Name").Value

Set datasource = Nothing


Set objVessel = Nothing
Set objDrawing = Nothing
Set objDrawingSite = Nothing
Set objDrawingSubscriber = Nothing
Set objAttr = Nothing

80
SmartPlant P&ID Automation Labs

60. WORKSHARE AWARENESS IN LLAMA

a) Purpose
To check out the workshare awareness in LLAMA.
b) Problem Statement
Set a satellite site as active project, then access a vessel in a drawing which is read-only for this
satellite site, try to modify the property of the vessel and commit to database. See what happens?
c) Solution
 Example code
Dim datasource As LMADataSource

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If

[Link]

Dim objVessel As LMVessel


Set objVessel = [Link](CONST_SPID_Vessel)
[Link] [Link]("Name").Value
'expects error in following code, "Read Only attribute"
[Link]("Name").Value = "InWorkshare"
[Link]

[Link]

Set datasource = Nothing


Set objVessel = Nothing

81
SmartPlant P&ID Automation Labs

61. ACCESS ACTIVE PROJECT

a) Purpose
To access the active project
b) Problem Statement
Set The Plant or one of projects as active project, then use [Link] to
obtain the active project. Then, print out all attributions of the active project, pay attention to the
Project Status.
c) Solution
 Example code
Dim datasource As LMADataSource
Dim objActiveProject As LMActiveProject
Dim objAttribute As LMAAttribute

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If

Set objActiveProject = [Link]


For Each objAttribute In [Link]
[Link] "Name: " & [Link] & Space(20 - Len([Link])) & "Value: "
& [Link]
Next

Set datasource = Nothing


Set objActiveProject = Nothing
Set objAttribute = Nothing

82
SmartPlant P&ID Automation Labs

62. HOW TO ACCESS PLANT FROM PROJECT

a) Purpose
When user is in a project, how to find the project belongs to which The Plant?
b) Problem Statement
Set one of the projects as active project, then try to find The Plant.
c) Solution
 Example code
Dim datasource As LMADataSource
Dim objPlantGroups As LMPlantGroups
Dim objPlantGroup As LMPlantGroup
Dim objAttribute As LMAAttribute

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If

Set objPlantGroups = New LMPlantGroups


[Link] datasource

[Link] "Total PlantGroups: " & [Link]

For Each objPlantGroup In objPlantGroups


For Each objAttribute In [Link]
[Link] "Name: " & [Link] & Space(20 - Len([Link])) & "Value:
" & [Link]
If [Link] = "Depth" And [Link] = "0" Then
MsgBox "ThePlant is: " & [Link]("Name")
End If
Next
Next

Set datasource = Nothing


Set objPlantGroups = Nothing
Set objPlantGroup = Nothing
Set objAttribute = Nothing

83
SmartPlant P&ID Automation Labs

63. ACCESS CLAIM STATUS OF ITEMS

a) Purpose
To access the items’ claim status.
b) Problem Statement
Set items in different claim status, and access claim status by using function
[Link]
c) Solution
 Example code
Dim datasource As LMADataSource

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If

Dim objVessel As LMVessel


Set objVessel = [Link](CONST_SPID_Vessel) 'get objVessel by id

'check Claim status


[Link] [Link]([Link])

Set datasource = Nothing


Set objVessel = Nothing

84
SmartPlant P&ID Automation Labs

64. ACCESS OPTIONSETTINGS

a) Purpose
To access the OptionSetting by Filter, and read value of OptionSetting
b) Problem Statement
Write a standalone application to obtain optionsetting (Default Assembly Path) by filter and read
the value of the optionsetting.
c) Solution
1. Dim LMAFilter, LMACriterion, LMOptionSetting
2. LMOptionSetting is a independent object, which does not has any relationship with other
objects in Data Model. To access LMOptionSetting, users need to know exactly what they are
looking for, for example, in optionsettings, where is the “Default Assembly Path” ?

 Example code
Dim datasource As LMADataSource

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If

Dim objFilter As LMAFilter


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

[Link] = "Name"
[Link] = "Default Assembly Path"
[Link] = "="

[Link] = "OptionSetting"
[Link] criterion

Dim objOptionSettings As LMOptionSettings


Dim objOptionSetting As LMOptionSetting
Set objOptionSettings = New LMOptionSettings
'get "Default Assembly Path" from OptionSettings by filter
[Link] datasource, Filter:=objFilter

Set objOptionSetting = [Link](1)


[Link] "Name = " & [Link]("Name").Value
[Link] "Value = " & [Link]("Value").Value

Set datasource = Nothing


Set objFilter = Nothing
Set criterion = Nothing
Set objOptionSettings = Nothing
Set objOptionSetting = Nothing

85
SmartPlant P&ID Automation Labs

65. CREATE A VESSEL AND PLACE INTO STOCKPILE

a) Purpose
Use PIDCreateItem method to create a vessel in the stockpile
b) Problem Statement
Write a standard executable to create a vessel and place it in the stockpile.
c) Solution
 Open the SmartPlant P&ID drawing.
1. Create a drawing through SPManager.
2. Double-click on the drawing to open up SmartPlant P&ID
 Create a standard executable VB project
3. Select a standard exe project
4. Reference the “Logical Model Automation” and “Placement Automation” libraries
 Add code to place a vessel into stockpile
5. Use the Function Function PIDCreateItem(DefinitionFile As String) As LMAItem
6. Provide the DefinitionFile string indicating the location of the symbol on a server
7. Use the return value to future reference.
 Example code
Dim objPlacement As Placement
Set objPlacement = New Placement

Dim item As LMAItem


Dim dirpath As String

Dim VesselLocation As String


VesselLocation = "\Equipment\Vessels\Horizontal Drums\Horz Surge w-Horiz [Link]"
'create a vessel into stockpile
Set item = [Link](VesselLocation)
If item Is Nothing Then
MsgBox "unsuccessful placement"
End If

Set objPlacement = Nothing


Set item = Nothing

86
SmartPlant P&ID Automation Labs

66. PLACE A VESSEL ON A DRAWING

a) Purpose
Use the PidPlaceSymbol method to place a vessel on a drawing
b) Problem Statement
Write a standard executable to place a vessel on a drawing.
c) Solution
 Open the SmartPlant P&ID drawing.
1. Create a drawing through SPManager.
2. Double-click on the drawing to open up SmartPlant P&ID
 Create a standard executable VB project
3. Select a standard exe project
4. Reference the “Logical Model Automation” and “Placement Automation” libraries
 Add code to place a vessel
5. Use the method Function PIDPlaceSymbol(DefinitionFile As String, X As Double, Y As
Double, [Mirror], [Rotation], [ExistingItem As LMAItem], [TargetItem]) As LMSymbol
6. Provide the DefinitionFile string indicating the location of the symbol on a server
7. Provide the X and Y coordinates of the placement on the drawing.
8. Use the return value to future reference.
 Example code
Dim objPlacement As Placement
Set objPlacement = New Placement

Dim dirpath As String

Dim symbol As LMSymbol


Dim VesselLocation As String
VesselLocation = "\Equipment\Vessels\Horizontal Drums\Horz Surge w-Horiz [Link]"

'place a vessle into active drawing


Set symbol = [Link](VesselLocation, 0.3, 0.2)

If symbol Is Nothing Then


MsgBox "unsuccessful placement"
End If

Set objPlacement = Nothing


Set symbol = Nothing

87
SmartPlant P&ID Automation Labs

67. PLACE NOZZLES AND TRAYS ON A VESSEL

a) Purpose
Use PIDPlaceSymbol method to place equipment components on a vessel
b) Problem Statement
Write a standard executable to place nozzles and trays on a vessel.
c) Solution
 Open the SmartPlant P&ID drawing.
1. Create a drawing through SPManager.
2. Double-click on the drawing to open up SmartPlant P&ID
 Create a standard executable VB project
3. Select a standard exe project
4. Reference the “Logical Model Automation” and “Placement Automation” libraries
 Add code to place a vessel
5. Use the Function PIDPlaceSymbol(DefinitionFile As String, X As Double, Y As Double,
[Mirror], [Rotation], [ExistingItem As LMAItem], [TargetItem]) As LMSymbol
6. Provide the DefinitionFile string indicating the location of the symbol on a server
7. Provide the X and Y coordinates of the placement on the drawing.
8. Provide the TargetItem as an LMAItem.
9. Use the return value to future reference.
10. Repeat place nozzles while set PIDSnapToTarget to TRUE
 Example code
Dim objPlacement As Placement
Set objPlacement = New Placement

Dim strdirpath As String


Dim nozzleName As String
Dim trayName As String

Dim xvessel As Double


Dim yvessel As Double
xvessel = 0.3
yvessel = 0.2
Dim symVessel As LMSymbol
Dim symbol2 As LMSymbol
Dim symbol3 As LMSymbol
Dim symbol4 As LMSymbol
Dim symbol5 As LMSymbol
Dim vesselName As String
Dim symbol21 As LMSymbol
Dim symbol31 As LMSymbol

vesselName = "\Equipment\Vessels\Vertical Drums\1D 1C [Link]"


nozzleName = "\Equipment Components\Nozzles\Flanged Nozzle with [Link]"
trayName = "\Equipment Components\Trays\Bubble Cap Trays\2-Pass Bubl [Link]"

'place a vessel
Set symVessel = [Link](vesselName, xvessel, yvessel)
'set Cleaning Requirement for the Vessel
Dim objVessel As LMVessel

88
SmartPlant P&ID Automation Labs

Set objVessel = [Link]([Link])


[Link]("CleaningReqmts").Value = "CC1"
'place two nozzles on vessel
Set symbol2 = [Link](nozzleName, xvessel - 0.2, yvessel + 0.05, _
TargetItem:=[Link])
Set symbol3 = [Link](nozzleName, xvessel + 0.2, yvessel + 0.07, _
TargetItem:=[Link])
'place two trays on vessel
Set symbol4 = [Link](trayName, xvessel - 0.05, yvessel + 0.05, _
TargetItem:=[Link])
Set symbol5 = [Link](trayName, xvessel + 0.05, yvessel + 0.1, _
TargetItem:=[Link])

''''' 'place nozzles again use same X, Y coordinates, but this time set PIDSnapToTarget=false
''''' [Link] = False
''''' Set symbol21 = [Link](nozzleName, xvessel - 0.2, yvessel + 0.05,
_
''''' TargetItem:=[Link])
''''' Set symbol31 = [Link](nozzleName, xvessel + 0.2, yvessel + 0.07,
_
''''' TargetItem:=[Link])
''''' [Link] = True

''''' 'place nozzles again use new X, Y coordinates, but this time set
PIDSetCopyPropertiesFlag=false
''''' [Link] False
''''' Set symbol21 = [Link](nozzleName, xvessel - 0.2, yvessel + 0.05,
_
''''' TargetItem:=[Link])
''''' Set symbol31 = [Link](nozzleName, xvessel + 0.2, yvessel + 0.07,
_
''''' TargetItem:=[Link])
''''' [Link] True

Set objPlacement = Nothing


Set symVessel = Nothing
Set symbol2 = Nothing
Set symbol3 = Nothing
Set symbol4 = Nothing
Set symbol5 = Nothing
''''' Set symbol21 = Nothing
''''' Set symbol31 = Nothing

68. PLACE LABELS ON A VESSEL

89
SmartPlant P&ID Automation Labs

a) Purpose
Use PIDPlaceLabel method to place labels on equipment
b) Problem Statement
Write a standard executable to populate some properties of a vessel and then place labels to
display them.
c) Solution
 Open the SmartPlant P&ID drawing.
1. Create a drawing through SPManager.
2. Double-click on the drawing to open up SmartPlant P&ID
 Create a standard executable VB project
3. Select a standard exe project
4. Reference the “Logical Model Automation” and “Placement Automation” libraries
 Add code to place a vessel
5. Use the Function PIDPlaceSymbol(DefinitionFile As String, X As Double, Y As Double,
[Mirror], [Rotation], [ExistingItem As LMAItem], [TargetItem]) As LMSymbol
6. Provide the DefinitionFile string indicating the location of the symbol on a server
7. Provide the X and Y coordinates of the placement on the drawing.
8. Provide the TargetItem as an LMAItem when placing nozzles or trays.
9. Use the return value to future reference.
 Add code to delete the vessel
10. Use the Function PIDPlaceLabel(DefinitionFile As String, Points() As Double, [Mirror],
[Rotation], [LabeledItem As LMRepresentation], [IsLeaderVisible As Boolean = False]) As
LMLabelPersist
11. The Points array consists of the exact number of points (starting from index 1) necessary
to place the label.
12. The LMRepresentation argument must be a representation of the parent item on the
drawing.
13. The return object is the label object.
 Example code
Dim objPlacement As Placement
Set objPlacement = New Placement

Dim strdirpath As String


Dim nozzleName As String
Dim trayName As String
Dim labelName1 As String
Dim labelName2 As String
Dim labelName3 As String
Dim vessel As LMVessel
Dim labelpersist As LMLabelPersist

Dim xvessel As Double


Dim yvessel As Double
xvessel = 0.2
yvessel = 0.2

Dim symVessel As LMSymbol


Dim vesselName As String
Dim points(1 To 4) As Double
Dim twopoints(1 To 2) As Double

90
SmartPlant P&ID Automation Labs

vesselName = "\Equipment\Vessels\Vertical Drums\1D 1C [Link]"


labelName1 = "\Equipment\Labels - Equipment\Equipment [Link]"
labelName2 = "\Equipment\Labels - Equipment\Insulation [Link]"
labelName3 = "\Equipment\Labels - Equipment\Heat [Link]"

'place vessel
Set symVessel = [Link](vesselName, xvessel, yvessel)
'get placed vessel and set some properties' value
Set vessel = [Link]([Link])
[Link] = "Vessel for Label Placement"
[Link] = "R15"
[Link] = "SS"
[Link] = "300 F"
[Link] = "ET"

'place three different labels for the vessel


twopoints(1) = xvessel + 0.02
twopoints(2) = yvessel + 0.1
Set labelpersist = [Link](labelName1, _
twopoints, Labeleditem:=[Link])
points(1) = xvessel
points(2) = yvessel
points(3) = xvessel - 0.05
points(4) = yvessel + 0.1
Set labelpersist = [Link](labelName2, _
points(), Labeleditem:=[Link], _
IsLeaderVisible:=True)

points(1) = xvessel
points(2) = yvessel
points(3) = xvessel + 0.05
points(4) = yvessel + 0.1
Set labelpersist = [Link](labelName3, _
points(), Labeleditem:=[Link], _
IsLeaderVisible:=True)

Set objPlacement = Nothing


Set symVessel = Nothing
Set labelpersist = Nothing

91
SmartPlant P&ID Automation Labs

69. PLACE OPC

a) Purpose
Use PIDPlaceOPC method to place an OPC into drawing.
b) Problem Statement
Write a standard executable to place an OPC into drawing.
c) Solution

 Example code
Dim objPlacement As Placement
Set objPlacement = New Placement

Dim OPClocation As String


OPClocation = "\Piping\Piping OPC's\[Link]"

'place a vessle into active drawing


Dim symbol As LMSymbol
Set symbol = [Link](OPClocation, 0.1, 0.1)

If symbol Is Nothing Then


MsgBox "unsuccessful placement"
End If

Set objPlacement = Nothing


Set symbol = Nothing

92
SmartPlant P&ID Automation Labs

70. PLACE OPC FROM STOCKPILE

a) Purpose
Use PIDPlaceOPC method to place an OPC from StockPile into drawing.
b) Problem Statement
Place an OPC into a drawing, and place its pair OPC in plant stockpile, then open another
drawing with a piperun placed, then write a standard executable to find the OPC, then find its pair
OPC in StockPile, then place it pair OPC from StockPile into current drawing, and connect with
the piperun.
c) Solution

 Example code
Dim objPlacement As Placement
Set objPlacement = New Placement

Dim OPClocation As String


OPClocation = "\Piping\Piping OPC's\[Link]"

Dim objOPC As LMOPC


Dim objpairOPC As LMOPC

Set objOPC = [Link](CONST_SPID_OPC)


Set objpairOPC = [Link]

Dim objConnector As LMConnector


Dim objPiperun As LMPipeRun
Dim objRep As LMRepresentation

Set objPiperun = [Link](CONST_SPID_PipeRun)


For Each objRep In [Link]
If [Link]("RepresentationType").Value = "Connector" Then
Set objConnector = [Link]([Link])
Exit For
End If
Next

Dim X As Double
Dim Y As Double

X = [Link](1).Attributes("XCoordinate").Value
Y = [Link](1).Attributes("YCoordinate").Value
'place the OPC from stockpile into active drawing
Dim symbol As LMSymbol
Set symbol = [Link](OPClocation, X, Y, , , [Link])

If symbol Is Nothing Then


MsgBox "unsuccessful placement"
End If

Set objPlacement = Nothing


Set symbol = Nothing

93
SmartPlant P&ID Automation Labs

71. PLACE PIPERUN WITH PIDPLACERUN

a) Purpose
Use PIDPlaceRun method to place a Piperun from stockpile into active drawing
b) Problem Statement
Write a standalone application to create a piperun in stockpile, then place this piperun from
stockpile into active drawing. Then place a valve, and place a piperun connects first piperun and
the valve.
c) Solution
 Example code
Dim objPlacement As Placement
Set objPlacement = New Placement

Dim PipeRunLocation As String


Dim objItem As LMAItem
Dim objConnector As LMConnector
Dim objInputs As PlaceRunInputs
Dim objSymbol As LMSymbol
Dim ValveLocation As String

PipeRunLocation = "\Piping\Routing\Process Lines\Primary [Link]"

Set objInputs = New PlaceRunInputs


[Link] 0.1, 0.1
[Link] 0.2, 0.1

Set objItem = [Link](PipeRunLocation)


Set objConnector = [Link](objItem, objInputs)

ValveLocation = "\Piping\Valves\2 Way Common\Ball [Link]"


Set objSymbol = [Link](ValveLocation, 0.15, 0.3, , 1.57)

Set objInputs = New PlaceRunInputs


[Link] objConnector, 0.15, 0.1
[Link] 0.15, 0.15
[Link] 0.12, 0.15
[Link] 0.12, 0.2
[Link] 0.15, 0.2
[Link] objSymbol, 0.15, 0.3

Set objItem = [Link](PipeRunLocation)


Set objConnector = [Link](objItem, objInputs)
'clean up
Set objPlacement = Nothing
Set objItem = Nothing
Set objConnector = Nothing
Set objSymbol = Nothing
Set objInputs = Nothing

94
SmartPlant P&ID Automation Labs

72. JOIN TWO PIPERUNS

a) Purpose
Use PIDAutoJoin to auto join two piperuns
b) Problem Statement
Write a standalone application to createa piperun in stockpile, then place this piperun from
stockpile into active drawing. Then place another piperun from middle of first piperun to have an
end open, then place a vessel with a nozzle, then place a new piperun connects nozzle and
second piperun, then use PIDAutoJoin to join second and third piperuns.
c) Solution
 Example code
Dim objPlacement As Placement
Set objPlacement = New Placement

Dim PipeRunLocation As String


Dim objItem As LMAItem
Dim objConnector As LMConnector
Dim objInputs As PlaceRunInputs
Dim objSymbol As LMSymbol
Dim VesselLocation As String
Dim NozzleLocation As String
Dim objPiperuns As LMPipeRuns
Dim objPiperun As LMPipeRun
Dim objSurvivorItem As LMAItem

Set objPiperuns = New LMPipeRuns

PipeRunLocation = "\Piping\Routing\Process Lines\Primary [Link]"

Set objInputs = New PlaceRunInputs


[Link] 0.1, 0.1
[Link] 0.2, 0.1

'first piperun
Set objItem = [Link](PipeRunLocation)
Set objConnector = [Link](objItem, objInputs)

Set objInputs = New PlaceRunInputs


[Link] 0.15, 0.1
[Link] 0.15, 0.3

'second piperun
Set objItem = [Link](PipeRunLocation)
Set objConnector = [Link](objItem, objInputs)
[Link] [Link]([Link])

VesselLocation = "\Equipment\Vessels\Vertical Drums\1D 1C [Link]"


NozzleLocation = "\Equipment Components\Nozzles\Flanged Nozzle with [Link]"

Set objSymbol = [Link](VesselLocation, 0.15, 0.5)

95
SmartPlant P&ID Automation Labs

Set objSymbol = [Link](NozzleLocation, 0.15, 0.5 - 0.1,


TargetItem:=[Link])

Set objInputs = New PlaceRunInputs


[Link] objConnector, 0.15, 0.3
[Link] objSymbol, [Link]("XCoordinate"),
[Link]("YCoordinate")

'third piperun
Set objItem = [Link](PipeRunLocation)
Set objConnector = [Link](objItem, objInputs)
[Link] [Link]([Link])

'AutoJoin
For Each objPiperun In objPiperuns
[Link] [Link], autoJoin_Both, objSurvivorItem
Next

MsgBox "Done!"
'clean up
Set objPlacement = Nothing
Set objItem = Nothing
Set objConnector = Nothing
Set objSymbol = Nothing
Set objInputs = Nothing

96
SmartPlant P&ID Automation Labs

73. PLACE GAP

a) Purpose
Use PIDPlaceGap method to place a Gap.
b) Problem Statement
Write a standalone application to place Connector, then place a Gap in the middle of the
connector
c) Solution
1. PIDPlaceGap returns a LMSymbol object, whose RepresentationType is “GAP”

 Example code
Dim objPlacement As Placement
Set objPlacement = New Placement

Dim PipeRunLocation As String


PipeRunLocation = "\Piping\Routing\Process Lines\Primary [Link]"

Dim twopoints(1 To 4) As Double


twopoints(1) = 0.2
twopoints(2) = 0.2
twopoints(3) = 0.4
twopoints(4) = 0.2

Dim objConnector As LMConnector


Set objConnector = [Link](PipeRunLocation, twopoints)

Dim gaplocation As String


gaplocation = "\Piping\Gaps\[Link]"
Dim objSymbol As LMSymbol
Set objSymbol = [Link](gaplocation, 0.3, 0.2, 0.02, 0.02, objConnector, -
1.57)

Set objConnector = Nothing


Set objSymbol = Nothing
Set objPlacement = Nothing

97
SmartPlant P&ID Automation Labs

74. PLACE BOUNDEDSHAPE

a) Purpose
Use PIDPlaceBoundedShape method to place a BoundedShape (AreaBreak).
b) Problem Statement
Write a standalone application to place a BoundedShape (AreaBreak) and a vessel with nozzle.
Add a vessel and assign it to be a part of the AreaBreak
c) Solution
1. PIDPlaceBoundedShape places a visual BoundedShape aroung the items rather than estbilish
the relationship between BoundedShape and items inside of it.

 Example code
Dim objPlacement As Placement
Set objPlacement = New Placement

Dim datasource As LMADataSource


Set datasource = [Link]

Dim VesselLocation As String


VesselLocation = "\Equipment\Vessels\Vertical Drums\1D 1C [Link]"

'place a vessel
Dim objSymbol1 As LMSymbol
Set objSymbol1 = [Link](VesselLocation, 0.25, 0.25)

'place a nozzle on the vessel


Dim NozzleLocation As String
NozzleLocation = "\Equipment Components\Nozzles\Flanged Nozzle with [Link]"
Dim objSymbol2 As LMSymbol
Set objSymbol2 = [Link](NozzleLocation, 0#, 0#, , , ,
[Link])

Dim points(1 To 10) As Double


points(1) = 0.1
points(2) = 0.1
points(3) = 0.4
points(4) = 0.1
points(5) = 0.4
points(6) = 0.4
points(7) = 0.1
points(8) = 0.4
points(9) = 0.1
points(10) = 0.1

'place BoundedShape(it is a AreaBreak)


Dim boundedshapelocation As String
boundedshapelocation = "\Design\Area [Link]"
Dim objBoundedShaped As LMBoundedShape
Set objBoundedShaped = [Link](boundedshapelocation,
points)

98
SmartPlant P&ID Automation Labs

'get the placed vessel


Dim objVessel As LMVessel
Set objVessel = [Link]([Link])

'get the BoundedShpae(AreaBreak) as PlantItemGroup


Dim objPlantItemGroup As LMPlantItemGroup
Set objPlantItemGroup = [Link]([Link])

[Link] "The vessel belongs to how many plantitemgroups? = " &


[Link]

'add the vessel to the PlantItemGroup


[Link] objPlantItemGroup
'[Link]
[Link] "The vessel belongs to how many plantitemgroups? = " &
[Link]

Set objPlacement = Nothing


Set datasource = Nothing

99
SmartPlant P&ID Automation Labs

75. PLACE ASSEMBLY

a) Purpose
Use PIDPlaceAssembly method to place assembly into drawing
b) Problem Statement
Create an assembly using the SmartPlant P&ID modeler. Write a standalone application to place
an assembly into drawing.
c) Solution
If the Assembly’s source is in a location that is not accessible, change the source to current
machine first
 Example code
Dim objPlacement As Placement
Set objPlacement = New Placement

Dim assemblylocation As String


assemblylocation = "\Assemblies\[Link]"

Dim objItems As LMAItems


'place assembly
Set objItems = [Link](assemblylocation, 0#, 0#)
If [Link] <> 0 Then
MsgBox "Place Assembly Completed"
End If

Set objPlacement = Nothing


Set objItems = Nothing

100
SmartPlant P&ID Automation Labs

76. DELETE VESSEL FROM DRAWING

a) Purpose
Use PIDRemovePlacement method to delete vessel from drawing
b) Problem Statement
Write a standard executable to delete vessel from the drawing.
c) Solution
 Open the SmartPlant P&ID drawing.
1. Create a drawing through SPManager.
2. Double-click on the drawing to open up SmartPlant P&ID
 Create a standard executable VB project
3. Select a standard exe project
4. Reference the “Logical Model Automation” and “Placement Automation” libraries
 Add code to delete the vessel from drawing
5. Use the Function PIDRemovePlacement(Representation As LMRepresentation) As
Boolean
6. The LMRepresentation argument must be a representation of the item on the drawing.
7. The boolean return value can be stored to determine success or failure.
 Example code
Dim objPlacement As Placement
Set objPlacement = New Placement

Dim objRep As LMRepresentation


Dim objVessel As LMVessel
Dim objSym As LMSymbol
Dim VesselLocation As String

VesselLocation = "\Equipment\Vessels\Horizontal Drums\Horz Surge w-Horiz [Link]"


'place a vessel into drawing
Set objSym = [Link](VesselLocation, 0.2, 0.2)

Set objVessel = [Link]([Link])


Set objRep = [Link](1)
'remove the vessel from drawing into stockpile
Dim success As Boolean
success = [Link](objRep)
If success Then
MsgBox "Symbol removed successfully"
Else
MsgBox "RemovePlacement unsuccessful"
End If

Set objPlacement = Nothing


Set objVessel = Nothing
Set objRep = Nothing

101
SmartPlant P&ID Automation Labs

77. DELETE VESSEL FROM MODEL

a) Purpose
Use PIDDeleteItem method to delete vessal from the project
b) Problem Statement
Write a standard executable to delete a vessel from project.
c) Solution
 Open the SmartPlant P&ID drawing.
8. Create a drawing through SPManager.
9. Double-click on the drawing to open up SmartPlant P&ID
 Create a standard executable VB project
10. Select a standard exe project
11. Reference the “Logical Model Automation” and “Placement Automation” libraries
 Add code to delete the vessel from model
12. Use the Function PIDDeleteItem(Item As LMAItem) As Boolean to remove from model
13. The LMRepresentation argument must be a representation of the item on the drawing.
14. The boolean return value can be stored to determine success or failure.

 Example code
Dim objPlacement As Placement
Set objPlacement = New Placement

Dim objItem As LMAItem


Dim success As Boolean
Dim objSym As LMSymbol
Dim VesselLocation As String

VesselLocation = "\Equipment\Vessels\Horizontal Drums\Horz Surge w-Horiz [Link]"


'place a vessel into drawing
Set objSym = [Link](VesselLocation, 0.2, 0.2)

Set objItem = [Link]([Link]).AsLMAItem


success = False
success = [Link](objItem)
If success Then
MsgBox "deletion from drawing successfully"
Else
MsgBox "deletion from drawing unsuccessful"
End If

Dim item As LMAItem


Set item = [Link](VesselLocation)
Set objItem = [Link]([Link]).AsLMAItem
success = False
success = [Link](objItem)
If success Then
MsgBox "deletion from stockpile successfully"

Else

102
SmartPlant P&ID Automation Labs

MsgBox "deletion from stockpile unsuccessful"


End If

Set objPlacement = Nothing


Set objItem = Nothing

103
SmartPlant P&ID Automation Labs

78. REPLACE SYMBOL

a) Purpose
Use PIDRePlaceSymbol method to replace a vessel.
b) Problem Statement
Write a standalone application to place a vessel with a nozzle on it. Replace the vessel with
different vessel. Note that the vessel is replaced and the nozzle is now on the new vessel.
c) Solution
 Example code
Dim objPlacement As Placement
Set objPlacement = New Placement

Dim VesselLocation As String


VesselLocation = "\Equipment\Vessels\Vertical Drums\1D 1C [Link]"
'place a vessel
Dim objSymbol1 As LMSymbol
Set objSymbol1 = [Link](VesselLocation, 0.2, 0.2)

Dim NozzleLocation As String


NozzleLocation = "\Equipment Components\Nozzles\Flanged Nozzle with [Link]"
'place a nozzle on the vessel
Dim objSymbol2 As LMSymbol
Set objSymbol2 = [Link](NozzleLocation, 0.3, 0.2, , , ,
[Link])

'replace the vessel, note nozzle is still on the new vessel


Dim replacevesselname As String
replacevesselname = "\Equipment\Vessels\Vertical Drums\2to1Parametric V [Link]"

Dim objSymbol3 As LMSymbol


Set objSymbol3 = [Link](replacevesselname, objSymbol1)

Set objSymbol1 = Nothing


Set objSymbol2 = Nothing
Set objSymbol3 = Nothing
Set objPlacement = Nothing

104
SmartPlant P&ID Automation Labs

79. REPLACE LABEL

a) Purpose
Use PIDRePlaceLabel method to replace a label.
b) Problem Statement
Write a standalone application to place a vessel with a nozzle on it, then replace the vessel with
different vessel. Note vessel is replaced with nozzle now is sitting on the new vessel.
c) Solution
 Example code
Dim objPlacement As Placement
Set objPlacement = New Placement

Dim VesselLocation As String


VesselLocation = "\Equipment\Vessels\Vertical Drums\2to1Parametric V [Link]"
'place a vessel
Dim objSymbol1 As LMSymbol
Set objSymbol1 = [Link](VesselLocation, 0.2, 0.2)

'get the vessel and set some properties' value


Dim objVessel As LMVessel
Set objVessel = [Link]([Link])
[Link]("Name").Value = "V1"
[Link]("TagPrefix").Value = "T"
[Link]

Dim labelName1 As String


labelName1 = "\Equipment\Labels - Equipment\Equipment [Link]"
Dim twopoints(1 To 4) As Double
twopoints(1) = 0.21
twopoints(2) = 0.25
twopoints(3) = 0.1
twopoints(4) = 0.1

'place a label on the vessel


Dim objLabelPersist1 As LMLabelPersist
Set objLabelPersist1 = [Link](labelName1, twopoints, , ,
[Link], True)

Dim replacelabelname As String


replacelabelname = "\Equipment\Labels - Equipment\Equipment [Link]"

'replace the label with new label


Dim objLabelPersist2 As LMLabelPersist
Set objLabelPersist2 = [Link](replacelabelname, objLabelPersist1)

Set objSymbol1 = Nothing


Set objLabelPersist1 = Nothing
Set objLabelPersist2 = Nothing
Set objPlacement = Nothing

105
SmartPlant P&ID Automation Labs

80. REPLACE OPC

a) Purpose
Use PIDRePlaceOPC method to replace an OPC.
b) Problem Statement
Write a standalone application to replace an OPC on draiwng.
c) Solution
** PIDRePlaceOPC Not Working Now, using PIDReplaceSymbol instead
 Example code
Dim objPlacement As Placement
Set objPlacement = New Placement

Dim OPClocation As String


OPClocation = "\Piping\Piping OPC's\[Link]"

Dim objOPC As LMOPC

Set objOPC =
[Link]("28B79FF6B52047DB98600BE313648290")

Dim objSymbol As LMSymbol


Set objSymbol =
[Link]([Link](1).ID)

Dim objSymbol1 As LMSymbol


Set objSymbol1 = [Link](OPClocation, objSymbol)

Set objSymbol = Nothing


Set objSymbol1 = Nothing
Set objOPC = Nothing
Set objPlacement = Nothing

106
SmartPlant P&ID Automation Labs

81. MODIFY PARAMETRICSYMBOL

a) Purpose
Use PIDApplyParameters method to modifty a Parametric Symbol
b) Problem Statement
Write a standalone application to place a parametric vessel symbol, and place a nozzle on it.
Then, Modifies the parameters of the vessel.
c) Solution
1. Names() are the Variables defined in Catalog Manager for the parametric symbol

 Example code
Dim objPlacement As Placement
Set objPlacement = New Placement

Dim VesselLocation As String


VesselLocation = "\Equipment\Vessels\Vertical Drums\2to1Parametric V [Link]"
Dim objSymbol1 As LMSymbol
Set objSymbol1 = [Link](VesselLocation, 0.2, 0.2, True, 1.57)

Dim NozzleLocation As String


NozzleLocation = "\Equipment Components\Nozzles\Flanged Nozzle with [Link]"
Dim objSymbol2 As LMSymbol
Set objSymbol2 = [Link](NozzleLocation, 0.22, 0.4, , , ,
[Link])

Dim names(1 To 2) As String


Dim values(1 To 2) As String
names(1) = "Top"
names(2) = "Right"
values(1) = "0.38"
values(2) = "0.2"

[Link] [Link], names, values

Set objSymbol1 = Nothing


Set objSymbol2 = Nothing
Set objPlacement = Nothing

107
SmartPlant P&ID Automation Labs

82. LOCATE X, Y COORDINATES OF SIGNAL POINTS ON AN


INSTRUMENT

a) Purpose
Using PIDConnectPointLocation to locate X, Y coordinates of signal points on an instrument.
b) Problem Statement
Place an off-line instrument, connect a signal line to signal point on the instrument with index as
3.
c) Solution
Using PIDConnectPointLocation to find out X, Y coordinates first.
 Example code
Dim objPlacement As Placement
Set objPlacement = New Placement

Dim SignalRunLocation As String


Dim objItem As LMAItem
Dim objConnector As LMConnector
Dim objInputs As PlaceRunInputs
Dim objSymbol As LMSymbol
Dim InstrLocation As String
Dim blnSuccess As Boolean
Dim X As Double, Y As Double

SignalRunLocation = "\Instrumentation\Signal Line\Electric [Link]"

InstrLocation = "\Instrumentation\Off-Line\With Implied Components\Level\Discr Field Mounted


[Link]"
Set objSymbol = [Link](InstrLocation, 0.3, 0.3)

blnSuccess = [Link](objSymbol, 3, X, Y)

Set objInputs = New PlaceRunInputs


[Link] 0.2, 0.3
[Link] objSymbol, X, Y

Set objItem = [Link](SignalRunLocation)


Set objConnector = [Link](objItem, objInputs)

'clean up
Set objPlacement = Nothing
Set objItem = Nothing
Set objConnector = Nothing
Set objSymbol = Nothing
Set objInputs = Nothing

108
SmartPlant P&ID Automation Labs

83. PLACE INSTRUMENT LOOP

a) Purpose
Use PIDCreateItem method to place an Instrument Loop in stockpile.
b) Problem Statement
Write a standalone application to place an Instrument Loop in stockpile and place a Piperun into
drawing, then associate the Instrument Loop with the Piperun.
c) Solution
1. Known problem, the association won’t be successful.
 Example code
Dim objPlacement As Placement
Set objPlacement = New Placement

Dim datasource As LMADataSource


Set datasource = [Link]
Dim InstrumentLocation As String
InstrumentLocation = "\Instrumentation\Off-Line\With Implied Components\Pressure\Discr Field
Mounted [Link]"
Dim objInstrSym As LMSymbol
Set objInstrSym = [Link](InstrumentLocation, 0.2, 0.2)

'get the placed instrument


Dim objInstr As LMInstrument
Set objInstr = [Link]([Link])

'place an InstrLoop into stockpile


Dim InstrLoopLocation As String
InstrLoopLocation = "\Instrumentation\Loops\Pressure [Link]"
Dim objItem As LMAItem
Set objItem = [Link](InstrLoopLocation)

Dim objInstrLoop As LMInstrLoop


Set objInstrLoop = [Link]([Link])
[Link]("TagSuffix").Value = "P"
[Link]

Set objInstrLoop = [Link]([Link])


[Link] [Link]("ItemTag").Value

[Link] "The instrument belongs to how many plantitemgroups? = " &


[Link]
[Link] [Link]
[Link]
[Link] "The instrument belongs to how many plantitemgroups? = " &
[Link]

Set objPlacement = Nothing


Set datasource = Nothing
Set objItem = Nothing
Set objInstrLoop = Nothing

109
SmartPlant P&ID Automation Labs

84. FIND AND REPLACE LABELS

a) Purpose
Comprehensive lab to practice filter for labels, and delete existing labels, then place new labels at
the same X, Y Coordinates.
b) Problem Statement
Get collection of labels in the database, then loop through each label, and delete "\Piping\
Segment Breaks\Construction [Link]" label, and place a new "\Piping\Segment
Breaks\Construction [Link]" label at the same X, Y Coordinate.
c) Solution
 Example code
Dim objPlacement As [Link]
Dim datasource As LMADataSource
Dim objFilter As LMAFilter
Dim objLabelPersists As LMLabelPersists
Dim objLabelPersist As LMLabelPersist
Dim objNewLabelPersist As LMLabelPersist
Dim X As Double, Y As Double
Dim objNewLabel As LMLabelPersist
Dim strFileName As String
Dim Points(1 To 4) As Double
Dim blnSuccess As Boolean
Dim strOLDFileName As String

Set objPlacement = New [Link]


Set datasource = [Link]

Set objFilter = New LMAFilter

[Link] ("FirstOne")
[Link]("FirstOne").SourceAttributeName = "ItemStatus"
[Link]("FirstOne").ValueAttribute = 1
[Link]("FirstOne").Operator = "="
[Link] = "Vessel"

[Link] ("SecondOne")
[Link]("SecondOne").SourceAttributeName = "SP_DrawingID"
[Link]("SecondOne").ValueAttribute =
[Link]
[Link]("SecondOne").Operator = "="
[Link]("SecondOne").Conjunctive = True

[Link] = "LabelPersist"

Set objLabelPersists = New LMLabelPersists

[Link] datasource, Filter:=objFilter

strOLDFileName = "\Piping\Segment Breaks\Construction [Link]"

110
SmartPlant P&ID Automation Labs

strFileName = "\Piping\Segment Breaks\Construction [Link]"


For Each objLabelPersist In objLabelPersists
If [Link]([Link]("FileName").Value, strOLDFileName,
vbTextCompare) = 0 Then
Points(1) = [Link](1).Attributes("XCoordinate").Value
Points(2) = [Link](1).Attributes("YCoordinate").Value
Points(3) = [Link]("XCoordinate").Value
Points(4) = [Link]("YCoordinate").Value
blnSuccess = False
blnSuccess = [Link]([Link])
If blnSuccess Then
Set objNewLabel = [Link](strFileName, Points,
IsLeaderVisible:=True)
End If
End If
Next

MsgBox "Done!"

Set objFilter = Nothing


Set objNewLabel = Nothing
Set objLabelPersist = Nothing
Set objLabelPersists = Nothing
Set datasource = Nothing
Set objPlacement = Nothing

111
SmartPlant P&ID Automation Labs

85. OPEN AND CLOSE AN EXISTING DRAWING

a) Purpose
Using PIDAutomation to open and close an existing drawing.
b) Problem Statement
Get collection of all drawings in the database, then loop through each drawing, open and close
each drawing.
c) Solution
 Example code
Dim datasource As LMADataSource
Dim objPIDAutoApp As [Link]
Dim objPIDADrawing As [Link]
Dim objDrawing As LMDrawing
Dim objDrawings As LMDrawings

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If

Set objDrawings = New LMDrawings


[Link] datasource

Set objPIDAutoApp = CreateObject("[Link]")

For Each objDrawing In objDrawings


If [Link]("ItemStatus").Index = 1 Then '1 stands for Active
Set objPIDADrawing =
[Link]([Link]("Name"))
If Not objPIDADrawing Is Nothing Then
MsgBox "Drawing " & [Link]("Name").Value & " is opened!"
[Link] True
End If
End If
Next

[Link]
Set objPIDAutoApp = Nothing
Set objPIDADrawing = Nothing
Set objDrawing = Nothing
Set objDrawings = Nothing

112
SmartPlant P&ID Automation Labs

86. CREATE , OPEN AND CLOSE A NEW DRAWING

a) Purpose
Using PIDAutomation to create, open and close a new drawing.
b) Problem Statement
Create, open and close a new drawing until one of your Units.
c) Solution
 Example code
Dim datasource As LMADataSource
Dim objPIDAutoApp As [Link]
Dim objPIDADrawing As [Link]
Dim PlantGroupName As String
Dim TemplateFileName As String
Dim DrawingNumber As String
Dim DrawingName As String

If Not blnUsePIDDatasource Then


Set datasource = New LMADataSource
Else
Set datasource = PIDDataSource
End If

Set objPIDAutoApp = CreateObject("[Link]")

PlantGroupName = "Unit01"
'considering accessing T_OptinSetting to read the template files path, which will be more
flexible
TemplateFileName = "\\blin\hostsite\lin_plant4\P&ID Reference Data\template files\[Link]"
DrawingNumber = "TestCreateNewDrawing1"
DrawingName = "TestCreateNewDrawing1"
Set objPIDADrawing = [Link](PlantGroupName, TemplateFileName,
DrawingNumber, DrawingName)
If Not objPIDADrawing Is Nothing Then
MsgBox "Drawing " & [Link] & " is opened!"
[Link] True
End If

[Link]
Set objPIDAutoApp = Nothing
Set objPIDADrawing = Nothing

113
SmartPlant P&ID Automation Labs

87. COMPREHENSIVE AUTOMATION LAB

a) Purpose
To practice a comprehensive auatomation lab, including LLAMA, Placement and PIDAutomation.
b) Problem Statement
Write a standalone application to create a new drawing, then place an assembly into the drawing,
then modify the piperuns placed by the assembly, set TagSequenceNo to 100. Then, close the
drawing.
c) Solution
 Example code
Dim datasource As LMADataSource
Dim objPIDAutoApp As [Link]
Dim objPIDADrawing As [Link]
Dim PlantGroupName As String
Dim TemplateFileName As String
Dim DrawingNumber As String
Dim DrawingName As String
Dim objPlacement As Placement
Dim AssemblyLocation As String
Dim objItems As LMAItems
Dim objItem As LMAItem
Dim objConnector As LMConnector
Dim objPiperun As LMPipeRun

Set objPIDAutoApp = CreateObject("[Link]")

PlantGroupName = "Unit01"
'considering accessing T_OptinSetting to read the template files path, which will be more
flexible
TemplateFileName = "\\blin\hostsite\lin_plant3\P&ID Reference Data\template files\[Link]"
DrawingNumber = "TestCreateNewDrawing2"
DrawingName = "TestCreateNewDrawing2"
Set objPIDADrawing = [Link](PlantGroupName, TemplateFileName,
DrawingNumber, DrawingName)
If Not objPIDADrawing Is Nothing Then
Set objPlacement = New Placement
Set datasource = [Link]
AssemblyLocation = "\Assemblies\[Link]"
'place assembly
Set objItems = [Link](AssemblyLocation, 0.2, 0.2)
'change TagSequenceNo
For Each objItem In objItems
If [Link] = "Connector" Then
Set objConnector = [Link]([Link])
If [Link] = "PipeRun" Then
Set objPiperun = [Link]([Link])
[Link]("TagSequenceNo").Value = 100
[Link]
End If
End If

114
SmartPlant P&ID Automation Labs

Next
[Link] True
End If

[Link]
Set objPIDAutoApp = Nothing
Set objPIDADrawing = Nothing

115
SmartPlant P&ID Automation Labs

88. CREATE A CALCULATION PROGRAM

a) Purpose
Enable the Calculation button at the customized property “XYCoordinates” at ModelItem level to
show X, Y coordinates of the symbol in format of X/Y.
b) Problem Statement
Write an Active-X dll implementing the DoCalculate method to read the X, Y coordinates of a
Symbol to the customized property ““XYCoordinates” at ModelItem level. The customized
property ““XYCoordinates” should be added at ModelItem level, with datatype is String, format is
Variable Length, Maximum Length is 40, and Category is Accessories.
c) Solution
 Example code
Implements ILMForeignCalc

Private Function ILMForeignCalc_DoCalculate(datasource As [Link], _


items As [Link], PropertyName As String, Value As Variant) As Boolean

ILMForeignCalc_DoCalculate = ShowXYCoordinates(datasource, items, Value,


PropertyName)

End Function

Private Function ShowXYCoordinates(datasource As [Link], _


items As [Link], Value As Variant, PropertyName As String) As Boolean

Dim Item As LMAItem


Dim objSymbol As LMSymbol
Dim objEquipment As LMEquipment

'check if the selected Property is "XYCoordinates", then copy value from X, Y coordinates
'to it

ShowXYCoordinates = False
For Each Item In items
If PropertyName = "XYCoordinates" Then
On Error Resume Next
Set objEquipment = [Link]([Link])
On Error GoTo 0
If Not objEquipment Is Nothing Then
Set objSymbol =
[Link]([Link]([Link]).[Link](1).Id)
Value = [Link]("XCoordinate").Value & "/" &
[Link]("YCoordinate").Value
End If
End If
Next
ShowXYCoordinates = True

'clean up

116
SmartPlant P&ID Automation Labs

Set Item = Nothing


Set objSymbol = Nothing
Set objEquipment = Nothing
End Function

Save the Project and enter the ProgID in the Calculation ID field of the XYCoordinates Attribute in
ModelItem through the DataDictionary Manager. Restart SPPID to find the button. Start the
Project in Debug mode and then click on the button to step through your code. Then, compile the
project, and click on the button again.

117
SmartPlant P&ID Automation Labs

89. CREATE A VALIDATEPROPERTY PROGRAM

a) Purpose
Enable the Property validation at the ActuatorType attribute of InlineComp
b) Problem Statement
Write an Active-X dll implementing the DoValidateProperty method for placing corresponding
actuator for an instrument valve when property ActuatorType is entered or changed.
c) Solution
 Example code
Implements ILMForeignCalc

Private Function ILMForeignCalc_DoValidateProperty(datasource As [Link], _


items As [Link], PropertyName As String, Value As Variant) As Boolean

ILMForeignCalc_DoValidateProperty = AddActuator(datasource, items, PropertyName, Value)

End Function

'add actuator when property actuator type is changed on instrument


Private Function AddActuator(datasource As [Link], _
items As [Link], PropertyName As String, Value As Variant) As Boolean
'
On Error GoTo ErrHandler
'
Dim Item As LMAItem
Dim objPlacement As Placement
Dim strFilePath As String
Dim x As Double
Dim y As Double
Dim objSym As LMSymbol
Dim objSymbol As LMSymbol

Dim objInstr As LMInstrument


Dim objPlantItem As LMPlantItem
Dim objInstrActuator As LMInstrument
Dim blnDelete As Boolean
Dim blnNeedAdd As Boolean

Set objPlacement = New Placement


AddActuator = False
For Each Item In items
If [Link] = "Instrument" And PropertyName = "ActuatorType" Then
If [Link]("InstrumentClass").Value = "Control valves and regulators" Then
'get the instrument
Set objInstr = [Link]([Link])
If [Link] = 0 Then
blnNeedAdd = True
Else

118
SmartPlant P&ID Automation Labs

If [Link] = 1 Then
blnDelete =
[Link]([Link](1).AsLMAItem)
blnNeedAdd = True
Else
MsgBox "Wrong, there are more than 1 Child for this instrument!"
End If
End If
If blnNeedAdd Then
Select Case Value
Case "Diaphragm"
strFilePath = "\Instrumentation\Actuators\Diaph [Link]"
Case "Single acting cylinder"
strFilePath = "\Instrumentation\Actuators\Single Action Cyl [Link]"
Case "Pilot operated cylinder"
strFilePath = "\Instrumentation\Actuators\Pilot Operated Cyl [Link]"
Case "Motor"
strFilePath = "\Instrumentation\Actuators\Motor [Link]"
Case "Digital"
strFilePath = "\Instrumentation\Actuators\Digital [Link]"
Case "Electro-hydraulic"
strFilePath = "\Instrumentation\Actuators\Electric-Hydraulic [Link]"
Case "Single solenoid"
strFilePath = "\Instrumentation\Actuators\Solenoid [Link]"
Case "Single solenoid w/reset"
strFilePath = "\Instrumentation\Actuators\Solenoid Act w-Man [Link]"
Case "Double solenoid"
strFilePath = "\Instrumentation\Actuators\Double Solenoid [Link]"
Case "Pilot"
strFilePath = "\Instrumentation\Actuators\Pilot [Link]"
Case "Weight"
strFilePath = "\Instrumentation\Actuators\Weight [Link]"
Case "Manual"
strFilePath = "\Instrumentation\Actuators\Manual [Link]"
Case "Spring"
strFilePath = "\Instrumentation\Actuators\Spring [Link]"
Case "Capacitance sensor"
strFilePath = "\Instrumentation\Actuators\Capacitance Sensor [Link]"
Case "Ball float"
strFilePath = "\Instrumentation\Actuators\Ball Float [Link]"
Case "Displacement float"
strFilePath = "\Instrumentation\Actuators\Displacement Float [Link]"
Case "Paddle wheel"
strFilePath = "\Instrumentation\Actuators\Paddle Wheel [Link]"
Case "Diaphragm Rotary Actuator"
strFilePath = "\Instrumentation\Actuators\Diaph [Link]"
Set objSym = [Link]([Link](1).Id)
x = [Link]
y = [Link]
Case Else
'do nothing
strFilePath = ""
End Select

If strFilePath <> "" Then


Set objSym = [Link]([Link](1).Id)

119
SmartPlant P&ID Automation Labs

x = [Link]("XCoordinate")
y = [Link]("YCoordinate")
Set objSymbol = [Link](strFilePath, x, y) '
targetitem:=[Link])
Else
MsgBox "Couldn't find corresponding Actuator"
End If
End If
AddActuator = True
End If
End If

Next

'clean up
Set objPlacement = Nothing
Set Item = Nothing
Set objSym = Nothing
Set objSymbol = Nothing
Set objInstr = Nothing
Set objPlantItem = Nothing
Set objInstrActuator = Nothing

Exit Function
ErrHandler:
MsgBox "Error happened: " & [Link]
'clean up
Set objPlacement = Nothing
Set Item = Nothing
Set objSym = Nothing
Set objSymbol = Nothing
Set objInstr = Nothing
Set objPlantItem = Nothing
Set objInstrActuator = Nothing
End Function

Save the Project and enter the ProgID in the Validation ID field of the ActuatorType Attribute in
InlineComp through the DataDictionary Manager. Restart SPPID. Start the Project in Debug
mode and then select different Actuators through ActuatorType property to step through your
code. Then, compile the Project, and change the property again.

120
SmartPlant P&ID Automation Labs

90. CREATE A VALIDATEITEM PROGRAM

a) Purpose
Enable the Item validation when placing PipeRun.
b) Problem Statement
User added a new property “SystemCode” for Drawing, user want this property value to be copied
to new Piperuns when placing them. Write an Active-X dll implementing the DoValidateItem
method when placing PipeRun to make the copy from Drawing to PipeRun. You will notice a
problem the a ProgID has existed for the PipeRun, learning how to call another validation
program through your code.
c) Solution
 Example code
Implements ILMForeignCalc

Private Function ILMForeignCalc_DoValidateItem(DataSource As [Link], _


Items As [Link], Context As ENUM_LMAValidateContext) As Boolean

Dim PlantItemValidate As ILMForeignCalc

'Call [Link]
Set PlantItemValidate = CreateObject("[Link]")
If Not PlantItemValidate Is Nothing Then
ILMForeignCalc_DoValidateItem = [Link](DataSource, Items,
Context)
End If

'call function to place actuator


ILMForeignCalc_DoValidateItem = CopySystemCode(DataSource, Items, Context)

End Function

Private Function CopySystemCode(DataSource As [Link], _


Items As [Link], Context As ENUM_LMAValidateContext) As Boolean
Dim objLMAItem As LMAItem
Dim objDrawing As LMDrawing
Dim objModelItem As LMModelItem

If Context = LMAValidateCreate Then


For Each objLMAItem In Items
Set objModelItem = [Link]([Link])
Set objDrawing = [Link](1).DrawingObject
[Link]("SystemCode").Value =
[Link]("SystemCode").Value
[Link]
Next
End If
End Function

121
SmartPlant P&ID Automation Labs

Save the Project and enter the ProgID in the Validation Program field of the PipeRun through the
DataDictionary Manager – DataBase Item Types. Restart SPPID. Start the Project in Debug
mode and then place an PipeRun to step through your code. Then, compile the Project, and
place PipeRun again.

122
SmartPlant P&ID Automation Labs

OPTIONAL LABS

1. WRITE A SIMPLE VB CODE AND DEBUG IT

a) Purpose
To relate Visual Basic to procedural languages
b) Problem Statement
Create a “Hello World” program using the Sub main().
c) Solution
 Open a Standard Executable in Visual Basic
1. From the Start menu, click on Programs folder/Microsoft Visual Basic 6./Visual Basic 6.0.
2. Open a [Link] project.
3. Select the default form and delete it through Project\Remove Form1.
4. Add a Module to the project through Project\Add Module.
5. Set Project1 Properties show Sub Main as the start-up procedure. Select Project\Project
Properties to get the dialog box.
 Enter the following code:
Sub Main()
[Link] “Hello World”
Msgbox “Hello World”
End Sub
 Save all the files associated with the Project
 Step through the program in Debug mode
 Compile and run the program

2. WRITE A SIMPLE VB CODE USING A FORM

a) Purpose
To introduce the object-oriented features of Visual Basic
b) Problem Statement
Create a “Hello World” program using Form-level code.
c) Solution
 Open a Standard Executable in Visual Basic
[Link] the Start menu, click on Programs folder/Microsoft Visual Basic 6./Visual Basic 6.0.
[Link] a [Link] project.
[Link] Command button on the default form.

123
SmartPlant P&ID Automation Labs

[Link]-click the Command button to simulate the click Event and open the definition for the
Click Event.
 Enter the following code:
Private Sub Command1_Click()
MsgBox "Hello World"
End Sub
 Save all the files associated with the Project
 Step through the program in Debug mode
 Compile and run the program
 Change the caption and name of the Command button and repeat the exercise

3. USE THE OBJECT BROWSER TO VIEW AUTOMATION OBJECTS

a) Purpose
To become familiar with looking up libraries in Visual Basic

b) Problem Statement
Use the Object Browser to examine the classes, methods, and properties of the Microsoft Excel
library and the SmartPlant P&ID library.
c) Solution
 Open a Standard Executable in Visual Basic
5. From the Start menu, click on Programs folder/Microsoft Visual Basic 6./Visual Basic 6.0.
6. Open a [Link] project.

 Reference Microsoft Excel into the Project


7. From the Project/References, select Microsoft Excel 8.0 Object Library

 Browse the Microsoft Excel library using the Object Browser


8. Click on the Object Browser icon and select Excel in the pull down list.
9. Click on each class on the left hand side to view its methods and properties on the right.
10. Click on each method or property for more information on them.

 Reference Llama into the Project


11. From the Project/References, select Intergraph SmartPlant P&ID Logical Model
Automation

 Browse the Llama library using the Object Browser

124
SmartPlant P&ID Automation Labs

4. WRITE VB CLIENT APPLICATION TO ACCESS MICROSOFT EXCEL’S


AUTOMATION OBJECTS

a) Purpose
To practice writing an Active-X client component to access an Active-X servernents
b) Problem Statement
Write an Active-X client executable to interact with Microsoft Excel and perform the following
operations:
Create a workbook and assign a value to a range of cells and save the workbook. Re-open the
workbook and examine the contents of the cells.
(Note: Excel Application contains Workbooks which contain Worksheets. Each Worksheet
contains Ranges, which contain Columns and Rows.)
c) Solution
 Open a Standard Executable in Visual Basic
1. From the Start menu, click on Programs folder/Microsoft Visual Basic 6./Visual Basic 6.0.
2. Open a [Link] project.
3. Create a Reference to the Excel object library
 Add code to start up Excel Application and make it visible
4. Use the CreateObject method to create an instance of [Link]
5. Make Excel Application visible by setting the boolean ‘Visible’ property to True
6. Examine the Excel instance visually. The Application may not have any open workbooks.
 Expand code to Add a new workbook
7. Use the ‘Add’ method in the Workbooks object in Excel to add a workbook.
8. Create an object variable to point to the new workbook.
9. Examine the Excel instance visually. The Workbook comes with 3 worksheets.
 Expand code to select a range in a worksheet
10. Use the Worksheets method in the Workbook object and set a variable pointing to
“Sheet1”.
11. Create a range in Sheet1 covering A1 to E10 using the ‘range’ method of the Worksheet
object and set a variable pointing to it.
 Include code to set a value in the range
12. Use the methods in the Range object and print out the number of columns and rows in
the range.
13. Use the ‘Value’ property of the Range object and assign a value to every cell in the
range.
14. Examine the Excel Application visually.
 Save and close the workbook
15. Use the SaveAs method of the workbook to save the file. Give a filename as argument.
16. Use Close method to close the workbook.
17. Examine the Excel Application visually.
 Re-open the Excel Workbook and examine the cells
18. Use the Open method in the Workbooks object of ExcelApplication.
19. Select the Workbook from the Workbooks collection by name and assign a variable to it.
20. Select Sheet1 from the Worksheets and examine the ‘Value’ of cell (10, 5) using the Cells
property.
 Example Code
Dim objExcel As [Link]

125
SmartPlant P&ID Automation Labs

Set objExcel = CreateObject("[Link]")


[Link] = True

Dim xlWorkbook As [Link]


Set xlWorkbook = [Link]

Dim xlWorksheet As [Link]


Set xlWorksheet = [Link]("SHEET1")

Dim range As range


Set range = [Link]("A1", "E10")
[Link] = 10

Dim strFileName As String


strFileName = Environ("TEMP") & "\[Link]"

[Link](1).SaveAs (strFileName)
[Link](1).Close

[Link] (strFileName)
Set xlWorkbook = [Link]("[Link]")
[Link] [Link]

Set xlWorksheet = [Link]("SHEET1")


[Link] [Link]
[Link] [Link](10, 5)

[Link] True
[Link]

Set xlWorksheet = Nothing


Set xlWorkbook = Nothing
Set objExcel = Nothing

126
SmartPlant P&ID Automation Labs

5. CREATE AN ACTIVE-X SERVER AND A CLIENT APPLICATION

a) Purpose
To practice writing an Active-X server component that can be accessed by a client application
b) Problem Statement
Write an Active-X server in Visual Basic containing a class called Customer.
Provide the Customer class with Name, Address, and Age properties. Create Property
procedures to set and get the values of these properties.
In the Age property, ensure that no age less than zero (0) can be assigned. The Age property
should use a default value of zero in such cases.
Create a Sub called Display to display the whole Name, Address, and Age of the customer in a
single message box.
c) Solution
 Open a Active-X DLL in Visual Basic
1. From the Start menu, click on Programs folder/Microsoft Visual Basic 6./Visual Basic 6.0.
2. Open a Active-X DLL project.
 Create a Class Module
12. Select Project\Add Class Module
13. Rename the Class Module to “Customer”
14. Dimension three private variables: strName as string, strAddress as string, intAge as
integer
15. Create three Property procedures with Get and Let definitions: Name, Address, Age.
16. In the Let procedure for the Age property, include an IF structure to ensure that the age is
never negative.
17. Create Sub called Display () that will concatenate the Name, Address and Age properties
and displays it in a message box. [Use Msgbox (…) to display]
 Create a executable application reference the Active-X DLL
18. Create a executable application reference the Active-X DLL
19. Create a form in the executable application
20. Create a command on the form and double click it to enter code into its click event.
21. Dimension and create three instances of the Customer class. Use the Name, Address,
and Age properties to input data into the object. Use the Display subroutine to display
the combined information.

 Example Code
Sample code in Class Customer:

Dim strname As String


Dim strAddress As String
Dim intAge As Integer
Public Property Get name() As String
name = strname
End Property
Public Property Let name(vdata As String)
strname = vdata
End Property

Public Property Get Address() As String

127
SmartPlant P&ID Automation Labs

Address = strAddress
End Property

Public Property Let Address(ByVal vNewValue As String)


strAddress = vNewValue
End Property

Public Property Get Age() As Integer


Age = intAge
End Property

Public Property Let Age(ByVal vNewValue As Integer)


If vNewValue >= 0 Then
intAge = vNewValue
End If
End Property
Public Sub Display()
MsgBox "Name=" & strname & " Address=" & strAddress & " Age=" & intAge
End Sub

Sample code in Client application:

Dim obj1 As Customer


Dim obj2 As Customer
Dim obj3 As Customer

Set obj1 = New Customer


Set obj2 = obj1
Set obj3 = New Customer

[Link] = "309 Ball St., College Station, TX"


[Link] = "Tom"
[Link] = 20

[Link] = "Dave"
[Link] = "David"
[Link] = -100

[Link] [Link]
[Link] [Link]
[Link] [Link]

[Link]
[Link]
[Link]

Set obj1 = Nothing


Set obj2 = Nothing
Set obj3 = Nothing

128
SmartPlant P&ID Automation Labs

6. CREATE AN INTERFACE, AN IMPLEMENTATION, AND A CLIENT


APPLICATION

a) Purpose
To practice writing Active-X server components which support interfaces
b) Problem Statement
Create an Active-X interface, its implementation, and a client driver program to use the two
libraries.
c) Solution
 Create the Interface Project
1. Create an Active-X dll project called Interface.
2. Create two class modules and name them IAccount and IPurchase.
22. IAccount has one function AccountBalance and IPurchase has one function
LastPurchaseAmount, each returning a double datatype.
23. Save the project and run it.
 Create a project called Implementation with a single class called CreditCard
24. Create an Active-X dll project called Implementation.
25. Reference the Interface dll.
26. Open the class module and name it CreditCard.
27. Implement the two interfaces in the class.
28. Create two private variables to hold the lastPurchaseAmount and the accountBalance.
29. Add a property called paymentAmount which reduces the account balance by the given
amount in the Let definition.
30. Add a second property called PurchaseAmount which increases the account balance by
the given amount and saves the given amount as the lastPurchaseAmount, in the Let
definition.
31. Implement the two functions from the interfaces to return the values of the two
appropriate variables.
 Create a project called Client with a Form
32. Create a standard executable project called Client.
33. Reference the two dlls created above.
34. Dimension one variable each for the three classes developed above.
35. Create a new creditcard object and assign it some payment and purchase using the
creditcard object’s properties.
36. Set the two interface variables to point to the creditcard object.
37. Print out the AccountBalance and LastPurchaseAmount using the two variables.
 Example Code
IAccount interface:
Public Function AccountBalance() As Double

End Function

IPurchase Interface:
Public Property Get LastPurchaseAmount() As Double

End Property

Implementation Class: CreditCard


Option Explicit

129
SmartPlant P&ID Automation Labs

Implements IAccount
Implements IPurchase

Private mvarLastPurchaseAmount As Double


Private mvarAccountBalance As Double

Private Function IAccount_AccountBalance() As Double


IAccount_AccountBalance = mvarAccountBalance
End Function

Private Property Get IPurchase_LastPurchaseAmount() As Double


IPurchase_LastPurchaseAmount = mvarLastPurchaseAmount
End Property

Public Property Let PurchaseAmount(vdata As Double)


mvarLastPurchaseAmount = vdata
mvarAccountBalance = mvarAccountBalance + vdata
End Property

Public Property Let paymentAmount(vdata As Double)


mvarAccountBalance = mvarAccountBalance - vdata
End Property

Public Function AddFinanceCharge(percent As Double) As Double


Dim interest As Double
interest = percent / 100# * mvarAccountBalance
mvarAccountBalance = mvarAccountBalance - interest
AddFinanceCharge = interest
End Function

Client Driver Program:


Private Sub Command1_Click()
Dim accountInterface As IAccount
Dim purchaseInterface As IPurchase

Dim creditCard As creditCard


Set creditCard = New creditCard
[Link] = 500.34
[Link] = 400#
Set accountInterface = creditCard
Set purchaseInterface = creditCard
[Link] [Link]
[Link] [Link]

[Link] 10.9
[Link] [Link]
[Link] [Link]

End Sub

130
SmartPlant P&ID Automation Labs

7. MODIFY PROPERTY BASED ON CONSTRUCTION STATUS

a) Purpose
Get familiar with LLAMA
b) Problem Statement
(1) Place two vessels, one with Construction Status = NEW, the other with Construction Status =
EXISTING
(2) Write an EXE to get two vessels, modify Description property to “New Construction Status” if
the Construction Status = NEW, and modify Description property to “Existing Construction Status”
if the Construction Status = EXISTING.
c) Solution
 Example code

8. SERACH ITEMS AND MODIFY PROPERTY

a) Purpose
Get familiar with LLAMA
b) Problem Statement
(1) Place some valves with different types, make sure some of them are Ball Valves
(2) Write an EXE to filter for Ball valves only, and set Nominal Diameter to 2” if the original value
is not set yet.
c) Solution
 Example code

9. MODIFY CASE PROCESS DATA

a) Purpose
Get familiar with LLAMA
b) Problem Statement
(1) Place a Vessel, assign some process data to the vassal, such as max operating pressure,
temperature, etc. When enter value for process data, intentionally some use default unit, some
not.
(2) Write an EXE to access this vessel, and change the process data’s display value to project
default format if not yet.
c) Solution
Example code

131
SmartPlant P&ID Automation Labs

10. FIND IMPLIED ITEMS AND MODIFY THEIR PROPERTY

a) Purpose
Get familiar with LLAMA
b) Problem Statement
(1) Place some off-line instruments with implied components
(2) Write an EXE to filter for implied items, check if it is an Instrument Root Valve, if so, set its
Nominal Diameter to 2”
c) Solution
 Example code

11. COUNT NOZZLES ON A VESSEL

a) Purpose
Get familiar with LLAMA
b) Problem Statement
(1) Place a vessel, and place several nozzles on it
(2) Write an EXE to count nozzles on the vessel, and set the vessel’s Description property value
to “Total number of nozzles on this vessel is: <the count of nozzles>”
c) Solution
 Example code

12. SEARCH ITEMS ACTIVE DRAWING STOCKPILE

a) Purpose
Get familiar with LLAMA
b) Problem Statement
(1) Place some vessels in the drawing, then remove some of them to drawing stockpile
(2) Write an EXE to filter for all vessels in drawing stockpile, and set the vessel’s Description
property value to “In drawing stockpile of the drawing: <DrawingName>”.
c) Solution
Example code

132
SmartPlant P&ID Automation Labs

13. NAVIGATE FROM OFF-LINE INSTRUMENT TO PROCESS PIPERUN

a) Purpose
Get familiar with LLAMA
b) Problem Statement
(1) Place an off-line instrument, connect the instrument to the process PipeRun with Connect-To-
Process line.
(2) Write an EXE to navigate from off-line instrument the process PipeRun, set instrument’s
Description property value to “Connected Process PipeRun’s Item tag is <Piperun ItemTag>.
c) Solution
Example code

14. FIND OPC AND FROM/TO

a) Purpose
Get familiar with LLAMA
b) Problem Statement
(1) place Vessel, with two nozzles on it and then draw a piperun from one of the nozzles and
place a OPC to the open end of the piperun, then open another drawing, place a vessel with two
nozzles on it, and then draw a piperun from one of the nozzles, and then place the pairedOPC to
the piperun,
(2) write a standalone application start from the vessel in first drawing, navigate from vessel, to
nozzle, to piperun, to OPC,
(3) continue the navigation, to pairedOPC (in other drawing), to piperun, to nozzle, and to the
vessel.
(4) place a valve on the piperun in first drawing, then repeat step (2) & (3)
(5) place a two more nozzles on the vessel in second drawing, place an off-line instrumentation
with implied components, such a Discr Field Mounted LC, then use SignalLine-Connect to
Process to link nozzle with Instrumentation, navigate from vessel in first drawing until find the
implied component (which is valve)
(6) continue the navigation from implied component to the vessel in second drawing
(7) change the property SupplyBy to “By A” for the vessel, nozzle, and piperun
(8) integrate this function to a validation code, which will be run when SupplyBy property of vessel
is changed. (due to the limitation of the code, you may start from the vessel in first drawing)

c) Solution
 Example code

133
SmartPlant P&ID Automation Labs

15. COPY A CUSTOMIZED PROPERTY OF UNIT TO PIPERUN

a) Purpose
Get familiar with LLAMA
b) Problem Statement
(1) Create a new property “AreaCode” at Unit, with datatype is String, format is Variable Length,
Maximum Length is 40, and Category is Accessories. Then place a Piperun.
(2) Write an EXE to set the Piperun’s Description’s property value to “Area Code is <AreaCode of
Unit>”.
c) Solution
 Example code

16. LABEL FIND AND REPLACE UTILITY

a) Purpose
To apply the knowledge you learned in this cource for both LLAMA and PLACEMENT
b) Problem Statement
Write a standalone application to obtain all Vessel on a drawing, then check if the EquipmentID
label is placed on the Vessel or not, if not, place the EquipmentID label to the Vessel, if the
EquipmentID label is placed already, replace the label. In this way, the latest EquipmentID label
will be placed on each Vessel.
c) Solution
1. Use LMAFilter to find all Vessels in current active drawing.
2. Use PIDPlaceLabel to place new label.
3. Use PIDReplaceLabel to replace existing label.
 Example code

17. AUTOMATICALLY CREATE NEW DRAWINGS

a) Purpose
To apply the knowledge you learned in this cource for LLAMA, PLACEMENT and PIDAutomation.
b) Problem Statement
Write a standalone application to create a new drawing, then place two assemblies into the new
drawing (assemblies are pre-defined, with one assembly has a piperun with one open end, and
the other assembly has an nozzle without any piperun connected). Then place a new Piperun to
connect the open end of the piperun to the nozzle, and use PIDAutoJoin method to auto join the
existing piperun and new placed piperun.

134
SmartPlant P&ID Automation Labs

c) Solution
 Example code

18. CALCULATION VALIDATION (1)

a) Purpose
Get familiar with Calculation Validation
b) Problem Statement
Write an Active-X dll implementing the DoCalculate method for creating a value for the Name of
Vessel. Ask user to enter the name they want to give to the vessel, then combine with SP_ID of
the vessel to obtain the final name of the vessel.
c) Solution
 Example code

19. CALCULATION VALIDATION (2)

a) Purpose
Get familiar with Calculation Validation
b) Problem Statement
Write an Active-X dll implementing the DoCalculate method for placing an assembly. Create a
new property called “Place Assembly” for PipingComp, placing an assembly when user click the
Calculation button on the “Place Assembly” field and the item type is “Valve”. Place the assembly
somewhere outside of the border.
c) Solution
 Example code

20. PROPERTY VALIDATION (1)

a) Purpose
Get familiar with Property Validation

135
SmartPlant P&ID Automation Labs

b) Problem Statement
Write an Active-X dll implementing the DoValidateProperty method for populating the value for
the Name of Vessel when user enter the value for TagPrefix of vessel. Vessel name is
combination of TagPrefix and SP_ID
c) Solution
 Example code

21. PROPERTY VALIDATION (2)

a) Purpose
Get familiar with Property Validation
b) Problem Statement
Write an Active-X dll implementing the DoValidateProperty method for populating the value for
the “Pressure Drop” of Relief Device, “Pressure Drop” is a new property for Relief Device, which
is difference of Oper Max Pressure between two piperuns connected to Relief Device. When one
of Oper Max Pressures is changed, Validation code should be fired and calculate the value for
the “Pressure Drop”
c) Solution
1. Some Relief Devices have more than two piperuns connected to them, select one with only two
piperuns connected.
 Example code

22. ITEM VALIDATION (1)

a) Purpose
Get familiar with Item Validation
b) Problem Statement
Write an Active-X dll implementing the DoValidateItem method for creating a value for the Name
of Vessel when a vessel is placed on drawing. Vessel name is combination of “T” and SP_ID
c) Solution
 Example code

136
SmartPlant P&ID Automation Labs

23. ITEM VALIDATION (2)

a) Purpose
Get familiar with Item Validation
b) Problem Statement
Write an Active-X dll implementing the DoValidateItem method to clean the OperFluidCode if the
line number label is deleted from the Piperun.
c) Solution
 Example code

24. ITEM VALIDATION (3)

a) Purpose
Get familiar with Item Validation
b) Problem Statement
Write an Active-X dll implementing the DoValidateItem method to write a log file with all
information about who/when place, delete, and modify items.
c) Solution
 Example code

25. MODIFY PLANTITEM VALIDATION

a) Purpose
Get familiar with PlantItem Validation Code.
b) Problem Statement
Modify the delivered PlantItem Validation code to keep the original tag sequence no when
copy/paste assembly.
c) Solution
 Example code

26. MODIFY ITEMTAG VALIDATION

a) Purpose
Get familiar with ItemTag Validation Code.

137
SmartPlant P&ID Automation Labs

b) Problem Statement
Modify the delivered ItemTag Validate code to allow ItemTag of PipeRun including
NominalDiameter.
c) Solution
 Example code

27. MODIFY IMPORT CODE

a) Purpose
Get familiar with Import Code.
b) Problem Statement
Modify the delivered Import code to allow import more properties for Equipment, new properties
such as “Height” of vessel, and/or a user defined property.
c) Solution
 Example code

28. NEW MOCRO FOR INSTRUMENT REPORT

a) Purpose
Create new macro to enhance the functionarity of Instrument Report.
b) Problem Statement
Write a macro for Instrument Report to obtain what items that connected the instrumentation
through “Connect to process” SignalRun.
c) Solution
1. “Connect to process” SignalRun is actually a special PipeRun, whose PipeRunType is "Conn to
process/supply"
2. You may limit your code to only report the items if they are PipeRun or Nozzle
 Example code

29. IMPROVEMENT OF FROM/TO MACRO

a) Purpose
To improve the functionality of From/To Macro

138
SmartPlant P&ID Automation Labs

b) Problem Statement
Modify the the From/To Macro to not reporting Branch Piperuns.
c) Solution
 Example code

139

Common questions

Powered by AI

When replacing a vessel using the PIDRePlaceSymbol method, components attached like nozzles are transferred onto the new vessel . This demonstrates the linked and dynamic nature of component associations within SmartPlant P&ID, ensuring that functional relationships between elements, such as vessels and nozzles, are maintained through replacements .

To place an Instrument Loop, use the PIDCreateItem with the InstrumentLoop location and get the object using GetInstrLoop method . Common challenges during association with a Piperun stem from known issues in the association process, often leading to failures despite correct syntax, portraying the complexity and interrelated nature of such associations in the system .

To modify properties of an object, such as a vessel, the LMADataSource.GetVessel method is used to obtain the object, and then specific properties, like 'Name', can be changed using the Attributes method . After modifying desired properties, one must use the LMVessel.Commit method to commit the changes to the database . It is essential to initiate a transaction using BeginTransaction before making changes, and finalize with CommitTransaction to ensure the changes are effectively saved .

You can access properties at different levels using LMADataSource.GetVessel and LMADataSource.GetEquipment methods . Changing the 'Name' property at the Equipment level, for example using Attributes property to update the value, affects the associated Vessel object's 'Name' property when re-accessed. This demonstrates a linkage in the property hierarchy where modification at a higher or related level propagates to associated objects .

To access a vessel using its SP_ID values, one must first dim an LMVessel object and retrieve the object using the LMADataSource.GetVessel method . Once the object is obtained, properties such as SP_ID, EquipmentSubClass, EquipmentType, aabbcc_code, Class, Item TypeName, volumeRating, and volumeRating in SI units can be printed using Debug.Print method .

To place a symbol, utilize the PIDPlaceSymbol method from a Placement object with parameters like DefinitionFile string for the symbol location, X and Y coordinates for positioning, and optional parameters such as Mirror or Rotation . The procedure also includes returning an LMSymbol object for future reference, ensuring the item is accurately placed in the drawing's intended location .

The PIDDeleteItem method removes a vessel by first placing it into a drawing with PIDPlaceSymbol, retrieving it as an LMAItem, and then invoking PIDDeleteItem . Indicators of a successful deletion include a boolean return value of true and possibly a message indicating the deletion's success .

To read the flow direction of a piperun, use the LMPipeRun object obtained via LMADataSource.GetPipeRun method, then access the FlowDirection attribute using the Attributes method to obtain its value . This information is critical as it helps in understanding and validating the flow configuration within a piping system, ensuring designs meet operational requirements .

Setting InitObjectsReadonly to True when handling a piperun in SmartPlant P&ID implies that the object is initialized in a read-only state, preventing modifications to its properties . This is particularly significant as it ensures that the properties remain unchanged even if attempts are made to modify them while the drawing is closed or when a new LMADataSource is initialized .

To filter historical data based on TimeStamp and ItemType, use the LMAFilter object to set criteria for filtering. For example, add criteria for 'TimeStamp' using '>' operator and specifically assign a timestamp value . Similarly, define criteria for ModelItem.ModelItemType using the '=' operator and assign an index value corresponding to 'Plant Item' . The filtered results are collected using the LMHistories objects' Collect method .

You might also like