Delete all properties for the active configuration – SOLIDWORKS MACRO

Amen Jlili

The following macro deletes all the properties from the active configuration. The macro is written used late-binding so it is version independent. The deletion action requires confirmation by the user.

' 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

Problems running the macro? Report a bug here.

More great articles

Crack any SOLIDWORKS password-protected VBAmacro with screenshots

Disclaimer: The information shared in this article is intended to show how easy it is to unlock the password protection…

Read Story

A PDM race condition: How your code might wrestle with PDM when saving files directly to the vault — and what to do about it.

A race condition may occur when two instructions are executed at the same time. The output gets determined by which…

Read Story
SOLIDWORKS VBA vs SOLIDWORKS .NET

Top reasons to upgrade your VBA macros in 2020

Converting a SOLIDWORKS VBA macro to an add-in. VBA macros continue to be the choice of the SOLIDWORKS community for…

Read Story
Arrow-up
×