Imports System.Runtime.InteropServices
Imports System.IO
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim objSEApplication As SolidEdgeFramework.Application = Nothing
Dim objDocuments As SolidEdgeFramework.Documents = Nothing
Dim objAssemblyDoc As SolidEdgeAssembly.AssemblyDocument = Nothing
Dim objPart As SolidEdgeAssembly.Occurrence = Nothing
Dim objSubOcc As SolidEdgeAssembly.SubOccurrence = Nothing
Dim bFileMissingArray() As Boolean
Dim objFolder As DirectoryInfo
Dim objFileInfo As FileInfo
Dim index As Integer
Dim i As Integer
Try
objFolder = GetTrainingFolder()
objFileInfo = New FileInfo(Path.Combine(objFolder.FullName, "Coffee Pot.asm"))
objSEApplication = Marshal.GetActiveObject("SolidEdge.Application")
If objSEApplication Is Nothing Then
objSEApplication = Activator.CreateInstance(Type.GetTypeFromProgID("SolidEdge.Application"))
objSEApplication.Visible = True
End If
objDocuments = objSEApplication.Documents
' opening an existing assembly file.
objAssemblyDoc = objDocuments.Open(objFileInfo.FullName)
ReDim bFileMissingArray(objAssemblyDoc.Occurrences.Count + 1)
' getting a part in the assembly
For index = 1 To objAssemblyDoc.Occurrences.Count
objPart = objAssemblyDoc.Occurrences.Item(index)
bFileMissingArray(index - 1) = objPart.FileMissing
If (objPart.Type = SolidEdgeFramework.ObjectType.igSubAssembly) Then
For i = 1 To objPart.SubOccurrences.Count
objSubOcc = objPart.SubOccurrences.Item(i)
bFileMissingArray(index + i - 1) = objSubOcc.FileMissing
Next i
End If
Next index
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
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 Class