<?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: Blocks with Attributes in VBA Forum</title>
    <link>https://forums.autodesk.com/t5/vba-forum/blocks-with-attributes/m-p/911070#M58425</link>
    <description>Public Sub changeBlockColor(colorValue As Integer)&lt;BR /&gt;
  Dim block As AcadBlock&lt;BR /&gt;
  Dim entity As AcadEntity&lt;BR /&gt;
  &lt;BR /&gt;
  For Each block In ThisDrawing.Blocks&lt;BR /&gt;
    For Each entity In block&lt;BR /&gt;
      entity.color = colorValue&lt;BR /&gt;
    Next entity&lt;BR /&gt;
  Next block&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
Public Sub testChangeBlockColor()&lt;BR /&gt;
  changeBlockColor acByLayer&lt;BR /&gt;
End Sub</description>
    <pubDate>Tue, 16 Dec 2003 16:02:11 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2003-12-16T16:02:11Z</dc:date>
    <item>
      <title>Blocks with Attributes</title>
      <link>https://forums.autodesk.com/t5/vba-forum/blocks-with-attributes/m-p/911069#M58424</link>
      <description>I am new to AutoCAD VBA, I was wondering if anyone could help me.  I am trying to write a Procedure that will loop through all the blocks, included nested blocks, in a drawing and change it objects, include attribute tags, to the color ByLayer.  I am running AutoCAD 2000i  Any help would be appreciated.&lt;BR /&gt;
&lt;BR /&gt;
Thanks,&lt;BR /&gt;
Joe</description>
      <pubDate>Tue, 16 Dec 2003 00:15:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/blocks-with-attributes/m-p/911069#M58424</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2003-12-16T00:15:11Z</dc:date>
    </item>
    <item>
      <title>Re: Blocks with Attributes</title>
      <link>https://forums.autodesk.com/t5/vba-forum/blocks-with-attributes/m-p/911070#M58425</link>
      <description>Public Sub changeBlockColor(colorValue As Integer)&lt;BR /&gt;
  Dim block As AcadBlock&lt;BR /&gt;
  Dim entity As AcadEntity&lt;BR /&gt;
  &lt;BR /&gt;
  For Each block In ThisDrawing.Blocks&lt;BR /&gt;
    For Each entity In block&lt;BR /&gt;
      entity.color = colorValue&lt;BR /&gt;
    Next entity&lt;BR /&gt;
  Next block&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
Public Sub testChangeBlockColor()&lt;BR /&gt;
  changeBlockColor acByLayer&lt;BR /&gt;
End Sub</description>
      <pubDate>Tue, 16 Dec 2003 16:02:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/blocks-with-attributes/m-p/911070#M58425</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2003-12-16T16:02:11Z</dc:date>
    </item>
    <item>
      <title>Re: Blocks with Attributes</title>
      <link>https://forums.autodesk.com/t5/vba-forum/blocks-with-attributes/m-p/911071#M58426</link>
      <description>Hi Joe,
This is a two step process.  The first is to find all block definitions and
change all of the entities defined within to color bylayer.  The second step
is to grab all block references and change all of their attribute references
to color bylayer.  Of course the tricky part there is the nested block
condition.  The first listing here takes care of step one.

Public Sub MakeColorByLayer(acadDB As AcadDatabase)
    Dim block As AcadBlock
    Dim ent As AcadEntity

    For Each block In acadDB.Blocks
        If Not block.IsLayout And Not block.IsXRef Then
            For Each ent In block
                ent.Color = acByLayer
            Next ent
        End If
    Next block
End Sub

This next listing handles the second step.  I chose a recursive function
here to handle the nested blocks.  I seriously doubt that anyone has blocks
nested deep enough where there would be a difference enough to warrant
coding up an iterative function to handle this.  Also note that I didn't
account for constant attributes.

