SmartPlant P&ID Automation Labs Guide
SmartPlant P&ID Automation Labs Guide
V4.3
AUTOMATION COURSE
LABS
SmartPlant P&ID Automation Labs
Labs
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:
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
[Link] [Link]
[Link] [Link]
[Link] [Link]
[Link] [Link]
4
SmartPlant P&ID Automation Labs
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
[Link] [Link]
[Link] [Link]
[Link] = "C:\HostSite\[Link]"
[Link] = "Lin_Plant3"
5
SmartPlant P&ID Automation Labs
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
7
SmartPlant P&ID Automation Labs
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
8
SmartPlant P&ID Automation Labs
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
[Link]
[Link]
9
SmartPlant P&ID Automation Labs
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
[Link] = True
[Link]
[Link]
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
[Link]
[Link]
[Link]("Name").Value = "TEST2" 'assign value to PipeRun name
[Link]
[Link]
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
[Link]
[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]
12
SmartPlant P&ID Automation Labs
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
13
SmartPlant P&ID Automation Labs
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
[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
14
SmartPlant P&ID Automation Labs
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
Row = 1
[Link](Row, 1) = "ItemType"
[Link](Row, 3) = "Format"
[Link](Row, 4) = "IsCodeList"
15
SmartPlant P&ID Automation Labs
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
16
SmartPlant P&ID Automation Labs
[Link] True
[Link]
MsgBox "Done"
17
SmartPlant P&ID Automation Labs
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
[Link] = "TagSuffix"
[Link] = "P"
[Link] = "="
[Link] = "PipeRun"
[Link] criterion
18
SmartPlant P&ID Automation Labs
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
[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
19
SmartPlant P&ID Automation Labs
20
SmartPlant P&ID Automation Labs
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
[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
21
SmartPlant P&ID Automation Labs
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
[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
23
SmartPlant P&ID Automation Labs
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]
24
SmartPlant P&ID Automation Labs
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
25
SmartPlant P&ID Automation Labs
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
[Link] [Link]
26
SmartPlant P&ID Automation Labs
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
[Link] [Link]
27
SmartPlant P&ID Automation Labs
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
28
SmartPlant P&ID Automation Labs
29
SmartPlant P&ID Automation Labs
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
30
SmartPlant P&ID Automation Labs
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
31
SmartPlant P&ID Automation Labs
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
[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
[Link] [Link]
32
SmartPlant P&ID Automation Labs
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
[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
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
34
SmartPlant P&ID Automation Labs
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
35
SmartPlant P&ID Automation Labs
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
36
SmartPlant P&ID Automation Labs
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
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
[Link] = "PartOfType"
[Link] = "2" 'implied item
[Link] = "="
[Link] = "PlantItem"
[Link] criterion
38
SmartPlant P&ID Automation Labs
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
[Link] = "SP_PartOfID"
[Link] = Null
[Link] = "!="
[Link] = "PlantItem"
[Link] criterion
39
SmartPlant P&ID Automation Labs
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
[Link] = "ItemTag"
[Link] = "L-101L"
[Link] = "="
[Link] = "InstrLoop"
[Link] criterion
40
SmartPlant P&ID Automation Labs
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
[Link] [Link]
[Link] [Link]
Next
Next
42
SmartPlant P&ID Automation Labs
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
[Link] [Link]
Dim nozzle As LMNozzle
43
SmartPlant P&ID Automation Labs
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 [Link] = 1 Then
Set objPiperun = [Link](1).PipeRunObject
44
SmartPlant P&ID Automation Labs
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.
45
SmartPlant P&ID Automation Labs
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
[Link] [Link]
For Each objInstrument In [Link]
[Link] [Link]("InstrumentType").Value
Next
46
SmartPlant P&ID Automation Labs
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
[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
47
SmartPlant P&ID Automation Labs
48
SmartPlant P&ID Automation Labs
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
[Link] = "ItemTag"
[Link] = "01110-GCD"
[Link] = "="
[Link] = "PipeRun"
[Link] criterion
49
SmartPlant P&ID Automation Labs
Next
50
SmartPlant P&ID Automation Labs
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 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
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
52
SmartPlant P&ID Automation Labs
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 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
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 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
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
55
SmartPlant P&ID Automation Labs
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
56
SmartPlant P&ID Automation Labs
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
[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
57
SmartPlant P&ID Automation Labs
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
[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
[Link] [Link]
58
SmartPlant P&ID Automation Labs
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
[Link] = "ItemTag"
[Link] = "01110-GCD"
[Link] = "="
[Link] = "PipeRun"
[Link] criterion
59
SmartPlant P&ID Automation Labs
60
SmartPlant P&ID Automation Labs
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
61
SmartPlant P&ID Automation Labs
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
62
SmartPlant P&ID Automation Labs
63
SmartPlant P&ID Automation Labs
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
[Link] = "ItemTag"
[Link] = "N10"
[Link] = "="
[Link] = "Nozzle"
[Link] criterion
64
SmartPlant P&ID Automation Labs
'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
'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
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
[Link] = "[Link]"
[Link] = "unit2d"
[Link] = "="
[Link] = "OPC"
[Link] criterion
67
SmartPlant P&ID Automation Labs
68
SmartPlant P&ID Automation Labs
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
69
SmartPlant P&ID Automation Labs
70
SmartPlant P&ID Automation Labs
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
[Link] = "Name"
[Link] = "Automation1"
[Link] = "="
[Link] = "Drawing"
[Link] criterion
71
SmartPlant P&ID Automation Labs
Next
Next
Next
72
SmartPlant P&ID Automation Labs
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
[Link] = "Name"
[Link] = "Automation1"
[Link] = "="
[Link] = "Drawing"
[Link] criterion
73
SmartPlant P&ID Automation Labs
Next
Next
Next
74
SmartPlant P&ID Automation Labs
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
'get the plantgroup just above the drawing, in our case, should be unit
Set objPlantGroup = [Link]
[Link] "PlantGroup Name = " & [Link]("Name").Value
75
SmartPlant P&ID Automation Labs
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
'get the plantgroup just above the drawing, in our case, should be unit
Set objPlantGroup = [Link](1).[Link]
[Link] "PlantGroup Name = " & [Link]("Name").Value
76
SmartPlant P&ID Automation Labs
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
77
SmartPlant P&ID Automation Labs
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
78
SmartPlant P&ID Automation Labs
[Link] [Link]("Name").Value
Next
79
SmartPlant P&ID Automation Labs
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
[Link] [Link]("Name").Value
[Link] [Link]("Name").Value
If Not [Link] Is Nothing Then
[Link] [Link]("Name").Value
End If
[Link] [Link]("Name").Value
80
SmartPlant P&ID Automation Labs
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
[Link]
[Link]
81
SmartPlant P&ID Automation Labs
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
82
SmartPlant P&ID Automation Labs
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
83
SmartPlant P&ID Automation Labs
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
84
SmartPlant P&ID Automation Labs
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
[Link] = "Name"
[Link] = "Default Assembly Path"
[Link] = "="
[Link] = "OptionSetting"
[Link] criterion
85
SmartPlant P&ID Automation Labs
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
86
SmartPlant P&ID Automation Labs
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
87
SmartPlant P&ID Automation Labs
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
'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
''''' '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
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
90
SmartPlant P&ID Automation Labs
'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"
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)
91
SmartPlant P&ID Automation Labs
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
92
SmartPlant P&ID Automation Labs
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 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])
93
SmartPlant P&ID Automation Labs
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
94
SmartPlant P&ID Automation Labs
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
'first piperun
Set objItem = [Link](PipeRunLocation)
Set objConnector = [Link](objItem, objInputs)
'second piperun
Set objItem = [Link](PipeRunLocation)
Set objConnector = [Link](objItem, objInputs)
[Link] [Link]([Link])
95
SmartPlant P&ID Automation Labs
'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
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
97
SmartPlant P&ID Automation Labs
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
'place a vessel
Dim objSymbol1 As LMSymbol
Set objSymbol1 = [Link](VesselLocation, 0.25, 0.25)
98
SmartPlant P&ID Automation Labs
99
SmartPlant P&ID Automation Labs
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
100
SmartPlant P&ID Automation Labs
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
101
SmartPlant P&ID Automation Labs
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
Else
102
SmartPlant P&ID Automation Labs
103
SmartPlant P&ID Automation Labs
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
104
SmartPlant P&ID Automation Labs
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
105
SmartPlant P&ID Automation Labs
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
Set objOPC =
[Link]("28B79FF6B52047DB98600BE313648290")
106
SmartPlant P&ID Automation Labs
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
107
SmartPlant P&ID Automation Labs
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
blnSuccess = [Link](objSymbol, 3, X, Y)
'clean up
Set objPlacement = Nothing
Set objItem = Nothing
Set objConnector = Nothing
Set objSymbol = Nothing
Set objInputs = Nothing
108
SmartPlant P&ID Automation Labs
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
109
SmartPlant P&ID Automation Labs
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
[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"
110
SmartPlant P&ID Automation Labs
MsgBox "Done!"
111
SmartPlant P&ID Automation Labs
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
[Link]
Set objPIDAutoApp = Nothing
Set objPIDADrawing = Nothing
Set objDrawing = Nothing
Set objDrawings = Nothing
112
SmartPlant P&ID Automation Labs
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
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
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
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
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
End Function
'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
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
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
End Function
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
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
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
'Call [Link]
Set PlantItemValidate = CreateObject("[Link]")
If Not PlantItemValidate Is Nothing Then
ILMForeignCalc_DoValidateItem = [Link](DataSource, Items,
Context)
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
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
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
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.
124
SmartPlant P&ID Automation Labs
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
[Link](1).SaveAs (strFileName)
[Link](1).Close
[Link] (strFileName)
Set xlWorkbook = [Link]("[Link]")
[Link] [Link]
[Link] True
[Link]
126
SmartPlant P&ID Automation Labs
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:
127
SmartPlant P&ID Automation Labs
Address = strAddress
End Property
[Link] = "Dave"
[Link] = "David"
[Link] = -100
[Link] [Link]
[Link] [Link]
[Link] [Link]
[Link]
[Link]
[Link]
128
SmartPlant P&ID Automation Labs
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
129
SmartPlant P&ID Automation Labs
Implements IAccount
Implements IPurchase
[Link] 10.9
[Link] [Link]
[Link] [Link]
End Sub
130
SmartPlant P&ID Automation Labs
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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 .