MACRO LIBRARY

Notify user when a specific feature is created

Free public access. No account or subscription required.

Files

Notify user when a specific feature is created

Code

Module: mMain

'Notifies user when a flange feature is added.
    
'Preconditions: part is open
    
'Written by Keith Rice
'CADSharp LLC
'www.cadsharp.com
    
Public listener As AddItemNotifyListener
    
Sub main()
    Set listener = New AddItemNotifyListener
    listener.connect
End Sub
    
'Note that if you want to kill the listener object in the class module after certain _
    code has been triggered, you cannot auto-instantiate the listener object

Class: AddItemNotifyListener

Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim WithEvents swPart As SldWorks.PartDoc
    
Sub connect()
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Set swPart = swModel
    Debug.Print "listening"
End Sub
    
Private Function swPart_AddItemNotify(ByVal EntityType As Long, ByVal itemName As String) As Long
    If InStr(1, itemName, "Flange") <> 0 Then Debug.Print "Flange was added"
    Set listener = Nothing
End Function