Imports SolidEdgeAssembly
Imports SolidEdgeFramework
Imports System.Text
Imports System.IO
Imports System.Runtime.InteropServices.ComTypes
Imports System.Runtime.InteropServices
Class TemplateName
'Event set object
Implements SolidEdgeFramework.ISEBeforeFileSaveAsEvents
'Flag to ensure correct event handler operation
Private objApp As Application
Private objAsmDoc As AssemblyDocument
Private _connectionPoints As New Dictionary(Of IConnectionPoint, Integer)()
Dim objFolder As DirectoryInfo
Dim objFileInfo As FileInfo
Sub Main1()
Try
'To start SolidEdge application
objApp = Activator.CreateInstance(Type.GetTypeFromProgID("SolidEdge.Application"))
If IsNothing(objApp) Then
Throw New Exception("Failed to get Application object")
End If
objApp.Visible = True
objFolder = GetTrainingFolder()
objFileInfo = New FileInfo(System.IO.Path.Combine(objFolder.FullName, "carrier.asm"))
'To open Assembly Document
objAsmDoc = objApp.Documents.Open(objFileInfo.FullName) '"C:\Program Files\Solid Edge ST8\Training\carrier.asm")
If IsNothing(objAsmDoc) Then
Throw New Exception("Failed to get Assembly Document object")
End If
'Instantiate the event set object.
Dim connectionPointContainer As IConnectionPointContainer = Nothing
Dim connectionPoint As IConnectionPoint = Nothing
Dim cookie As Integer = 0
connectionPointContainer = TryCast(objApp, IConnectionPointContainer)
If connectionPointContainer IsNot Nothing Then
connectionPointContainer.FindConnectionPoint(GetType(SolidEdgeFramework.ISEBeforeFileSaveAsEvents).GUID, connectionPoint)
If connectionPoint IsNot Nothing Then
connectionPoint.Advise(Me, cookie)
If cookie <> 0 Then
_connectionPoints.Add(connectionPoint, cookie)
Else
Throw New System.Exception("Advisory connection between the connection point and the caller's sink object failed.")
End If
Else
Throw New System.Exception(String.Format("Connection point '{0}' not found.", GetType(SolidEdgeFramework.ISEBeforeFileSaveAsEvents).GUID))
End If
Else
Throw New System.Exception("Source does not implement IConnectionPointContainer.")
End If
Catch ex As Exception
Console.WriteLine(ex.Message)
Finally
Console.WriteLine("Click Create Part In-Place command to hit for next event ..")
Console.ReadKey()
objApp.Quit()
objApp = Nothing
End Try
End Sub
Sub OnBeforeFileSaveAsUI(TemplatePath As String) Implements SolidEdgeFramework.ISEBeforeFileSaveAsEvents.OnBeforeFileSaveAsUI
Dim sb As New StringBuilder()
sb.AppendFormat("{0}({1})", "OnbeforeFileSave", Templatepath)
sb.AppendLine()
Console.WriteLine(sb.ToString)
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(System.IO.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
Module Module1
Sub Main()
Dim obj As TemplateName = New TemplateName
obj.Main1()
End Sub
End Module