6 Replies Latest reply on Jul 27, 2015 9:33 AM by Anand Dharwa

    Delete dangling dimensions

    Rafi Sokol

      I need a procedure to delete all dangling dimensions in all the views of an active drawing.

        • Re: Delete dangling dimensions
          Deepak Gupta

          Check swDim.IsDangling

            • Re: Delete dangling dimensions
              Rafi Sokol

              This is correct, but how do I collect all the dimensions, to find out which are dangling?

                • Re: Delete dangling dimensions
                  Adam Hoffman

                  This is one I wrote for myself to do notes and dimensions. Edit however you like:

                   

                   

                  ' ****************************************************************************** '
                  '                            Clean Up Drawing Macro                              '
                  ' ****************************************************************************** '


                  'Macro will traverse through all drawing views
                  'and delete dangling dimensions and notes

                   

                  'Written by Adam Hoffman
                  'Was written using SolidWorks 2014 SP 2.0
                  'This macro is provided as is and the creator is not responsible for any mishaps

                   

                   

                  Dim swApp As SldWorks.SldWorks
                  Dim swModel As SldWorks.ModelDoc2
                  Dim swDraw As SldWorks.DrawingDoc
                  Dim swSelMgr As SldWorks.SelectionMgr

                  Dim swView As SldWorks.View

                  Dim swAnno As SldWorks.Annotation
                  Dim sAnnoType As String
                  Dim swNote As SldWorks.Note


                  Dim bSelect As Boolean
                  Dim bDeleteFlag As Boolean
                  Dim sItemName As String

                  Const swDrawingDoc = 3
                  Const swAssemblyDoc = 2
                  Const swPartDoc = 1


                  Sub CleanUpMain()

                  Set swApp = Application.SldWorks

                  Set swModel = swApp.ActiveDoc

                  'If the active document is not a drawing exit program
                  If Not swModel.GetType() = swDrawingDoc Then

                     MsgBox ("You Must Run This Macro Inside Of A Drawing!")
                     Exit Sub
                    
                  ElseIf swModel.GetType() = swDrawingDoc Then

                     Set swDraw = swModel
                    
                  End If


                  swModel.ClearSelection2 (True) 'Make sure all selections are cleared before you start
                  bDeleteFlag = False

                  Set swView = swDraw.GetFirstView 'This is the overall drawing itself

                  Set swView = swView.GetNextView 'This is the actual first view in the drawing


                  'Start the loop through views in the drawing
                  Do While Not swView Is Nothing

                     'Start the dangling Note removal
                     Set swNote = swView.GetFirstNote
                    
                     Do While Not swNote Is Nothing
                    
                        sItemName = ""
                        sItemName = swNote.GetName()
                       
                        Dim sNoteText As String
                        sNoteText = ""
                       
                        sNoteText = swNote.GetText()
                       
                        'I found when dealing with notes this was more reliable
                        'than using the swAnno.IsDangling method
                        If sNoteText = "?" Or sNoteText = "" Then
                    
                           bSelect = swModel.Extension.SelectByID2(sItemName + "@" + CStr(swView.Name), "NOTE", 0, 0, 0, True, 0, Nothing, 0)
                          
                           bDeleteFlag = True
                          
                        End If
                    
                        Set swNote = swNote.GetNext
                    
                     Loop
                    
                     If bDeleteFlag = True Then
                    
                        'After going through all the notes in this view delete the ones that have been selected
                        boolstatus = swModel.Extension.DeleteSelection2(2)
                       
                     End If
                    
                     'End of dangling Note removal
                    
                     swModel.ClearSelection2 (True)
                     bDeleteFlag = False
                     boolstatus = False
                       
                     'Start the dangling dimension removal
                     Set swAnno = swView.GetFirstAnnotation3()
                    
                     Do While Not swAnno Is Nothing
                      
                       If swAnno.GetType = 4 Then
                         
                           sItemName = ""
                          
                           If swAnno.IsDangling Then

                              sItemName = swAnno.GetName()
                          
                              bSelect = swModel.Extension.SelectByID2(sItemName + "@" + CStr(swView.Name), "DIMENSION", 0, 0, 0, True, 0, Nothing, 0)
                              bDeleteFlag = True
                          
                           End If
                          
                        End If
                       
                        Set swAnno = swAnno.GetNext3()
                       
                     Loop
                    
                     If bDeleteFlag = True Then
                    
                        'After going through all the dimensions in this view delete the ones that have been selected
                        boolstatus = swModel.Extension.DeleteSelection2(2)
                       
                     End If
                    
                     'End of dangling dimension removal
                    

                     Set swView = swView.GetNextView

                  Loop 'End of loop through drawing views and overall program


                  End Sub