<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to delete all block attributes from a block using vba in VBA Forum</title>
    <link>https://forums.autodesk.com/t5/vba-forum/how-to-delete-all-block-attributes-from-a-block-using-vba/m-p/6812495#M8371</link>
    <description>&lt;P&gt;Hi, after your post, I tried to find the way myself. here is the code that works.&lt;/P&gt;&lt;P&gt;Thank you for your help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Option Explicit
Sub ClearAtt()

    Dim objBlockRef As AcadBlockReference
    Dim objBlock As AcadBlock
    Dim objEntity As AcadEntity
    Dim objAttributes As AcadAttributeReference
    Dim AttList As Variant
    Dim I As Integer
    
    'unlock all layers
    Dim objLayer As AcadLayer
    For Each objLayer In ThisDrawing.Layers
        objLayer.Lock = False
    Next&lt;BR /&gt;&lt;BR /&gt;
    'remove all attributes from block definition
    For Each objBlock In ThisDrawing.Blocks
        For Each objEntity In objBlock
            If objEntity.EntityName = "AcDbAttributeDefinition" Then
                objEntity.Delete
            End If
            
            'check nested block references in Block definition
            If objEntity.EntityName = "AcDbBlockReference" Then
                Set objBlockRef = objEntity
                On Error Resume Next
                clearBlockRef objEntity
            End If
        Next
    Next
    
    'remove all attributes from block references
    
    For Each objEntity In ThisDrawing.ModelSpace
        If objEntity.EntityName = "AcDbBlockReference" Then
            Set objBlockRef = objEntity
            clearBlockRef objBlockRef
        End If
        objBlockRef.Update
    Next
        
End Sub
    


Private Sub clearBlockRef(objBlockRef As AcadBlockReference)

    Dim objEntity As AcadEntity
    Dim I As Integer
    Dim AttList As Variant
    Dim nestedBlockRef As AcadBlockReference
    Dim objAttributes As Variant
    
    'remove all the block attributes in the block references
    If objBlockRef.HasAttributes Then
        AttList = objBlockRef.GetAttributes
        For I = LBound(AttList) To UBound(AttList)
            Set objAttributes = AttList(I)
            objAttributes.Erase
            objBlockRef.Update
        Next
    End If
End Sub&lt;/PRE&gt;</description>
    <pubDate>Wed, 18 Jan 2017 06:10:17 GMT</pubDate>
    <dc:creator>ilovejingle</dc:creator>
    <dc:date>2017-01-18T06:10:17Z</dc:date>
    <item>
      <title>How to delete all block attributes from a block using vba</title>
      <link>https://forums.autodesk.com/t5/vba-forum/how-to-delete-all-block-attributes-from-a-block-using-vba/m-p/6809640#M8368</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I think the question it self is pretty much descriptive.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What I want to do is loop through all the blocks, find all the block attributes for each block, and delete them permanently one by one.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I tried to&amp;nbsp;write a piece of code, but it doesn't work, when I explode the block, I still got all the attributes coming out.&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;BR /&gt;Sub ClearAtt()

    Dim objBlock As AcadBlockReference
    Dim objEntity As AcadEntity
    Dim objAttributes As AcadAttributeReference
    Dim AttList As Variant
    Dim I As Integer
    
    
    For Each objEntity In ThisDrawing.ModelSpace
        If objEntity.EntityName = "AcDbBlockReference" Then
            Set objBlock = objEntity
            If objBlock.HasAttributes Then
                AttList = objBlock.GetAttributes
                For I = LBound(AttList) To UBound(AttList)
                    Set objAttributes = AttList(I)
                    objAttributes.Erase
                    objBlock.Update
                Next
            End If
        
        End If
    Next
    