Public Sub MakeAttRefsColorByLayer(blockRef As AcadBlockReference)
    Dim acadDoc As AcadDocument
    Set acadDoc = blockRef.Document

    Dim blockName As String
    blockName = blockRef.Name

    Dim blockDef As AcadBlock
    Set blockDef = acadDoc.Blocks.Item(blockName)

    'Test if the block is a simple block.
    If Not blockDef.IsLayout And Not blockDef.IsXRef Then
        Dim attRefs As Variant
        Dim attRef As AcadAttributeReference
        Dim attRefIndex As Integer

        'Set all of the attributes to color bylayer
        If blockRef.HasAttributes Then
            attRefs = blockRef.GetAttributes()
            For attRefIndex = LBound(attRefs) To UBound(attRefs)
                Set attRef = attRefs(attRefIndex)
                attRef.Color = acByLayer
            Next attRefIndex
        End If

        'Check for nested blocks
        Dim ent As AcadEntity
        Dim nestedBlockRef As AcadBlockReference
        For Each ent In blockDef
            If TypeOf ent Is AcadBlockReference Then
                'Make recursive call to handle nested blocks
                Set nestedBlockRef = ent
                Call MakeAttRefsColorByLayer(nestedBlockRef)
            End If
        Next ent
    End If
End Sub

You can run these two functions like this.  For the sake of simplicity I am
iterating all of the layouts in search of block references, but you could
just as easily create a filtered selection set if you so desired.

Public Sub TestMakeColorByLayer()
    'Step one
    Call MakeColorByLayer(ThisDrawing.Database)

    'Step Two
    Dim layout As AcadLayout
    Dim ent As AcadEntity
    Dim blockRef As AcadBlockReference

    For Each layout In ThisDrawing.Layouts
        For Each ent In layout.block
            If TypeOf ent Is AcadBlockReference Then
                Set blockRef = ent
                Call MakeAttRefsColorByLayer(blockRef)
            End If
        Next ent
    Next layout
End Sub

I also just caught the fact that you are on 2000i.  My original code was
created in 2004 and utilized the new true color object.  I'm pretty sure
that I ripped all of that out and replaced all of the TrueColor property
calls to the Color property, but it's not tested as such.  Let me know if
you have any problems.
-- 
Bobby C. Jones
www.AcadX.com

"JMongi5967" &lt;NOSPAM&gt; wrote in message
news:9922485.1071541144387.JavaMail.jive@jiveforum1.autodesk.com...
&amp;gt; I am new to AutoCAD VBA, I was wondering if anyone could help me.  I am
trying to write a Procedure that will loop through all the blocks, included
nested blocks, in a drawing and change it objects, include attribute tags,
to the color ByLayer.  I am running AutoCAD 2000i  Any help would be
appreciated.
&amp;gt;
&amp;gt; Thanks,
&amp;gt; Joe&lt;/NOSPAM&gt;</description>
      <pubDate>Tue, 16 Dec 2003 20:19:31 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/blocks-with-attributes/m-p/911071#M58426</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2003-12-16T20:19:31Z</dc:date>
    </item>
    <item>
      <title>Re: Blocks with Attributes</title>
      <link>https://forums.autodesk.com/t5/vba-forum/blocks-with-attributes/m-p/911072#M58427</link>
      <description>Just for the record, This is not a "two step process",
and you don't need to worry about 'nested' blocks or
application of 'recursive' concepts, because you're
going to process *all* objects in the drawing, except
for those in layouts.

In fact, the "recursive approach" posted in another
reply, will needlessly process the same block multiple
times, when insertions of it appear in more than one
parent block.  Duh!

This Sub will process every block, including layouts,
but will not change the color of entities that are
directly owned by layouts:

Public Sub ProcessBlock(Block As AcadBlock)
   Dim IsNested As Boolean
   IsNested = not Block.IsLayout
   Dim Entity As AcadEntity
   ForEach Entity in Block
     If IsNested then
        Entity.Color = acByLayer
     End If
     if TypeOf Entity is AcadBlockReference then
        Dim BlockRef As AcadBlockReference
        Set BlockRef = Entity
        If BlockRef.HasAttributes then
          Dim AttRef As AcadAttributeReference
          Dim Attributes As Variant
          Attributes = BlockRef.GetAttributes
          Dim i As Integer
          For i = LBound(Attributes) to UBound(Attributes)
             Set AttRef = Attributes(i)
             AttRef.Color = acByLayer
          Next i
        End If
     End If
   Next Entity
