MACRO LIBRARY

Delete balloons attached to fasteners

Free public access. No account or subscription required.

Files

Delete balloons attached to fasteners

Code

'This macro deletes balloons attached to fasteners in the selected drawing view
    
'Preconditions: drawing view containing balloons is selected and a search string used to _
    identify the folder location of toolbox parts is specified as SEARCH_STRING
    
'Written by Keith Rice
'CADSharp LLC
'www.cadsharp.com
    
Const SEARCH_STRING As String = "c:\solidworks data"
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swView As SldWorks.View
Dim vAnns As Variant
Dim swAnn As SldWorks.Annotation
Dim vAttachedEnts As Variant
Dim swEnt As SldWorks.Entity
Dim swComp As SldWorks.Component2
Dim swCompModel As SldWorks.ModelDoc2
Dim i As Integer
    
Sub main()
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Set swSelMgr = swModel.SelectionManager
    Set swView = swSelMgr.GetSelectedObject6(1, -1)
    vAnns = swView.GetAnnotations
    For i = 0 To UBound(vAnns)
        Set swAnn = vAnns(i)
        If swAnn.GetType = swNote Then
            vAttachedEnts = swAnn.GetAttachedEntities3
            If IsEmpty(vAttachedEnts) = False Then
                Set swEnt = vAttachedEnts(0)
                Set swComp = swEnt.GetComponent
                Set swCompModel = swComp.GetModelDoc2
                'Debug.Print swCompModel.GetPathName    'used to examine toolbox part paths
                If LCase(Left(swCompModel.GetPathName, 18)) = LCase(SEARCH_STRING) Then
                    swAnn.Select3 False, Nothing
                    swModel.EditDelete
                End If
            End If
        End If
    Next i
End Sub