US$0.00
0

A Simple Macro for All SolidWorks Delete Dangling Dimensions Automated!

Reattaching Dangling Dimensions - 2024 - What's New in SOLIDWORKS

If you’ve been working a while in SOLIDWORKS, you know the drill. You open a drawing, and there they are: those hanging, useless dimensions that lost their reference points. They’re referred to as dangling dimensions, and one or two will not hurt anything, but a whole group can take a neat drawing and make it into a confusing mess. They’re not just visual eyesores; they’re an early symptom of unwanted errors.

But what if you could nuke them all in one click? Well… now you can, by following along with this guide. This guide is going to explore a simple macro for all SolidWorks delete dangling dimensions. You can utilize a simple, convenient macro that addresses this very problem by zapping all your dangling dimensions for you.

Key Features

  • Deletes all dangling dimensions from active drawings.
  • Works with any SOLIDWORKS version, thanks to late-binding.
  • User confirmation required before deletion.

How The Macro Works Behind the Scenes?

The VBA macro follows a clear, logical route to make sure that it only targets what you want it to. Here’s a step-by-step breakdown of how it works:

  • It Checks for the Document: It first checks whether the current document is a drawing. If you have something open like an assembly or a part, it will warn you and terminate, so you don’t even use it where it shouldn’t be used. This is also a good thing to keep in mind if you ever wonder how to cancel macros inc before they land you in trouble.
  • It Scans for Dangles: The macro searches every view in your drawing, looking for any annotations SOLIDWORKS has tagged as “dangling.” It only calls out those dimensions that have lost their reference.
  • It Asks for Authorization: You get a message of approval prior to deletion being done. That is your final chance to approve the action and prevent modifications from being inadvertently made, which is really a great safety feature, especially if you are working on something intricate and would like to prevent modifications from being made by accident, as if you have to delete configuration SolidWorks drawings in a particular way.
  • It’s Version-Agnostic: Because it uses late-binding, the macro does not use explicit references and works perfectly across different versions without your involvement in code.es and works perfectly across different versions without your involvement in code.

Code:

' Delete all dangling dimensions
' Conditions = Active document must be drawing
' Results = Dangling dimensions deleted
' www.bluebyte.biz
Dim swApp           As Object
Dim swModel         As Object
Dim swDraw          As Object
Dim swSheet         As Object
Dim swView          As Object
Dim boolstatus      As Boolean
Dim swAnn           As Object
Dim swDispDim       As Object
Dim vSheetNames     As Variant

Public Enum swDocumentTypes_e

    swDocNONE = 0       '  Used to be TYPE_NONE

    swDocPART = 1       '  Used to be TYPE_PART

    swDocASSEMBLY = 2   '  Used to be TYPE_ASSEMBLY

    swDocDRAWING = 3    '  Used to be TYPE_DRAWING

End Enum

Sub main()
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
     If swModel Is Nothing Then
        swApp.SendMsgToUser ("Macro failed because there is no active drawing document.")
    ElseIf swModel.GetType <> swDocumentTypes_e.swDocDRAWING Then
        swApp.SendMsgToUser ("Macro failed because active document is not a drawing.")
    Else
        Set swDraw = swModel
        swModel.ClearSelection2 (True)
        vSheetNames = swDraw.GetSheetNames
        For i = 0 To UBound(vSheetNames)
            swDraw.ActivateSheet vSheetNames(i)
            Set swSheet = swDraw.Sheet(vSheetNames(i))
            Set swView = swDraw.GetFirstView
            Do While Not swView Is Nothing
                Set swAnn = swView.GetFirstAnnotation3
                Do While Not swAnn Is Nothing
                    If swAnn.IsDangling Then
                        swAnn.Select2 True, -1
                    End If
                    Set swAnn = swAnn.GetNext3
                Loop
                Set swView = swView.GetNextView
            Loop
            boolstatus = swModel.DeleteSelection(True)
            If boolstatus Then
             swModel.ClearSelection2 (True)
            End If
        Next i
    End If
End Sub

Bottom Line

Should you need to automate your SOLIDWORKS workflows even further, from dimension management to automating other drawing processes, Blue Byte Systems Inc. is here to help. We specialize in custom add-ins and automation utilities designed to your specifications. Contact us today!

Author

Amen Jlili

Amen Jlili is the founder and technical director of Blue Byte Systems Inc., a software company in Vancouver, Canada, specializing in automating SOLIDWORKS and PDM. With over a decade of experience, he has authored several courses and open-source frameworks related to the SOLIDWORKS API. His leadership ensures that Blue Byte Systems prioritizes customer satisfaction and delivers high-quality software and CAD design solutions.
0
    0
    Your Cart
    Your cart is emptyReturn to Shop
    ×