End Sub

With the above, you just need this:

Public Sub ProcessDrawing
  Dim ABlock As AcadBlock
  ForEach ABlock in ThisDrawing.Blocks
    If not ABlock.IsXref then
       ProcessBlock ABlock
    End if
  Next Block
End Sub

-- 
AcadXTabs: MDI Document Tabs for AutoCAD
http://www.acadxtabs.com


"JMongi5967" &lt;NOSPAM&gt; wrote in message news:9922485.1071541144387.JavaMail.jive@jiveforum1.autodesk.com...
&amp;gt; I am new to AutoCAD VBA, I was wondering if anyone could help me.  I am trying to write a Procedure that will loop
through all the blocks, included nested blocks, in a drawing and change it objects, include attribute tags, to the color
ByLayer.  I am running AutoCAD 2000i  Any help would be appreciated.
&amp;gt;
&amp;gt; Thanks,
&amp;gt; Joe&lt;/NOSPAM&gt;</description>
      <pubDate>Wed, 17 Dec 2003 15:50:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/blocks-with-attributes/m-p/911072#M58427</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2003-12-17T15:50:43Z</dc:date>
    </item>
    <item>
      <title>Re: Blocks with Attributes</title>
      <link>https://forums.autodesk.com/t5/vba-forum/blocks-with-attributes/m-p/911073#M58428</link>
      <description>Note that both of those subs were not tested
at all, and there's a stupid bug in the second
sub:

Public Sub ProcessDrawing
  Dim ABlock As AcadBlock
  ForEach ABlock in ThisDrawing.Blocks
    If not ABlock.IsXref then
       ProcessBlock ABlock
    End if
  Next ABlock     ' bug fixed
End Sub


-- 
AcadXTabs: MDI Document Tabs for AutoCAD
http://www.acadxtabs.com</description>
      <pubDate>Wed, 17 Dec 2003 15:54:37 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/blocks-with-attributes/m-p/911073#M58428</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2003-12-17T15:54:37Z</dc:date>
    </item>
    <item>
      <title>Re: Blocks with Attributes</title>
      <link>https://forums.autodesk.com/t5/vba-forum/blocks-with-attributes/m-p/911074#M58429</link>
      <description>Big Duh indeed T man!  What was the other poster, or is that poser, thinking
:-)  Thanks for the simplified answer.
-- 
Bobby C. Jones
www.AcadX.com

