Products
Handling Assembly Change Events
This blog will be focusing on the usage of newly introduced enumerations in Solid Edge when handling assembly change events. We identified frequent scenarios by our automation users and added the following seAssemblyChangeEventsConstants Enumeration in SE2021MP1. These enums will be useful for automation users in several cases including:
- seAssemblyOccurrenceAdd : This enumeration will notify automation users when a new occurrence is added in an assembly.
- seAssemblyOccurrenceRemove : This enumeration will notify automation users when an occurrence is removed from an assembly.
- seAssemblyOccurrenceTransform : This enumeration will notify automation users when transform of an occurrence is changed (occurrence is moved\rotated) in an assembly.
- seAssemblySketchModify : This enumeration will notify automation users when the sketch in an assembly is modified. This will also return the sketch pointer.
- seAssemblyFeatureModify : This enumeration will notify automation users when an assembly feature is modified.
- seAssemblyOccurrenceGeomModify : This enumeration will notify automation users when geometry of an occurrence is modified.
In order to make use of these recently added enumerations, the user must be hooked up to AssemblyChangeEvents object. For better and quick understanding, I prepared below sample code to demonstrate the usage of AssemblyChangeEvents object.
Imports System.Runtime.InteropServices
Public Class Form1
Private _application As SolidEdgeFramework.Application
Private _assemblyDocument As SolidEdgeAssembly.AssemblyDocument
Private _assemblyChangeEvents As SolidEdgeFramework.ISEAssemblyChangeEvents_Event
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' Connect to a running instance of Solid Edge.
_application = DirectCast(Marshal.GetActiveObject("SolidEdge.Application"), SolidEdgeFramework.Application)
_assemblyDocument = CType(_application.ActiveDocument, SolidEdgeAssembly.AssemblyDocument)
' Connect to events using delegate event model.
_assemblyChangeEvents = CType(_assemblyDocument.AssemblyChangeEvents, SolidEdgeFramework.ISEAssemblyChangeEvents_Event)
' Attach to specific events.
AddHandler _assemblyChangeEvents.AfterChange, AddressOf _assemblyChangeEvents_AfterChange
AddHandler _assemblyChangeEvents.BeforeChange, AddressOf _assemblyChangeEvents_BeforeChange
End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As FormClosingEventArgs)
If _assemblyChangeEvents IsNot Nothing Then
' Dettach from specific events.
RemoveHandler _assemblyChangeEvents.BeforeChange, AddressOf _assemblyChangeEvents_BeforeChange
RemoveHandler _assemblyChangeEvents.AfterChange, AddressOf _assemblyChangeEvents_AfterChange
End If
_assemblyDocument = Nothing
_assemblyChangeEvents = Nothing
_application = Nothing
End Sub
Private Sub _assemblyChangeEvents_BeforeChange(ByVal theDocument As Object, ByVal obj1 As Object, ByVal Type As SolidEdgeFramework.ObjectType, <ComAliasName("SolidEdgeFramework.seAssemblyChangeEventsConstants")> ByVal ChangeType As SolidEdgeFramework.seAssemblyChangeEventsConstants)
' Handle BeforeChange.
Dim str1 As String = obj1.name.ToString
MsgBox(String.Format("_assemblyChangeEvents_BeforeChange: The object is {0} and the type is {1} and {2} and the ID is", str1, Type, ChangeType))
End Sub
Private Sub _assemblyChangeEvents_AfterChange(ByVal theDocument As Object, ByVal obj1 As Object, ByVal Type As SolidEdgeFramework.ObjectType, <ComAliasName("SolidEdgeFramework.seAssemblyChangeEventsConstants")> ByVal ChangeType As SolidEdgeFramework.seAssemblyChangeEventsConstants)
' Handle AfterChange.
Dim str1 As String = obj1.name.ToString
MsgBox(String.Format("_assemblyChangeEvents_AfterChange: The object is {0} and the type is {1} and {2} and the ID is ", str1, Type, ChangeType))
End Sub
End Class
Comments