Accessing other interfaces using ToInterface - 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

In the previous example, we retrieved a Vault object, but we only accessed properties on the IObject interface. IObject contains a method as follows:

Function ToInterface(ByVal pstrInterface As String) As IInterface

This function is very important. Not only will it return the requested interface, but it will also walk through the 'implies' tree and return the most specialized version of that interface. It also considers the specialization values. It is important, when accessing interfaces, to use this function and to request the correct interface. This will ensure that any customizations will be included in the returned object. For more information on specialization values, see Editing the SpecializationValues.xml file.

So, given the previous example, we can access the Vault-specific properties using the following code.

Dim lobjVaultIObject As IObject = SPFRequestContext.Instance.QueryRequest.GetObject(DataAccess.GetObjType.ByUID, "VLT_SPF40Vault")

Dim lobjVault As ISPFVault = CType(lobjVaultIObject.ToInterface("ISPFVault"), ISPFVault)

Debug.Print(lobjVault.SPFLocalPath)

Debug.Print(lobjVault.GetHost().Name)

Notice the call to ToInterface. That function returns IInterface, so we need to cast the return to the correct interface. Once we have ISPFVault, though, we can access all the properties on that interface and any interface it implies. You see the first debug statement accesses the SPFLocalPath property, which is available as a property. Furthermore, the code generator has provided access to the relationships defined on this interface through methods. The second debug statement shows an example of crossing to a related Host through the GetHost method. Since that method returns an object of class ISPFHost, the properties of that interface are immediately available.