Fire Notification After Adding a Mate Example (VB.NET)
This example shows how to fire a post-notify event when adding mates.
' ******************************************************************************
'
' Preconditions:
' (1)
Specified assembly document exists.
' (2)
The Tools > Options > Stop VSTA
debugger on macro exit
' checkbox
is not selected.
' (2)
Run this macro in debug mode (press F5).
' (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. Check the
' taskbar
for the message box.
' (3)
Close the message box.
' (4)
Close the document.
'
' NOTE:
Because this assembly document is used by
' a
SOLIDWORKS online tutorial, do not save
' any
changes when closing the document.
'
' (5)
Stop the macro by clicking Debug >
Stop Debugging.
'
' ******************************************************************************
Imports SolidWorks.Interop.sldworks
Imports SolidWorks.Interop.swconst
Imports System
Imports System.Diagnostics
Imports System.Collections
Partial Class SolidWorksMacro
Public
WithEvents swAssemblyDoc As AssemblyDoc
Public
Sub Main()
Dim
swModel As ModelDoc2
Dim
errorstatus As Long, warningstatus As Long
Dim
openAssem As Hashtable
'
Open assembly document
swApp.OpenDoc6("C:\Program Files\SOLIDWORKS
Corp\SOLIDWORKS\samples\tutorial\api\toaster_scene.sldasm",
swDocumentTypes_e.swDocASSEMBLY, swOpenDocOptions_e.swOpenDocOptions_Silent,
"", errorstatus, warningstatus)
swModel
= swApp.ActiveDoc
'
Set up event
swAssemblyDoc
= swModel
openAssem
= New Hashtable
AttachEventHandlers()
End
Sub
Sub
AttachEventHandlers()
AttachSWEvents()
End
Sub
Sub
AttachSWEvents()
AddHandler
swAssemblyDoc.AddMatePostNotify, AddressOf Me.swAssemblyDoc_AddMatePostNotify
End
Sub
Private
Function swAssemblyDoc_AddMatePostNotify()
As Integer
'
Display message after user interactively adds a mate
MsgBox("A
mate has been added to the assembly.")
End
Function
'''
<summary>
'''
The SldWorks swApp variable is pre-assigned for you.
'''
</summary>
Public
swApp As SldWorks
End Class