Undo Hidden Component and Fire Undo Post-Notify Event Example (VBA)
This example demonstrates firing an undo post-notification event in
an assembly document.
Module
'
--------------------------------------------------------------------------
' Preconditions: Open:
' <SolidWorks_install_dir>\samples\tutorial\smartcomponents\stepped_shaft.sldasm
'
' The
base-plate<1> component is selected and then hidden.
' The
latter action is then undone and a post-notification
' event
is fired indicating that an undo action has occurred.
'
' Postconditions: None
'
--------------------------------------------------------------------------
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim swAssembly As SldWorks.AssemblyDoc
Dim boolstatus As Boolean
Dim swAssemblyEvents As Class1
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swModelDocExt = swModel.Extension
' Event notification
Set swAssembly = swModel
Set swAssemblyEvents = New Class1
Set swAssemblyEvents.swAssembly = swApp.ActiveDoc
' Select a component and hide it
boolstatus = swModelDocExt.SelectByID2("base_plate-1@stepped_shaft",
"COMPONENT", 0, 0, 0, False, 0, Nothing, 0)
swModel.HideComponent2
swModel.ClearSelection2
True
' Undo hiding of the component
swModel.EditUndo2
1
' Post-notification event is fired
'Rebuild the assembly
swModel.ForceRebuild3
True
End Sub
Class module
Option Explicit
Public WithEvents swAssembly As SldWorks.AssemblyDoc
Private Function swAssembly_UndoPostNotify()
As Long
'Display message after undo action occurs
MsgBox
"An undo post-notification event has been fired."
End Function