Imports System.IO
Imports System.Runtime.InteropServices
Module Example
<STAThread()> _
Sub Main()
Dim objTrainingFolder As DirectoryInfo
Dim objApplication As SolidEdgeFramework.Application = Nothing
Try
OleMessageFilter.Register()
objTrainingFolder = GetTrainingFolder()
objApplication = Activator.CreateInstance(Type.GetTypeFromProgID("SolidEdge.Application"))
objApplication.Visible = True
OpenSolidEdgeDocument(objApplication, Path.Combine(objTrainingFolder.FullName, "bar.par"))
OpenAssemblyWithConfiguration(objApplication, Path.Combine(objTrainingFolder.FullName, "Try It\BrakePedalAssy.asm"), "default,rkriggs")
Catch ex As Exception
Console.WriteLine(ex.Message)
Finally
OleMessageFilter.Revoke()
End Try
End Sub
Sub OpenSolidEdgeDocument(ByVal objApplication As SolidEdgeFramework.Application, ByVal path As String)
Dim objDocuments As SolidEdgeFramework.Documents
Dim objDocument As SolidEdgeFramework.SolidEdgeDocument
Dim objAssemblyDocument As SolidEdgeAssembly.AssemblyDocument
Dim objDraftDocument As SolidEdgeDraft.DraftDocument
Dim objPartDocument As SolidEdgePart.PartDocument
Dim objSheetMetalDocument As SolidEdgePart.SheetMetalDocument
Dim objWeldmentDocument As SolidEdgePart.WeldmentDocument
objDocuments = objApplication.Documents
objDocument = objDocuments.Open(path)
Select Case objDocument.Type
Case SolidEdgeFramework.DocumentTypeConstants.igAssemblyDocument
objAssemblyDocument = objDocument
Case SolidEdgeFramework.DocumentTypeConstants.igDraftDocument
objDraftDocument = objDocument
Case SolidEdgeFramework.DocumentTypeConstants.igPartDocument
objPartDocument = objDocument
Case SolidEdgeFramework.DocumentTypeConstants.igSheetMetalDocument
objSheetMetalDocument = objDocument
Case SolidEdgeFramework.DocumentTypeConstants.igUnknownDocument
' Handle case
Case SolidEdgeFramework.DocumentTypeConstants.igWeldmentAssemblyDocument
' Weldment Assembly Document
Case SolidEdgeFramework.DocumentTypeConstants.igWeldmentDocument
objWeldmentDocument = objDocument
End Select
End Sub
Sub OpenAssemblyWithConfiguration(ByVal objApplication As SolidEdgeFramework.Application, ByVal path As String, ByVal configurationName As String)
Dim objDocuments As SolidEdgeFramework.Documents
Dim objAssemblyDocument As SolidEdgeAssembly.AssemblyDocument
Dim sFileName As String
Dim iOverride As Integer
iOverride = 0 'No assembly override (default)
'iOverride = 1 'Override configuration: all parts active
'iOverride = 2 'Override configuration: all parts inactive
'The Filename parameter can optionally contain newline characters to separate additional information: a configuration name and configuration overrides.
sFileName = String.Format("{0}{1}{2}{3}{4}", path, vbLf, configurationName, vbLf, iOverride)
objDocuments = objApplication.Documents
objAssemblyDocument = objDocuments.Open(sFileName)
End Sub
Function GetTrainingFolder() As DirectoryInfo
Dim objInstallData As SEInstallDataLib.SEInstallData = Nothing
Dim objInstallFolder As DirectoryInfo = Nothing
Dim objTrainingFolder As DirectoryInfo = Nothing
Try
objInstallData = New SEInstallDataLib.SEInstallData
objInstallFolder = New DirectoryInfo(objInstallData.GetInstalledPath())
objTrainingFolder = New DirectoryInfo(Path.Combine(objInstallFolder.Parent.FullName, "Training"))
Catch
Finally
If Not (objInstallData Is Nothing) Then
Marshal.FinalReleaseComObject(objInstallData)
objInstallData = Nothing
End If
End Try
Return objTrainingFolder
End Function
End Module