Creating relationships - 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

Relationships can be created using the CreateRel method on the Utilities object or by using the CreateRel method on the ContainerObjectDictionary. There are three overloads of this method.

Public Shared Function CreateRel(ByVal pobjSPFSession As SPFSession, ByVal pstrRelDefUID As String, ByVal pobjEnd1 As IObject, ByVal pobjEnd2 As IObject) As IRel

Public Shared Function CreateRel(ByVal pobjSPFSession As SPFSession, ByVal pstrRelDefUID As String, ByVal pobjEnd1 As IObject, ByVal pobjEnd2 As IObject, ByVal pstrOrderValue As String) As IRel

Public Shared Function CreateRel(ByVal pobjSPFSession As SPFSession, ByVal pstrRelDefUID As String, ByVal pobjEnd1 As IObject, ByVal pobjEnd2 As IObject, ByVal pstrRelUID As String, ByVal pstrRelOBID As String, ByVal pobjTerminationDate As SPFDate) As IRel

Most of the time, you will use the first version. The second version adds the order value property for ordered relationships.

As an example, take a look at the following RelDef.

This is a relationship between a SmartPlant Foundation user and a company. The following code is an example of creating this relationship:

' Get the user and company

Dim lobjUser As IObject = Me.SPFSession.GetObjectByName("BillyBobThornton", "ISPFUser")

Dim lobjCompany As IObject = Me.SPFSession.GetObjectByName("20thCenturyFox", "ISPFCompany")

' Create the rel

Dim lobjUserCompany As IRel = SPF.Client.Schema.Utilities.CreateRel(Me.SPFSession, "SPFUserCompany", lobjUser, lobjCompany)

You can create objects and their relationships all in one transaction. The invocation of CreateRel is very simple, just passing in the SPFSession, RelDefUID, and the two objects.

Notice, though, the line adding the relationship to the transaction; it returns IRel to get to IObject. There is a property called IObject.