End Sub&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jan 2017 06:14:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/how-to-delete-all-block-attributes-from-a-block-using-vba/m-p/6809640#M8368</guid>
      <dc:creator>ilovejingle</dc:creator>
      <dc:date>2017-01-17T06:14:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to delete all block attributes from a block using vba</title>
      <link>https://forums.autodesk.com/t5/vba-forum/how-to-delete-all-block-attributes-from-a-block-using-vba/m-p/6810676#M8369</link>
      <description>&lt;P&gt;Actually, your question IS NOT as "pretty much descriptive" as you think once I saw the the question at first look: do you mean attributes in block definition (AcadAttribute) or attributes in block reference (AcadAttributeReference)?, or both?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you mean attributes in AcadBlock, your code obviously does not delete them from a block definition. And even it did, it would not affect any block reference based on that block definition.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you mean attributes in AcadBlockReference, then your code just does that correctly. However, you need to remember, it has no affect to the block definition (i.e., if you insert a new block, the attributes would be automatically created based on the block definition. Thus, you end up in drawing with block references from the same definition, but some have attributes, some do not - because your code deleted them).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is misunderstanding that Explode a block reference would convert whatever see in the block reference back to individual entities. No, the exploding actually erase the block reference (because block reference is a single entity, just a reference to the block definition, and cannot be split into multiple entities), and grabs copies of all individual entities defined in block definition (including attribute definition) and drop them at the place where the block reference is. That is why you exploded the block reference with attribute being removed, and you still get attributes: these attributes are AcadAttribute, not AcadAttributeReference.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now, if you actually want to change the block definition by removing all attribute (AcadAttribute, so that all block reference created after would not have attributes), and you also need to update existing block reference, then you need to delete AcadAttribute from block definition, and then you need to update all existing block references (as your code already does) or you can run command "attsync".&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jan 2017 14:50:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/how-to-delete-all-block-attributes-from-a-block-using-vba/m-p/6810676#M8369</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2017-01-17T14:50:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to delete all block attributes from a block using vba</title>
      <link>https://forums.autodesk.com/t5/vba-forum/how-to-delete-all-block-attributes-from-a-block-using-vba/m-p/6812263#M8370</link>
      <description>&lt;P&gt;Thank you for your explanation, really appreciate it, now I understand my problem more.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I want to do is actually both. delete the attributes in block definition as well as in block reference.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;now I know how to delete the attributes in block reference, how to loop through all the block definition and delete all the attributes there?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Looking forward to your reply.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jan 2017 01:54:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/how-to-delete-all-block-attributes-from-a-block-using-vba/m-p/6812263#M8370</guid>
      <dc:creator>ilovejingle</dc:creator>
      <dc:date>2017-01-18T01:54:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to delete all block attributes from a block using vba</title>
      <link>https://forums.autodesk.com/t5/vba-forum/how-to-delete-all-block-attributes-from-a-block-using-vba/m-p/6812495#M8371</link>
      <description>&lt;P&gt;Hi, after your post, I tried to find the way myself. here is the code that works.&lt;/P&gt;&lt;P&gt;Thank you for your help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Option Explicit
Sub ClearAtt()

    Dim objBlockRef As AcadBlockReference
    Dim objBlock As AcadBlock
    Dim objEntity As AcadEntity
    Dim objAttributes As AcadAttributeReference
    Dim AttList As Variant
    Dim I As Integer
    
    'unlock all layers
    Dim objLayer As AcadLayer
    For Each objLayer In ThisDrawing.Layers
        objLayer.Lock = False
    Next&lt;BR /&gt;&lt;BR /&gt;
    'remove all attributes from block definition
    For Each objBlock In ThisDrawing.Blocks
        For Each objEntity In objBlock
            If objEntity.EntityName = "AcDbAttributeDefinition" Then
                objEntity.Delete
            End If
            
            'check nested block references in Block definition
            If objEntity.EntityName = "AcDbBlockReference" Then
                Set objBlockRef = objEntity
                On Error Resume Next
                clearBlockRef objEntity
            End If
        Next
    Next
    
    'remove all attributes from block references
    
    For Each objEntity In ThisDrawing.ModelSpace
        If objEntity.EntityName = "AcDbBlockReference" Then
            Set objBlockRef = objEntity
            clearBlockRef objBlockRef
        End If
        objBlockRef.Update
    Next
        
End Sub
    


Private Sub clearBlockRef(objBlockRef As AcadBlockReference)

    Dim objEntity As AcadEntity
    Dim I As Integer
    Dim AttList As Variant
    Dim nestedBlockRef As AcadBlockReference
    Dim objAttributes As Variant
    
    'remove all the block attributes in the block references
    If objBlockRef.HasAttributes Then
        AttList = objBlockRef.GetAttributes
        For I = LBound(AttList) To UBound(AttList)
            Set objAttributes = AttList(I)
            objAttributes.Erase
            objBlockRef.Update
        Next
    End If
End Sub&lt;/PRE&gt;</description>
      <pubDate>Wed, 18 Jan 2017 06:10:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/how-to-delete-all-block-attributes-from-a-block-using-vba/m-p/6812495#M8371</guid>
      <dc:creator>ilovejingle</dc:creator>
      <dc:date>2017-01-18T06:10:17Z</dc:date>
    </item>
  </channel>
</rss>

