Creating complex objects (documents) - 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

There are a number of things that happen behind the scenes both client and server when you call the Create method on a ClassDef.

Dim lobjClassDefs As IObjectDictionary = pobjWindowsFormsClient.SPFSession.GetObjectsByName("SPFDesignDocVersion", "IClassDef")

If lobjClassDefs.Count > 0 Then

Dim lobjMasterClassDef As IClassDef = CType(lobjClassDefs.Item(0).Interfaces("IClassDef"), IClassDef)

Dim lobjDocs As IObjectDictionary = lobjMasterClassDef.Create()

In the example above a query request is made to the server to retrieve the SPFDesignDocVersion ClassDef object. Then it is cast to IClassDef, and the create method will call the server to see if this is a complex object. If so, the return collection will contain instantiated versions of each of the complex objects. So in the case of documents, this will be Master, RelToRev, Revision, RelToVersion, and Version. Then you can set the properties as required.

See example code in the client training assembly under Source\Client\SPFClientTraining\SPF\Client\Forms\Custom Examples\CreateDocumentAndAttachFile.vb.

'

' Get the classdef for the Version object (important that it is the version

'

Dim lobjClassDefs As IObjectDictionary = pobjWindowsFormsClient.SPFSession.GetObjectsByName("SPFDesignDocVersion", "IClassDef")

If lobjClassDefs.Count > 0 Then

Dim lobjMasterClassDef As IClassDef = CType(lobjClassDefs.Item(0).Interfaces("IClassDef"), IClassDef)

Dim lobjDocs As IObjectDictionary = lobjMasterClassDef.Create()

'

' this collection will contain all the document objects and relationships to each other.

'

Dim lobjDocVersion As IObject = Nothing ' Need this to attach the file to.

'

' Need to set the name, description. Then RevScheme and OwningGroup and various other properties

' Need to get the revision scheme and the owning group from the database

'

Dim lobjOwningGroup As IObject = pobjWindowsFormsClient.SPFSession.GetObjectsByUID("DAG_ADMIN").Item(0)

Dim lobjRevScheme As IObject = pobjWindowsFormsClient.SPFSession.GetObjectsByUID("RS_RevA1").Item(0)

Dim lobjClassification As IObject = pobjWindowsFormsClient.SPFSession.GetObjectsByUID("DC_Civil_Details_1").Item(0)

Dim lstrName As String = "K056-001-002"

Dim lstrDesc As String = "Created using custom code in the client"

Dim lobjOwningGroupRel As IRel = Nothing

Dim lobjRevSchemaRel As IRel = Nothing

Dim lobjClassificationRel As IRel = Nothing

With lobjDocs.GetEnumerator

Do While .MoveNext

Dim lobjItem As IObject = .Value

If lobjItem.Interfaces.Contains("ISPFDocumentMaster") Then

'

' This is the master

'

lobjItem.Interfaces("ISPFDocument").Properties("SPFDocState").SetValue("RESERVED")

'

' Create the relationship to the Revision Scheme

'

lobjClassificationRel = Schema.Utilities.CreateRel(pobjWindowsFormsClient.SPFSession, "SPFPrimaryClassification", lobjClassification, lobjItem, "10")

ElseIf lobjItem.Interfaces.Contains("ISPFDocumentRevision") Then

'

' This is the revision

'

lobjItem.Interfaces("ISPFDocumentRevision").Properties("SPFMajorRevision").SetValue("A")

lobjItem.Interfaces("ISPFDocumentRevision").Properties("SPFRevState").SetValue("WORKING")

lobjItem.Interfaces("ISPFDocumentRevision").Properties("SPFMinorRevision").SetValue("1")

'

' Create the relationship to the Revision Scheme

'

lobjRevSchemaRel = Schema.Utilities.CreateRel(pobjWindowsFormsClient.SPFSession, "SPFDocRevisionRevisionScheme", lobjItem, lobjRevScheme, "10")

ElseIf lobjItem.Interfaces.Contains("ISPFDocumentVersion") Then

'

' Create the relationship to the Owning group

'

lobjOwningGroupRel = Schema.Utilities.CreateRel(pobjWindowsFormsClient.SPFSession, "SPFItemOwningGroup", lobjItem, lobjOwningGroup, "10")

lobjDocVersion = lobjItem

End If

If lobjItem.ClassDefinitionUID <> "Rel" Then

lobjItem.Name = lstrName

lobjItem.Description = lstrDesc

End If

Loop

End With

'

' Add the new rels into the container

'

lobjDocs.Add(lobjOwningGroupRel.IObject)

lobjDocs.Add(lobjRevSchemaRel.IObject)

lobjDocs.Add(lobjClassificationRel.IObject)

'

' Now attach the file to the new document

' To create the file metadata call this method, it actually creates the file, fileype rel as well

'

Dim lobjFileInfo As New IO.FileInfo("c:\temp\Document1.doc")

Dim lobjFileResult As FileCreationResult = SPF.Client.Schema.Utilities.CreateFileObject(pobjWindowsFormsClient, lobjFileInfo)

lobjDocs.Add(lobjFileResult.File)

lobjDocs.Add(lobjFileResult.FileType.IObject)

lobjDocs.Add(lobjFileResult.RelFileFileType.IObject)

'

' You need to work out which vault the file is going to before you send it.

'

Dim lobjVault As IObject = Nothing

Dim lobjServerReq As New ServerRequest(pobjWindowsFormsClient.SPFSession, "GetVaultForNewFile")

lobjServerReq.AddQueryElement(lobjDocs.GetNode) ' It finds the object in this collection that has the ISPFFileComposition idef on it

lobjServerReq.Execute()

'

' Get the Vault from the reply

'

Dim lnodContainer As XmlNode = lobjServerReq.Response.SelectSingleNode("/Reply/Container")

Dim lobjContainer As IObjectDictionary = pobjWindowsFormsClient.SPFSession.InstantiateContainer(lnodContainer)

lobjVault = lobjContainer(0)

'

' Cast the file object so you can call the method on it

'

Dim lobjISPFFile As ISPFFile = CType(lobjFileResult.File.Interfaces("ISPFFile"), ISPFFile)

lobjISPFFile.UploadToLocalFileService(lobjVault)

'

' Create rel to the document object

'

Dim lobjIRel As IRel = SPF.Client.Schema.Utilities.CreateRel(pobjWindowsFormsClient.SPFSession, "SPFFileComposition", lobjISPFFile.IObject, lobjDocVersion)

lobjDocs.Add(lobjIRel.IObject)

'

' Add the file vault rel as well

'

Dim lobjFileVaultRel As IRel = SPF.Client.Schema.Utilities.CreateRel(pobjWindowsFormsClient.SPFSession, "SPFFileVault", lobjISPFFile.IObject, lobjVault)

lobjDocs.Add(lobjFileVaultRel.IObject)

'

' Now call commit to send everything to the server.

'

lobjDocs.Commit()

End If