Undo Deleted Note and Fire Undo Pre- and Post-notify Events Example
(VBA)
This example demonstrates firing Undo pre- and post-notifications in
a drawing document.
Module
'
---------------------------------------------------------------------------
' Preconditions: Open:
' <SolidWorks_install_dir>\samples\tutorial\driveworksxpress\mobile gantry.slddrw.
'
' The
right-side note in Drawing View 3 is selected and then deleted.
' The
latter action is then undone and pre- and post-notification
' events
are fired indicating that an undo action is about to occur
' and
has occurred.
'
' Postconditions: None
'
---------------------------------------------------------------------------
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim swDrawing As SldWorks.DrawingDoc
Dim boolstatus As Boolean
Dim swDrawingEvents As Class1
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swModelDocExt = swModel.Extension
' Event notification
Set swDrawing = swModel
Set swDrawingEvents = New Class1
Set swDrawingEvents.swDrawing = swApp.ActiveDoc
' Activate the drawing view that contains
' the note you want to delete
boolstatus = swDrawing.ActivateView("Drawing
View3")
boolstatus = swModelDocExt.SelectByID2("DetailItem77@Drawing
View3", "NOTE", 0.3058741216774, 0.1870419466786, 0, False,
0, Nothing, 0)
' Delete the selected note
swModel.EditDelete
' Undo deletion of note
' Pre- and post-notifications
' are fired
swModel.EditUndo2
1
' Rebuild the drawing
swModel.ForceRebuild3
True
End Sub
Class Module
Option Explicit
Public WithEvents swDrawing As SldWorks.DrawingDoc
Private Function swDrawing_UndoPostNotify()
As Long
'Display message after undo action occurs
MsgBox
"An Undo post-notification event has been fired."
End Function
Private Function swDrawing_UndoPreNotify()
As Long
'Display message after undo action occurs
MsgBox
"An Undo pre-notification event has been fired."
End Function