SPAutomation Course Labs V2009
SPAutomation Course Labs V2009
Unpublished – rights reserved under the copyright laws of the United States.
Intergraph Corporation
Huntsville, Alabama 35894-0001
Trademarks
Intergraph, the Intergraph logo, PDS, SmartPlant, SmartSketch, FrameWorks, INtools, MARIAN, ISOGEN, and
IntelliShip are registered trademarks and SupportModeler and SupportManager are trademarks of Intergraph
Corporation. Microsoft and Windows are registered trademarks of Microsoft Corporation. MicroStation is a
registered trademark of Bentley Systems, Inc. Other brands and product names are trademarks of their respective
owners.
Table of Contents
Table of Contents
Preface ...............................................................................................................................10
4. Identify an item in the database using sp_id and read its properties ..................15
7. Rollback .....................................................................................................................18
8. Propagation ...............................................................................................................19
12. Collect items from the database using filters with multiple criteria ...............26
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:
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 Debug.Print method to print out the required properties.
Example Code
Dim datasource As LMADataSource
Debug.Print datasource.ProjectNumber
Debug.Print datasource.SiteNode
Debug.Print datasource.IsSatellite
Debug.Print datasource.GetSystemEditingToolbarSetting
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
plant, then create a new drawing and place another Vessel in it.
c) Solution
Change the site and plant within your program to get access to that Vessel.
Example code
Dim datasource As LMADataSource
Debug.Print datasource.SiteNode
Debug.Print datasource.ProjectNumber
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
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 LMADataSource.GetVessle method.
3. Use Debug.Print method to print out the required properties.
Example code
Dim datasource As LMADataSource
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 LMADataSource.GetVessle method.
2. Change the value of required properties
3. Use LMVessel.Commit to commit the change to database
Example code
Dim datasource As LMADataSource
datasource.BeginTransaction
datasource.CommitTransaction
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
datasource.InitObjectsReadonly = True
datasource.BeginTransaction
datasource.CommitTransaction
a) Purpose
To rollback a transaction by automation program
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 LMADataSource.GetVessle method.
2. Dim a LMEquipment object and get the object using LMADataSource.GetEquipment method.
3. Use LMVessel.AsLMAItem and LMEquipment.AsLMAEquipment method to transfer to LMAItem.
Example code
datasource.BeginTransaction
datasource.BeginTransaction
objPipeRun.Attributes("Name").Value = "TEST2" 'assign value to PipeRun name
objPipeRun.Commit
datasource.RollbackTransaction
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
datasource.BeginTransaction
datasource.PropagateChanges = True
objPipeRun.Attributes("SupplyBy").Value = "By D" 'assign value to PipeRun Supply By
objPipeRun.Commit
datasource.PropagateChanges = False
objPipeRun.Attributes("CleaningReqmts").Value = "CC1" 'assign value to PipeRun Supply By
objPipeRun.Commit
datasource.CommitTransaction
Purpose
To access LMAAttributes collection of LLAMA object.
Problem Statement
Place a Vessel and get the LMVessel object, then loop through its Attributes collection.
Solution
Example code
Dim datasource As LMADataSource
Debug.Print objVessel.Attributes.item("ProcessAlternateDesign.Max.Pressure").Value
Debug.Print "Total attributes for Vessel: " & objVessel.Attributes.Count
For Each objAttr In objVessel.Attributes
Debug.Print "Attribute Name=" & objAttr.name & Space(50 - Len(objAttr.name)) & " Value=" &
objAttr.Value
Next
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 LMAAttribute.ISPAttribute
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
xlWorksheet.Cells(Row, 1) = "ItemType"
xlWorksheet.Cells(Row, 3) = "Format"
xlWorksheet.Cells(Row, 4) = "IsCodeList"
Row = Row + 1
On Error Resume Next
vValue = objVessel.Attributes("ProcessDesign.Max.Pressure")
On Error GoTo 0
xlWorksheet.Cells(Row, 1) = "Total attributions for Vessel: " & objVessel.Attributes.Count
Row = Row + 1
For Each objAttr In objVessel.Attributes
xlWorksheet.Cells(Row, 1) = objVessel.AsLMAItem.ItemType
xlWorksheet.Cells(Row, 2) = objAttr.name
xlWorksheet.Cells(Row, 3) = objAttr.ISPAttribute.Attribution.Format
On Error Resume Next
CodeListCount = 0
CodeListCount = objAttr.ISPAttribute.Attribution.ISPEnumAtts.Count
On Error GoTo 0
If CodeListCount > 0 Then
xlWorksheet.Cells(Row, 4) = "True"
Else
xlWorksheet.Cells(Row, 4) = "False"
End If
xlWorksheet.Cells(Row, 5) = objAttr.Index
xlWorksheet.Cells(Row, 6) = objAttr.ISPAttribute.Attribution.CalculationProgID
xlWorksheet.Cells(Row, 7) = objAttr.ISPAttribute.Attribution.ValidationProgID
Row = Row + 1
Next
MsgBox "Done"
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 LMPipeRuns.Collect method by using the LMAFilter
Example code
Dim datasource As LMADataSource
criterion.SourceAttributeName = "TagSuffix"
criterion.ValueAttribute = "P"
criterion.Operator = "="
objFilter.ItemType = "PipeRun"
objFilter.Criteria.Add criterion
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 LMPipeRuns.Collect method by using the LMAFilter
Example code
Dim datasource As LMADataSource
objFilter.Criteria.AddNew ("FirstOne")
objFilter.Criteria.item("FirstOne").SourceAttributeName = "ItemTag"
objFilter.Criteria.item("FirstOne").ValueAttribute = "%K%"
objFilter.Criteria.item("FirstOne").Operator = "like"
objFilter.ItemType = "PipeRun"
objFilter.Criteria.AddNew ("SecondOne")
objFilter.Criteria.item("SecondOne").SourceAttributeName = "TagSuffix"
objFilter.Criteria.item("SecondOne").ValueAttribute = "P_"
objFilter.Criteria.item("SecondOne").Operator = "like"
objFilter.Criteria.item("SecondOne").Conjunctive = False
objFilter.Criteria.AddNew ("ThirdOne")
objFilter.Criteria.item("ThirdOne").SourceAttributeName = "Name"
objFilter.Criteria.item("ThirdOne").ValueAttribute = Null
objFilter.Criteria.item("ThirdOne").Operator = "!="
objFilter.Criteria.item("ThirdOne").Conjunctive = False
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
objFilter.Criteria.AddNew ("FirstOne")
objFilter.Criteria.item("FirstOne").SourceAttributeName = "ItemStatus"
objFilter.Criteria.item("FirstOne").ValueAttribute = "1"
objFilter.Criteria.item("FirstOne").Operator = "="
objFilter.ItemType = "PipeRun"
objFilter.Criteria.AddNew ("SecondOne")
objFilter.Criteria.item("SecondOne").SourceAttributeName = "NominalDiameter"
objFilter.Criteria.item("SecondOne").ValueAttribute = "5064" '2"
objFilter.Criteria.item("SecondOne").Operator = "="
objFilter.Criteria.item("SecondOne").Conjunctive = True
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
objChildFilter1.ItemType = "PipeRun"
objChildFilter1.name = "Filter 1"
objChildFilter1.Criteria.AddNew ("FirstOne")
objChildFilter1.Criteria.item("FirstOne").SourceAttributeName = "ItemStatus"
objChildFilter1.Criteria.item("FirstOne").ValueAttribute = "1"
objChildFilter1.Criteria.item("FirstOne").Operator = "="
objChildFilter2.ItemType = "PipeRun"
objChildFilter2.name = "Filter 2"
objChildFilter2.Criteria.AddNew ("FirstOne")
objChildFilter2.Criteria.item("FirstOne").SourceAttributeName = "NominalDiameter"
objChildFilter2.Criteria.item("FirstOne").ValueAttribute = "5032" '1"
objChildFilter2.Criteria.item("FirstOne").Operator = "="
objChildFilter2.Criteria.AddNew ("SecondOne")
objChildFilter2.Criteria.item("SecondOne").SourceAttributeName = "NominalDiameter"
objChildFilter2.Criteria.item("SecondOne").ValueAttribute = 5064 '2"
objChildFilter2.Criteria.item("SecondOne").Operator = "="
objChildFilter2.Criteria.item("SecondOne").Conjunctive = False
objFilter.ItemType = "PipeRun"
objFilter.FilterType = 1 '1 for compound filter, 0 for simple filter
objFilter.ChildLMAFilters.Add objChildFilter1
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 LMADataSource.Filters 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 = datasource.Filters
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
a) Purpose
To create a filter with select list data in criteria, learn how to resolve the select data to its index dynamically.
b) Problem Statement
Place couple piping valves in drawing. Write a standalone application to collect all Ball Valves.
c) Solution
Example code
Dim datasource As LMADataSource
criterion.SourceAttributeName = "PipingCompType"
criterion.ValueAttribute = datasource.CodeList("Piping Component
Type").EnumeratedAttributes.GetItemIndex("Ball valve")
criterion.Operator = "="
objFilter.ItemType = "PipingComp"
objFilter.Criteria.Add criterion
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
Debug.Print objHistories.Count
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
Debug.Print objStatuses.Count
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
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
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
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
objFilter.Criteria.AddNew ("FirstOne")
objFilter.Criteria.item("FirstOne").SourceAttributeName = "TimeStamp"
objFilter.Criteria.item("FirstOne").ValueAttribute = "7/19/04 8:00:00 AM"
objFilter.Criteria.item("FirstOne").Operator = ">"
objFilter.ItemType = "History"
objFilter.Criteria.AddNew ("SecondOne")
objFilter.Criteria.item("SecondOne").SourceAttributeName = "ModelItem.ModelItemType"
objFilter.Criteria.item("SecondOne").ValueAttribute = 29 '29 is the index for 'Plant Item'
objFilter.Criteria.item("SecondOne").Operator = "="
objFilter.Criteria.item("SecondOne").Conjunctive = True
Dim objHistories As LMHistories
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 LMADataSource.GetVessel and LMADataSource.GetEquipment methods to obtain object Vessel and
Equipment with same SP_ID
2.change 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
Debug.Print objEquipment.name
Debug.Print objVessel.name
objEquipment.Attributes("Name").Value = "Lab-12"
objEquipment.Commit
Set objVessel = datasource.GetVessel(CONST_SPID_Vessel)
Debug.Print objEquipment.name
Debug.Print objVessel.name
datasource.CommitTransaction
Set datasource = Nothing
Set objVessel = Nothing
Set objEquipment = Nothing
Set objAttr = Nothing
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
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
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
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
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
criterion.SourceAttributeName = "PartOfType"
criterion.ValueAttribute = "2" 'implied item
criterion.Operator = "="
objFilter.ItemType = "PlantItem"
objFilter.Criteria.Add criterion
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, TEMA 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
criterion.SourceAttributeName = "SP_PartOfID"
criterion.ValueAttribute = Null
criterion.Operator = "!="
objFilter.ItemType = "PlantItem"
objFilter.Criteria.Add criterion
a) Purpose
To get familiar with relationship between PlantItemGroup and PlantItem
c) 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
criterion.SourceAttributeName = "ItemTag"
criterion.ValueAttribute = "L-101L"
criterion.Operator = "="
objFilter.ItemType = "InstrLoop"
objFilter.Criteria.Add criterion
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
Debug.Print objInstrLoops.Count
Debug.Print objInstruments.Count
Next
Next
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 LMAVessel.nozzles to get a collection of nozzle belong to this Vessel
Example code
Dim datasource As LMADataSource
Debug.Print nozzles.Count
Dim nozzle As LMNozzle
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 LMADataSource.GetPipingComp
2. loop LMPipingComp.InlineComps
3. use LMInlinecomp.PipeRunObject
Example code
Dim datasource As LMADataSource
If objPipingComp.InlineComps.Count = 1 Then
Set objPiperun = objPipingComp.InlineComps.Nth(1).PipeRunObject
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 LMADataSource.GetInstrument
2. loop LMInstrument.InlineComps
3. use LMInlinecomp.InstrumentObject
Example code
„be aware of that only inline instrument associate with InlineComp object.
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
Debug.Print objSignalRun.Instruments.Count
For Each objInstrument In objSignalRun.Instruments
Debug.Print objInstrument.Attributes("InstrumentType").Value
Next
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
Debug.Print objInstrument.InstrFunctions.Count
For Each objInstrFunction In objInstrument.InstrFunctions
For Each objAttribute In objInstrFunction.Attributes
Debug.Print "Attribute Name=" & objAttribute.name & Space(50 - Len(objAttribute.name)) & " Value=" &
objAttribute.Value
Next
Next
Debug.Print objInstrument.InstrOptions.Count
For Each objInstrOption In objInstrument.InstrOptions
For Each objAttribute In objInstrOption.Attributes
Debug.Print "Attribute Name=" & objAttribute.name & Space(50 - Len(objAttribute.name)) & " Value=" &
objAttribute.Value
Next
Next
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
criterion.SourceAttributeName = "ItemTag"
criterion.ValueAttribute = "01110-GCD"
criterion.Operator = "="
objFilter.ItemType = "PipeRun"
objFilter.Criteria.Add criterion
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
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
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
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
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
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
a) Purpose
Directly find the active drawing not through an item first, then find all PlantItems in it.
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
objFilter.Criteria.AddNew ("FirstOne")
objFilter.Criteria.item("FirstOne").SourceAttributeName = "Representation.Drawing.Name"
objFilter.Criteria.item("FirstOne").ValueAttribute = objDrawing.Attributes("Name").Value
objFilter.Criteria.item("FirstOne").Operator = "="
objFilter.ItemType = "PlantItem"
objFilter.Criteria.AddNew ("SecondOne")
objFilter.Criteria.item("SecondOne").SourceAttributeName = "ItemStatus"
objFilter.Criteria.item("SecondOne").ValueAttribute = 1
objFilter.Criteria.item("SecondOne").Operator = "="
objFilter.Criteria.item("SecondOne").Conjunctive = True
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
objFilter.Criteria.AddNew ("SecondOne")
objFilter.Criteria.item("SecondOne").SourceAttributeName = "Representation.InStockpile"
objFilter.Criteria.item("SecondOne").ValueAttribute = 2 '2 is index stands for True
objFilter.Criteria.item("SecondOne").Operator = "="
objFilter.Criteria.item("SecondOne").Conjunctive = True
objFilter.Criteria.AddNew ("ThirdOne")
objFilter.Criteria.item("ThirdOne").SourceAttributeName = "Representation.SP_DrawingId"
objFilter.Criteria.item("ThirdOne").ValueAttribute = 0 '0 stands Plant Stockpile
objFilter.Criteria.item("ThirdOne").Operator = "="
objFilter.Criteria.item("ThirdOne").Conjunctive = True
Debug.Print objVessels.Count
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
criterion.SourceAttributeName = "ItemTag"
criterion.ValueAttribute = "01110-GCD"
criterion.Operator = "="
objFilter.ItemType = "PipeRun"
objFilter.Criteria.Add criterion
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.
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 LMConnector.ModelItemID,
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
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 LMPipeRun.Representations, obtain LMConnector, whose RepresentationType is “Connector”, then, from
LMConnector.ConnnectItem1SymbolObject or LMConnector.ConnecItem2SymbolObject find the Symbol object
connect to
the Connector, then, from LMSymbol.ModelItemID 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
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
criterion.SourceAttributeName = "ItemTag"
criterion.ValueAttribute = "N10"
criterion.Operator = "="
objFilter.ItemType = "Nozzle"
objFilter.Criteria.Add criterion
'After the BranchPoint is located, use again the connect1connectors & connect2connectors method to locate
'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 branchsymbol.Connect1Connectors.Count >= 1 Then
For Each connector2 In branchsymbol.Connect1Connectors
If connector2.ModelItemID <> connector.ModelItemID Then
Set connector3 = connector2
Exit For
'Print out two nozzles' name and itmetag of the vessel they attached
Debug.Print "Nozzle2 itemtag = " & nozzle2.Attributes("ItemTag").Value
Debug.Print "Nozzle itemtag = " & nozzle.Attributes("ItemTag").Value
Debug.Print "vessel nozzle2 attached = " & nozzle2.EquipmentObject.Attributes("ItemTag").Value
Debug.Print "vessel nozzle attached =" & nozzle.EquipmentObject.Attributes("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
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
criterion.SourceAttributeName = "Representation.Drawing.Name"
criterion.ValueAttribute = "unit2d"
criterion.Operator = "="
objFilter.ItemType = "OPC"
objFilter.Criteria.Add criterion
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
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
criterion.SourceAttributeName = "Name"
criterion.ValueAttribute = "Automation1"
criterion.Operator = "="
objFilter.ItemType = "Drawing"
objFilter.Criteria.Add criterion
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
criterion.SourceAttributeName = "Name"
criterion.ValueAttribute = "Automation1"
criterion.Operator = "="
objFilter.ItemType = "Drawing"
objFilter.Criteria.Add criterion
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 = objVessel.PlantGroupObject
Debug.Print "PlantGroup Name = " & objPlantGroup.Attributes("Name").Value
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 = objVessel.Representations.Nth(1).DrawingObject.PlantGroupObject
Debug.Print "PlantGroup Name = " & objPlantGroup.Attributes("Name").Value
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
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
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
Debug.Print objDrawingSite.DrawingObject.Attributes("Name").Value
Debug.Print objDrawingSite.WSSiteObject.Attributes("Name").Value
If Not objDrawingSite.ToWSSiteWSSiteObject Is Nothing Then
Debug.Print objDrawingSite.ToWSSiteWSSiteObject.Attributes("Name").Value
End If
Debug.Print objDrawingSite.PlantGroupObject.Attributes("Name").Value
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
datasource.BeginTransaction
datasource.CommitTransaction
a) Purpose
To access the active project
b) Problem Statement
Set The Plant or one of projects as active project, then use LMADatasource.GetActiveProject 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
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
a) Purpose
To access the items‟ claim status.
b) Problem Statement
Set items in different claim status, and access claim status by using function
LMADatasource.GetModelItemClaimStatus
c) Solution
Example code
Dim datasource As LMADataSource
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
criterion.SourceAttributeName = "Name"
criterion.ValueAttribute = "Default Assembly Path"
criterion.Operator = "="
objFilter.ItemType = "OptionSetting"
objFilter.Criteria.Add criterion
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
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
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 = objPlacement.PIDPlaceSymbol(vesselName, xvessel, yvessel)
'set Cleaning Requirement for the Vessel
''''' 'place nozzles again use same X, Y coordinates, but this time set PIDSnapToTarget=false
''''' objPlacement.PIDSnapToTarget = False
''''' Set symbol21 = objPlacement.PIDPlaceSymbol(nozzleName, xvessel - 0.2, yvessel + 0.05, _
''''' TargetItem:=symVessel.AsLMRepresentation)
''''' Set symbol31 = objPlacement.PIDPlaceSymbol(nozzleName, xvessel + 0.2, yvessel + 0.07, _
''''' TargetItem:=symVessel.AsLMRepresentation)
''''' objPlacement.PIDSnapToTarget = True
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
'place vessel
Set symVessel = objPlacement.PIDPlaceSymbol(vesselName, xvessel, yvessel)
'get placed vessel and set some properties' value
Set vessel = objPlacement.PIDDataSource.GetVessel(symVessel.ModelItemID)
vessel.name = "Vessel for Label Placement"
vessel.InsulPurpose = "R15"
vessel.HTraceMedium = "SS"
vessel.HTraceMediumTemp = "300 F"
vessel.HTraceReqmt = "ET"
points(1) = xvessel
points(2) = yvessel
points(3) = xvessel + 0.05
points(4) = yvessel + 0.1
Set labelpersist = objPlacement.PIDPlaceLabel(labelName3, _
points(), Labeleditem:=symVessel.AsLMRepresentation, _
IsLeaderVisible:=True)
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
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 = objConnector.ConnectorVertices.Nth(1).Attributes("XCoordinate").Value
Y = objConnector.ConnectorVertices.Nth(1).Attributes("YCoordinate").Value
'place the OPC from stockpile into active drawing
Dim symbol As LMSymbol
Set symbol = objPlacement.PIDPlaceSymbol(OPClocation, X, Y, , , objpairOPC.AsLMAItem)
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
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 = objPlacement.PIDCreateItem(PipeRunLocation)
Set objConnector = objPlacement.PIDPlaceRun(objItem, objInputs)
'second piperun
Set objItem = objPlacement.PIDCreateItem(PipeRunLocation)
Set objConnector = objPlacement.PIDPlaceRun(objItem, objInputs)
objPiperuns.Add objPlacement.PIDDataSource.GetPipeRun(objConnector.ModelItemID)
'third piperun
Set objItem = objPlacement.PIDCreateItem(PipeRunLocation)
Set objConnector = objPlacement.PIDPlaceRun(objItem, objInputs)
objPiperuns.Add objPlacement.PIDDataSource.GetPipeRun(objConnector.ModelItemID)
'AutoJoin
For Each objPiperun In objPiperuns
objPlacement.PIDAutoJoin objPiperun.AsLMAItem, autoJoin_Both, objSurvivorItem
Next
MsgBox "Done!"
'clean up
Set objPlacement = Nothing
Set objItem = Nothing
Set objConnector = Nothing
Set objSymbol = Nothing
Set objInputs = Nothing
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
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 = objPlacement.PIDPlaceSymbol(VesselLocation, 0.25, 0.25)
Debug.Print "The vessel belongs to how many plantitemgroups? = " & objVessel.PlantItemGroups.Count
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
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
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
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
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
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
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
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 = objPlacement.PIDConnectPointLocation(objSymbol, 3, X, Y)
'clean up
Set objPlacement = Nothing
Set objItem = Nothing
Set objConnector = Nothing
Set objSymbol = Nothing
Set objInputs = Nothing
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
Debug.Print "The instrument belongs to how many plantitemgroups? = " & objInstr.PlantItemGroups.Count
objInstr.PlantItemGroups.Add objInstrLoop.AsLMPlantItemGroup
objInstr.Commit
Debug.Print "The instrument belongs to how many plantitemgroups? = " & objInstr.PlantItemGroups.Count
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 Responsibility.sym" label, and place a new "\Piping\Segment Breaks\Construction Status.sym"
label at the same X, Y Coordinate.
c) Solution
Example code
Dim objPlacement As Plaice.Placement
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
objFilter.Criteria.AddNew ("FirstOne")
objFilter.Criteria.item("FirstOne").SourceAttributeName = "ItemStatus"
objFilter.Criteria.item("FirstOne").ValueAttribute = 1
objFilter.Criteria.item("FirstOne").Operator = "="
objFilter.ItemType = "Vessel"
objFilter.Criteria.AddNew ("SecondOne")
objFilter.Criteria.item("SecondOne").SourceAttributeName = "SP_DrawingID"
objFilter.Criteria.item("SecondOne").ValueAttribute = objPlacement.PIDDataSource.PIDMgr.Drawing.ID
objFilter.Criteria.item("SecondOne").Operator = "="
objFilter.Criteria.item("SecondOne").Conjunctive = True
objFilter.ItemType = "LabelPersist"
MsgBox "Done!"
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 PIDAutomation.Application
Dim objPIDADrawing As PIDAutomation.Drawing
Dim objDrawing As LMDrawing
Dim objDrawings As LMDrawings
objPIDAutoApp.Quit
Set objPIDAutoApp = Nothing
Set objPIDADrawing = Nothing
Set objDrawing = Nothing
Set objDrawings = Nothing
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 PIDAutomation.Application
Dim objPIDADrawing As PIDAutomation.Drawing
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\C-Size.pid"
DrawingNumber = "TestCreateNewDrawing1"
DrawingName = "TestCreateNewDrawing1"
Set objPIDADrawing = objPIDAutoApp.Drawings.Add(PlantGroupName, TemplateFileName, DrawingNumber,
DrawingName)
If Not objPIDADrawing Is Nothing Then
MsgBox "Drawing " & objPIDADrawing.name & " is opened!"
objPIDADrawing.CloseDrawing True
End If
objPIDAutoApp.Quit
Set objPIDAutoApp = Nothing
Set objPIDADrawing = Nothing
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 PIDAutomation.Application
Dim objPIDADrawing As PIDAutomation.Drawing
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\E-Size.pid"
DrawingNumber = "TestCreateNewDrawing2"
DrawingName = "TestCreateNewDrawing2"
Set objPIDADrawing = objPIDAutoApp.Drawings.Add(PlantGroupName, TemplateFileName, DrawingNumber,
DrawingName)
If Not objPIDADrawing Is Nothing Then
Set objPlacement = New Placement
Set datasource = objPlacement.PIDDataSource
AssemblyLocation = "\Assemblies\Automation.pid"
'place assembly
Set objItems = objPlacement.PIDPlaceAssembly(AssemblyLocation, 0.2, 0.2)
'change TagSequenceNo
For Each objItem In objItems
If objItem.ItemType = "Connector" Then
Set objConnector = datasource.GetConnector(objItem.ID)
If objConnector.ModelItemObject.AsLMAItem.ItemType = "PipeRun" Then
Set objPiperun = datasource.GetPipeRun(objConnector.ModelItemID)
objPiperun.Attributes("TagSequenceNo").Value = 100
objPiperun.Commit
End If
End If
Next
objPIDADrawing.CloseDrawing True
objPIDAutoApp.Quit
Set objPIDAutoApp = Nothing
Set objPIDADrawing = Nothing
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 = datasource.GetEquipment(Item.Id)
On Error GoTo 0
If Not objEquipment Is Nothing Then
Set objSymbol = datasource.GetSymbol(datasource.GetModelItem(Item.Id).Representations.Nth(1).Id)
Value = objSymbol.Attributes("XCoordinate").Value & "/" &
objSymbol.Attributes("YCoordinate").Value
End If
End If
Next
ShowXYCoordinates = True
'clean up
Set Item = Nothing
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.
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
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: " & Err.Description
'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.
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 PlantItemValidation.Validate
Set PlantItemValidate = CreateObject("PlantItemValidation.Validate")
If Not PlantItemValidate Is Nothing Then
ILMForeignCalc_DoValidateItem = PlantItemValidate.DoValidateItem(DataSource, Items, Context)
End If
End Function
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.
Purpose
Enable the Drawing validation when a drawing event is triggered.
d) Problem Statement
System admin wants to log the time user name when a drawing is opened, closed or printed. This example writes an
Active-X dll (DrawingValidation.dll) implementing the DoValidateItem method when ac drawing event (Open,
Close, Print, Create, Modify) is detected. The ProgID, DrawingValidation.Validate needs to be assigned to
Drawing object in DataDictionary Manage -> DataBase Itemtypes table.
e) Solution
Example code
Option Explicit
Implements ILMForeignCalc
Implements IPrintValidation
End Function
Case LMForeignCalc.ENUM_LMAValidateContext.LMAValidateCreate
sFileName = "Drawing Created
Case LMForeignCalc.ENUM_LMAValidateContext.LMAValidateDelete
sFileName = "Drawing Deleted "
Case LMForeignCalc.ENUM_LMAValidateContext.LMAValidateModify
sFileName = "Drawing Modified
'Create file
If Len(sFileName) > 0 Then CreateFile sFileName, Items
ILMForeignCalc_DoValidateItem = True
Exit Function
ErrHndl:
MsgBox Err.Description
ILMForeignCalc_DoValidateItem = False
End Function
'Create file for the Context Type (Create, Delete, Open, Close, Modify, or Print) in the "Environ("Temp")" Directory
and log drawing info.
'Create the "Environ("Temp")" Directory if doesn't already exist.
sFolder = Environ("Temp")
lFileNum = FreeFile
Dim f, fs
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.OpenTextFile(sFileName, ForAppending, -2)
f.WriteLine (DateTime.Time)
f.WriteLine (" Item Type: " & Items.Nth(1).ItemType)
f.WriteLine (" Name: " & Items.Nth(1).Attributes("Name"))
f.WriteLine (" UserName: " & Environ("UserName") & vbCrLf)
f.Close
Set fs = Nothing
Set fso = Nothing
Exit Sub
ErrHndl:
End Sub
ErrHndl:
IPrintValidation_DoValidatePrint = False
End Function
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 Standard.exe 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()
Debug.print “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
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
1.From the Start menu, click on Programs folder/Microsoft Visual Basic 6./Visual Basic 6.0.
2.Open a Standard.exe project.
3.Create Command button on the default form.
Purpose
To become familiar with looking up libraries in Visual Basic
Problem Statement
Use the Object Browser to examine the classes, methods, and properties of the Microsoft Excel library and the
SmartPlant P&ID library.
Solution
Open a Standard Executable in Visual Basic
3. From the Start menu, click on Programs folder/Microsoft Visual Basic 6./Visual Basic 6.0.
4. Open a Standard.exe project.
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 Standard.exe 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 Excel.Application
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 Excel.Application
objExcel.Workbooks(1).SaveAs (strFileName)
objExcel.Workbooks(1).Close
objExcel.Workbooks.Open (strFileName)
Set xlWorkbook = objExcel.Workbooks("Excel1.xls")
Debug.Print xlWorkbook.Sheets.Count
xlWorkbook.Close True
objExcel.Quit
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
10. Select Project\Add Class Module
11. Rename the Class Module to “Customer”
12. Dimension three private variables: strName as string, strAddress as string, intAge as integer
13. Create three Property procedures with Get and Let definitions: Name, Address, Age.
14. In the Let procedure for the Age property, include an IF structure to ensure that the age is never
negative.
15. 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
16. Create a executable application reference the Active-X DLL
17. Create a form in the executable application
18. Create a command on the form and double click it to enter code into its click event.
19. 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:
obj2.name = "Dave"
obj3.name = "David"
obj3.Age = -100
Debug.Print obj1.name
Debug.Print obj2.name
Debug.Print obj3.name
obj1.Display
obj2.Display
obj3.Display
Purpose
To practice writing Active-X server components which support interfaces
Problem Statement
Create an Active-X interface, its implementation, and a client driver program to use the two libraries.
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.
20. IAccount has one function AccountBalance and IPurchase has one function
LastPurchaseAmount, each returning a double datatype.
21. Save the project and run it.
Create a project called Implementation with a single class called CreditCard
22. Create an Active-X dll project called Implementation.
23. Reference the Interface dll.
24. Open the class module and name it CreditCard.
25. Implement the two interfaces in the class.
26. Create two private variables to hold the lastPurchaseAmount and the accountBalance.
27. Add a property called paymentAmount which reduces the account balance by the given amount in
the Let definition.
28. 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.
29. Implement the two functions from the interfaces to return the values of the two appropriate
variables.
Create a project called Client with a Form
30. Create a standard executable project called Client.
31. Reference the two dlls created above.
32. Dimension one variable each for the three classes developed above.
33. Create a new creditcard object and assign it some payment and purchase using the creditcard
object‟s properties.
34. Set the two interface variables to point to the creditcard object.
35. 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
Implements IAccount
creditCard.AddFinanceCharge 10.9
Debug.Print accountInterface.AccountBalance
Debug.Print purchaseInterface.LastPurchaseAmount
End Sub
Purpose
Get familiar with LLAMA
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.
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
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
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
a) Purpose
How to determine if a drawing is belong to the active site in workshare environment? Or just a read only drawing?
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.
a) Purpose
To apply the knowledge you learned in this cource for both LLAMA and PLACEMENT
b) Problem Statement
Considering following workflow: In the beginning of project, same piping valve, for example ball valve, is used as
for Normal Close (NC) and Normal Open (NO), by setting the attribute “Opening Action”, to NC or NO. Later in the
project, it is required to have different symbols for NC or NO valves. It is OK to keep the original valve as NO, but
needs a new symbol for NC. Problem: how to update all placed valves in different drawings?
Write a standalone application to search all placed valves, using ball valve for example, then depends on its
“Opening Action” is NC or NO, if it is NC, then to replace it with new valve.
You may start the project by open a drawing, and run the utility against the active drawing only. Later, enhance the
utility to have function to batch process all drawings.
You need to create one new ball valve symbol as NC for this lab.
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
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.
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
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.
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.
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. Then print out the ItemTag of the connected item if it is a Piperun, or the ItemTag of its parent
if it is Nozzle.
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
b) Problem Statement
Modify the the From/To Macro to not reporting Branch Piperuns.
c) Solution
Example code