Creating objects - SmartPlant Foundation - IM Update 44 - Customization & Programming - Hexagon

SmartPlant Foundation Customization

Language
English
Product
SmartPlant Foundation
Search by Category
Customization & Programming
SmartPlant Foundation / SDx Version
10

Objects can be created very simply using a set of shared functions on the utility classes or if using a container by calling methods on the container object. This is described above.

This class is called Utilities and is in the SPF.Client.Schema namespace. The methods are as follows:

Public Shared Function CreateObject(ByVal pobjSPFSession As SPFSession, ByVal pstrClassDefinitionUID As String, ByVal pstrOBID As String, ByVal pstrUID As String, ByVal pstrName As String, ByVal pstrDescription As String) As IObject

Public Shared Function CreateObject(ByVal pobjSPFSession As SPFSession, ByVal pstrClassDefinitionUID As String, ByVal pstrUID As String, ByVal pstrName As String, ByVal pstrDescription As String) As IObject

Public Shared Function CreateObject(ByVal pobjSPFSession As SPFSession, ByVal pstrClassDefinitionUID As String, ByVal pstrName As String, ByVal pstrDescription As String) As IObject

Public Shared Function CreateObject(ByVal pobjSPFSession As SPFSession, ByVal pstrClassDefinitionUID As String) As IObject

All the functions above take a ClassDefUID as a parameter in addition to the SPFSession. The ClassDef will be referenced for creating the object itself. Then, interfaces will be created for all the required Realizes. From those interfaces, properties will be created for all the required exposes. The returned object will pass validation as soon as values have been set for the required properties.

Consider the following table illustrating the ClassDef SPFDepartment:

InterfaceDefs displayed in bold indicate a required Realizes relationship to that ClassDef. Likewise, PropertyDefs displayed in bold indicate a required Exposes relationship to that InterfaceDef. If we call CreateObject passing in this ClassDef will create the object with all the highlighted interfaces instanced. Further, the UID property will be instanced because it is required. Other required properties (such as those on ISPFInternalOrg and ISPFExternalOrg) will not be instanced because those interfaces are not required.

An example of using this method to create a SPFDepartment object is as follows:

Dim lobjDept As IObject = SPF.Client.Schema.Utilities.CreateObject (Me.SPFSession, "SPFDepartment")

lobjDept.Name = "Finance"

lobjDept.Description = "Finance area"

The first statement creates the object as described. The second and third statements set the values for the Name and Description properties. But what about interfaces and properties other than IObject and its properties? IObject contains a collection of type IInterfaceDictionary. The most important member of that class is the two variants of the indexer.

Public ReadOnly Default Property Item(ByVal pstrInterfaceDefinitionUID As String) As IInterface

Public ReadOnly Default Property Item(ByVal pstrInterfaceDefinitionUID As String, ByVal pblnActivate As Boolean) As IInterface

The first is just an abbreviation of the second passing true by default in the Activate parameter. Activate tells the Client API to create the interface if it has not already been instanced. Both of these return IInterface.

Likewise, a properties collection is exposed from IInterface, which is of type IPropertyDictionary. This collection has indexers as follows:

Public ReadOnly Default Property Item(ByVal pstrPropertyDefinitionUID As String) As Property

Public ReadOnly Default Property Item(ByVal pstrPropertyDefinitionUID As String, ByVal pblnActivate As Boolean) As Property

To set the property SPFOrgNotes on the ISPFOrganization interface, the code is as follows:

lobjDeliverable.Interfaces("ISPFOrganization").Properties("SPFOrgNotes").SetValue("For Review")

The code for a complete transaction creating a SPFDepartment is as follows:

' Begin transaction

Dim lobjContainer As New ObjectDictionary(_spfCustomApp.SPFWindowsClient.SPFSession)

Dim lobjDept As IObject = SPF.Client.Schema.Utilities.CreateObject (Me.SPFSession, "SPFDepartment")

lobjDept.Name = "Finance"

lobjDept.Description = "Finance area"

lobjContainer.Add(lobjDept)

lobjDeliverable.Interfaces("ISPFOrganization").Properties("SPFOrgNotes").SetValue("For Review")

' Commit transaction

lobjContainer.Commit()

Consider using containers for creating objects.