INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Member Login

HANDLE


PASSWORD
Remember Me
Forgot Password?

Come Join Us!

  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • Turn Off Ad Banners
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

E-mail*
Handle

Password
Verify P'word
*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Member Feedback

"...Your site is one of the cleanest and BEST forums that I have seen. I have sent quite a few people your way. Keep up the good work!!!"

Geography

Where in the world do Eng-Tips members come from?

API and Macros

Remove Dangling Drawing Entities
Posted: 14 Nov 01 (Edited 9 Jun 04)

For those of you that pre-configure assemblies and drawings, you may have encountered this problem. Let's say you have a template assembly with 10 parts and a master drawing template for that assembly. If, for a particular job, you need to remove (or supress) 3 items from the assembly, you will notice that some dimensions, annotations and weld symbols may be left dangling on your master drawing template. These can take some time to delete if the drawing is quite large or if it's based on a large master assembly.

Here is some code you can insert into a macro file and link to a macro button. This will automatically remove all of the dangling items. The only problem is that it will not work on section views. This lies in the fact that the View.Name property returns the name shown in the Feature Manager Design Tree, while the value of the items use the name format "Drawing ViewX".

CODE

'<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
'  Utility - Remove Dangling Dimensions, Annotations and Weld Symbols
'
'  Written by:  Dimensional Solutions, Inc.
'               DimensionalSoutions@core.com
'<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
Option Explicit

Const swSelNOTHING = 0

