Imports System.Runtime.InteropServices
Imports System.ComponentModel
Public Class SimplifiedAssemblyObject
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim objApplication As SolidEdgeFramework.Application = Nothing
Dim objAssy As SolidEdgeAssembly.AssemblyDocument = Nothing
Dim objSimpAssys As SolidEdgeAssembly.SimplifiedAssemblies = Nothing
Dim objSimpAssy As SolidEdgeAssembly.SimplifiedAssembly = Nothing
Dim objSimpModel As SolidEdgePart.SimplifiedAssemblyModel = Nothing
Dim objEnclosures As SolidEdgePart.Enclosures = Nothing
Dim objOccs As SolidEdgeAssembly.Occurrences = Nothing
Dim objOcc As SolidEdgeAssembly.Occurrence = Nothing
Dim objRef As SolidEdgeFramework.Reference = Nothing
Dim objEnc As SolidEdgePart.Enclosure = Nothing
Dim objSubOccs As SolidEdgeAssembly.SubOccurrences = Nothing
Dim objSubOcc As SolidEdgeAssembly.SubOccurrence = Nothing
Dim objModels As SolidEdgePart.Models = Nothing
Dim objModel As SolidEdgePart.Model = Nothing
Dim objConsts As SolidEdgePart.Constructions = Nothing
Dim objMRefPlanes As SolidEdgePart.RefPlanes = Nothing
Dim objMRefPlane As SolidEdgePart.RefPlane = Nothing
Dim objType As Type = Nothing
Dim occArray As System.Array = Array.CreateInstance(GetType(SolidEdgeFramework.Reference), 1)
Try
' Create/get the application with specific settings
objApplication = Marshal.GetActiveObject("SolidEdge.Application")
If objApplication Is Nothing Then
' Get the type from the Solid Edge ProgID
objType = Type.GetTypeFromProgID("SolidEdge.Application")
' Start Solid Edge
objApplication = Activator.CreateInstance(objType)
' Make Solid Edge visible
objApplication.Visible = True
End If
'Get reference to active document
objAssy = objApplication.ActiveDocument()
objOccs = objAssy.Occurrences
objOcc = objOccs.Item(1)
objSubOccs = objOcc.SubOccurrences
For Each subocc As SolidEdgeAssembly.SubOccurrence In objSubOccs
If (subocc.ThisAsOccurrence.Subassembly = False) Then
objSubOcc = subocc
End If
Next
objRef = objSubOcc.Reference
objRef = objAssy.CreateReference(objOcc, objSubOcc.ThisAsOccurrence)
occArray(0) = objRef
objSimpAssys = objAssy.SimplifiedAssemblies
objSimpAssy = objSimpAssys.Item(1)
objSimpModel = objSimpAssy.SimplifiedModel
objMRefPlanes = objSimpModel.RefPlanes
objMRefPlane = objMRefPlanes(1)
objModels = objSimpModel.Models
objModels.AddSimplifyEnclosure(1, occArray, objMRefPlane, SolidEdgePart.EnclosureTypeConstant.igEnclosureTypeBox, "body", objEnc)
objModel = objModels(0)
objEnclosures = objModel.Enclosures
MsgBox(objEnclosures.Count)
Catch ex As Exception
MsgBox(ex.ToString)
Finally
End Try
End Sub
End Class