Imports System.IO
Imports System.Runtime.InteropServices
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim objApplication As SolidEdgeFramework.Application = Nothing
Dim SEInstallDir As DirectoryInfo
Dim objAssemblyDocument As SolidEdgeAssembly.AssemblyDocument = Nothing
Dim objAsmPatterns As SolidEdgeAssembly.AssemblyPatterns = Nothing
Dim objAsmPattern As SolidEdgeAssembly.AssemblyPattern = Nothing
Dim PartsToPattern(3) As Object
Dim ToOccurrences(2) As Object
Dim FromOccurrence As Object
Try
' Create/get the application with specific settings
objApplication = Marshal.GetActiveObject("SolidEdge.Application")
SEInstallDir = GetTrainingFolder()
' open the document.
objAssemblyDocument = objApplication.Documents.Open(SEInstallDir.FullName + "\carrier.asm")
PartsToPattern(0) = objAssemblyDocument.Occurrences.Item(1)
ToOccurrences(0) = objAssemblyDocument.Occurrences.Item(4)
objAsmPatterns = objAssemblyDocument.AssemblyPatterns
FromOccurrence = objAssemblyDocument.Occurrences.Item(3)
objAsmPattern = objAsmPatterns.CreateDuplicate("Duplicate Test", 1, PartsToPattern, FromOccurrence, 1, ToOccurrences)
Dim msg = MsgBox("Do you want to edit this duplicate Component?", MsgBoxStyle.YesNo, "Create Duplicate")
If msg = MsgBoxResult.Yes Then
objAsmPattern.EditDuplicate(1, PartsToPattern, FromOccurrence, 1, ToOccurrences, "Rename Duplicate")
End If
objAssemblyDocument.UpdatePathfinder(SolidEdgeAssembly.AssemblyPathfinderUpdateConstants.seRebuild)
Catch ex As Exception
MsgBox(Err.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