Sub main()
    Dim swApp As Object
    Dim Part As Object
    Dim dwgView As Object
    Dim dispDimension As Object
    Dim dwgDimension As Object
    Dim dwgNote As Object
    Dim dwgWeld As Object
    Dim dwgAnnotation As Object
    Dim attachedEntitiesArray As Variant
    Dim attachedEntityTypes As Variant
    Dim bRemoveLastFlag As Boolean
    Dim s1 As String
    Dim sViewName As String, sDwgName As String
    
    Set swApp = CreateObject(&quot;SldWorks.Application&quot;)
    Set Part = swApp.ActiveDoc
 
    Set dwgView = Part.GetFirstView     'this is the drawing template
    
    Do While Not dwgView Is Nothing
        'Travserse Through the Dimensions
        Set dwgView = dwgView.GetNextView
        If Not dwgView Is Nothing Then
            sViewName = dwgView.Name
            'Travserse through all of the dimensions in this view
            Set dispDimension = dwgView.GetFirstDisplayDimension3
            Do While Not dispDimension Is Nothing
                Set dwgDimension = dispDimension.GetDimension
                bRemoveLastFlag = False
                If dwgDimension.Value = 0 Then
                    'Delete the Dimension
                    If InStr(1, dwgDimension.FullName, &quot;Annotations&quot;) Then
                        'The next dimension must be selected before this one can be removed
                        bRemoveLastFlag = True
                        s1 = dwgDimension.Name & &quot;@&quot; & sViewName
                    End If
                End If
                Set dispDimension = dispDimension.GetNext3
                If bRemoveLastFlag = True Then
                    Part.SelectByID s1, &quot;DIMENSION&quot;, 0, 0, 0
                    Part.DeleteSelection False
                    bRemoveLastFlag = False
                End If
            Loop
            'Travserse through all of the reference dimensions in this view
            Set dispDimension = dwgView.GetFirstDisplayDimension3
            Do While Not dispDimension Is Nothing
                Set dwgAnnotation = dispDimension.GetAnnotation
                'Only allow this to act on Reference Dimensions
                If dwgAnnotation.GetName Like &quot;RD*&quot; Then
                    attachedEntitiesArray = dwgAnnotation.GetAttachedEntities
                    attachedEntityTypes = dwgAnnotation.GetAttachedEntityTypes
                    If IsEmpty(attachedEntitiesArray) _
                     Or IsNull(attachedEntitiesArray) Then
                        'Delete the Ref Dim -  next one must be selected before this on can be removed
                        bRemoveLastFlag = True
                        s1 = dwgAnnotation.GetName & &quot;@&quot; & dwgView.Name
                    ElseIf attachedEntityTypes(0) = swSelNOTHING _
                     Or attachedEntitiesArray(0) Is Nothing Then        'Dangling
                        'Delete the Ref Dim -  next one must be selected before this on can be removed
                        bRemoveLastFlag = True
                        s1 = dwgAnnotation.GetName & &quot;@&quot; & dwgView.Name
                    ElseIf (UBound(attachedEntitiesArray) + 1) >= 2 Then '(# of attached items)
                        If attachedEntityTypes(1) = swSelNOTHING _
                        Or attachedEntitiesArray(1) Is Nothing Then        'Dangling
                            'Delete the Ref Dim -  next one must be selected before this on can be removed
                            bRemoveLastFlag = True
                            s1 = dwgAnnotation.GetName & &quot;@&quot; & dwgView.Name
                        End If
                    Else
                        'Attached
                    End If
                End If
                Set dispDimension = dispDimension.GetNext3
                If bRemoveLastFlag = True Then
                    Part.SelectByID s1, &quot;DIMENSION&quot;, 0, 0, 0
                    Part.DeleteSelection False
                    bRemoveLastFlag = False
                End If
            Loop
            'Traverse through all of the notes in this drawing view
            Set dwgNote = dwgView.GetFirstNote
            Do While Not dwgNote Is Nothing
                Set dwgAnnotation = dwgNote.GetAnnotation
                bRemoveLastFlag = False
                attachedEntitiesArray = dwgAnnotation.GetAttachedEntities
                attachedEntityTypes = dwgAnnotation.GetAttachedEntityTypes
                If IsEmpty(attachedEntitiesArray) _
                 Or IsNull(attachedEntitiesArray) Then
                    'Not Attached (And Never Was)
                ElseIf attachedEntityTypes(0) = swSelNOTHING _
                 Or attachedEntitiesArray(0) Is Nothing Then        'Dangling
                    'Delete the Note
                    'The next note must be selected before this on can be removed
                    bRemoveLastFlag = True
                    s1 = dwgNote.GetName & &quot;@&quot; & sViewName
                Else
                    'Attached
                End If
                Set dwgNote = dwgNote.GetNext
                If bRemoveLastFlag = True Then
                    Part.SelectByID s1, &quot;NOTE&quot;, 0, 0, 0
                    Part.DeleteSelection False
                    bRemoveLastFlag = False
                End If
            Loop
            'Traverse through all of the welds in this drawing view
            Set dwgWeld = dwgView.GetFirstWeldSymbol
            Do While Not dwgWeld Is Nothing
                Set dwgAnnotation = dwgWeld.GetAnnotation
                bRemoveLastFlag = False
                attachedEntitiesArray = dwgAnnotation.GetAttachedEntities
                attachedEntityTypes = dwgAnnotation.GetAttachedEntityTypes
                If IsEmpty(attachedEntitiesArray) _
                 Or IsNull(attachedEntitiesArray) Then
                    'Not Attached (And Never Was)
                ElseIf attachedEntityTypes(0) = swSelNOTHING _
                 Or attachedEntitiesArray(0) Is Nothing Then        'Dangling
                    'Delete the Note
                    'The next note must be selected before this one can be removed
                    bRemoveLastFlag = True
                    s1 = dwgAnnotation.GetName & &quot;@&quot; & sViewName
                Else
                    'Attached
                End If
                Set dwgWeld = dwgWeld.GetNext
                If bRemoveLastFlag = True Then
                    Part.SelectByID s1, &quot;WELD&quot;, 0, 0, 0
                    Part.DeleteSelection False
                    bRemoveLastFlag = False
                End If
            Loop
        End If
    Loop
    Set swApp = Nothing
    Set Part = Nothing
    Set dwgView = Nothing
    Set dispDimension = Nothing
    Set dwgDimension = Nothing
    Set dwgNote = Nothing
    Set dwgWeld = Nothing
    Set dwgAnnotation = Nothing
    MsgBox &quot;Done!&quot;
End Sub

Back to SolidWorks 3D CAD products FAQ Index
Back to SolidWorks 3D CAD products Forum
My FAQ Archive
Email This FAQ To A Friend

My Archive