"Tony Tanzillo" &lt;TONY.TANZILLO at="" caddzone="" dot="" com=""&gt; wrote in message
news:3fe07ab5$1_2@statler...
&amp;gt; Just for the record, This is not a "two step process",
&amp;gt; and you don't need to worry about 'nested' blocks or
&amp;gt; application of 'recursive' concepts, because you're
&amp;gt; going to process *all* objects in the drawing, except
&amp;gt; for those in layouts.
&amp;gt;
&amp;gt; In fact, the "recursive approach" posted in another
&amp;gt; reply, will needlessly process the same block multiple
&amp;gt; times, when insertions of it appear in more than one
&amp;gt; parent block.  Duh!
&amp;gt;
&amp;gt; This Sub will process every block, including layouts,
&amp;gt; but will not change the color of entities that are
&amp;gt; directly owned by layouts:
&amp;gt;
&amp;gt; Public Sub ProcessBlock(Block As AcadBlock)
&amp;gt;    Dim IsNested As Boolean
&amp;gt;    IsNested = not Block.IsLayout
&amp;gt;    Dim Entity As AcadEntity
&amp;gt;    ForEach Entity in Block
&amp;gt;      If IsNested then
&amp;gt;         Entity.Color = acByLayer
&amp;gt;      End If
&amp;gt;      if TypeOf Entity is AcadBlockReference then
&amp;gt;         Dim BlockRef As AcadBlockReference
&amp;gt;         Set BlockRef = Entity
&amp;gt;         If BlockRef.HasAttributes then
&amp;gt;           Dim AttRef As AcadAttributeReference
&amp;gt;           Dim Attributes As Variant
&amp;gt;           Attributes = BlockRef.GetAttributes
&amp;gt;           Dim i As Integer
&amp;gt;           For i = LBound(Attributes) to UBound(Attributes)
&amp;gt;              Set AttRef = Attributes(i)
&amp;gt;              AttRef.Color = acByLayer
&amp;gt;           Next i
&amp;gt;         End If
&amp;gt;      End If
&amp;gt;    Next Entity
&amp;gt; End Sub
&amp;gt;
&amp;gt; With the above, you just need this:
&amp;gt;
&amp;gt; Public Sub ProcessDrawing
&amp;gt;   Dim ABlock As AcadBlock
&amp;gt;   ForEach ABlock in ThisDrawing.Blocks
&amp;gt;     If not ABlock.IsXref then
&amp;gt;        ProcessBlock ABlock
&amp;gt;     End if
&amp;gt;   Next Block
&amp;gt; End Sub
&amp;gt;
&amp;gt; -- 
&amp;gt; AcadXTabs: MDI Document Tabs for AutoCAD
&amp;gt; http://www.acadxtabs.com
&amp;gt;
&amp;gt;
&amp;gt; "JMongi5967" &lt;NOSPAM&gt; wrote in message
news:9922485.1071541144387.JavaMail.jive@jiveforum1.autodesk.com...
&amp;gt; &amp;gt; I am new to AutoCAD VBA, I was wondering if anyone could help me.  I am
trying to write a Procedure that will loop
&amp;gt; through all the blocks, included nested blocks, in a drawing and change it
objects, include attribute tags, to the color
&amp;gt; ByLayer.  I am running AutoCAD 2000i  Any help would be appreciated.
&amp;gt; &amp;gt;
&amp;gt; &amp;gt; Thanks,
&amp;gt; &amp;gt; Joe
&amp;gt;
&amp;gt;&lt;/NOSPAM&gt;&lt;/TONY.TANZILLO&gt;</description>
      <pubDate>Wed, 17 Dec 2003 16:23:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/blocks-with-attributes/m-p/911074#M58429</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2003-12-17T16:23:08Z</dc:date>
    </item>
    <item>
      <title>Re: Blocks with Attributes</title>
      <link>https://forums.autodesk.com/t5/vba-forum/blocks-with-attributes/m-p/911075#M58430</link>
      <description>Nice.  And at the risk of gittin stomped ;-)

There is also the matter of possible constant attributes
that would be handled similarly with getconstantattributes.


"Tony Tanzillo" &lt;TONY.TANZILLO at="" caddzone="" dot="" com=""&gt; wrote in message
news:3fe07b96_7@statler...
&amp;gt; Note that both of those subs were not tested
&amp;gt; at all, and there's a stupid bug in the second
&amp;gt; sub:
&amp;gt;
&amp;gt; Public Sub ProcessDrawing
&amp;gt;   Dim ABlock As AcadBlock
&amp;gt;   ForEach ABlock in ThisDrawing.Blocks
&amp;gt;     If not ABlock.IsXref then
&amp;gt;        ProcessBlock ABlock
&amp;gt;     End if
&amp;gt;   Next ABlock     ' bug fixed
&amp;gt; End Sub
&amp;gt;
&amp;gt;
&amp;gt; --
&amp;gt; AcadXTabs: MDI Document Tabs for AutoCAD
&amp;gt; http://www.acadxtabs.com
&amp;gt;
&amp;gt;
&amp;gt;&lt;/TONY.TANZILLO&gt;</description>
      <pubDate>Wed, 17 Dec 2003 19:30:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/blocks-with-attributes/m-p/911075#M58430</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2003-12-17T19:30:03Z</dc:date>
    </item>
  </channel>
</rss>

