Fire Notification After Adding a Mate Example (VBA)
This example shows how to fire a post-notify event when adding mates:
Main module
' ******************************************************************************
'
' Preconditions:
' (1)
Specified assembly document exists.
' (2)
Run the macro (press F5 and click Run).
' (3)
Interactively add a mate between two entities
' (Insert > Mate). For example, add
a lock mate
' between
the plate and cup.
'
' Postconditions:
' (1)
A mate is added between the selected entities.
' (2)
A message box informing you of a new mate being
' added
to the assembly is displayed. Close the
' message
box.
' (3)
Close the document.
'
' NOTE:
Because this assembly document is used by
' a
SOLIDWORKS online tutorial, do not save
' any
changes when closing the document.
'
' ******************************************************************************
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swAssemblyDoc As SldWorks.AssemblyDoc
Dim errorstatus As Long, warningstatus As Long
Dim swAssemblyDocEvents As Class1
Sub main()
Set swApp = Application.SldWorks
swApp.OpenDoc6
"C:\Program Files\SOLIDWORKS Corp\SOLIDWORKS\samples\tutorial\api\toaster_scene.sldasm",
swDocASSEMBLY, swOpenDocOptions_Silent, "", errorstatus, warningstatus
Set swModel = swApp.ActiveDoc
Set swAssemblyDoc = swModel
' Set up event
Set swAssemblyDocEvents = New Class1
Set swAssemblyDocEvents.swAssemblyDoc = swApp.ActiveDoc
End Sub
Class module
Option Explicit
Public WithEvents swAssemblyDoc As SldWorks.AssemblyDoc
'Send message after a mate is added
Private Function swAssemblyDoc_AddMatePostNotify()
As Long
MsgBox
"A mate has been added to this assembly."
End Function