<?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: Change Attribute Layer In Block With VBA in VBA Forum</title>
    <link>https://forums.autodesk.com/t5/vba-forum/change-attribute-layer-in-block-with-vba/m-p/5476443#M9952</link>
    <description>norman.yuan, That works perfect for what I need. Just added an "if then" to check if the attribute name found in the for loop matches the attribute i am sending from the main sub, and it works just fine. I did not think of using the "TypeOf" operator to avoid errors, that will avoid me having to send with ucase, etc. Thanks for the solution!</description>
    <pubDate>Tue, 20 Jan 2015 23:29:14 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2015-01-20T23:29:14Z</dc:date>
    <item>
      <title>Change Attribute Layer In Block With VBA</title>
      <link>https://forums.autodesk.com/t5/vba-forum/change-attribute-layer-in-block-with-vba/m-p/5476291#M9949</link>
      <description>I am running into something, and I can't seem to figure it out. I have a subroutine to change the layer of an attribute, but it does not seem to work, and I can't find much on it online, so here i am! I will do my best to format it here, as my insert code button is not showing up in IE 11 or chrome... Private Sub ToZeroLayer(acadAttribute As String) Dim AttRef As AcadAttributeReference Dim Block As Object For Each Block In ThisDrawing.PaperSpace If Block.EntityName = "AcDbBlockReference" Then If Block.HasAttributes Then Array1 = Block.GetAttributes For i = LBound(Array1) To UBound(Array1) If (Array1(i).EntityName) = acadAttribute Then Set AttRef = (Array1(i)) AttRef.Layer = "0" End If Next End If End If Next End Sub It runs through the code without error, but it appears to do nothing.... Any help would be much appreciated! --Thanks as always!</description>
      <pubDate>Tue, 20 Jan 2015 21:28:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/change-attribute-layer-in-block-with-vba/m-p/5476291#M9949</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-01-20T21:28:27Z</dc:date>
    </item>
    <item>
      <title>Re: Change Attribute Layer In Block With VBA</title>
      <link>https://forums.autodesk.com/t5/vba-forum/change-attribute-layer-in-block-with-vba/m-p/5476366#M9950</link>
      <description>Did you try and debug it line by line? At a first glance I'd say it would never pass the "If (Array1(i).EntityName) = acadAttribute Then" check since attribute "name" is its "tagstring" property (or something similar - I'm not at my PC now) actually.&lt;BR /&gt;Then I can't tell you anything about attributereference object properties and treatment since I never used it.</description>
      <pubDate>Tue, 20 Jan 2015 22:11:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/change-attribute-layer-in-block-with-vba/m-p/5476366#M9950</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-01-20T22:11:36Z</dc:date>
    </item>
    <item>
      <title>Re: Change Attribute Layer In Block With VBA</title>
      <link>https://forums.autodesk.com/t5/vba-forum/change-attribute-layer-in-block-with-vba/m-p/5476428#M9951</link>
      <description>&lt;P&gt;Using&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;If AcadEntity.EntityName&amp;nbsp;= "xxxxxx" Then&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;is an error-prone approach, because up/lowercase difference could lead to different result, In your case, use "TypeOf xxxx Is xxxxxxx" would be more error-proofing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Following code change an block's attribute's layer: the attribute was defined in layer "0", and the block reference is inserted in layer "0", running the code changes the layer of the attributes in the block reference to "Layer1". Since "Layer1" has color red, the code result can be visibily verified.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Public Sub Test()

    Dim ent As AcadEntity
    Dim blk As AcadBlockReference
    Dim atts As Variant
    Dim att As AcadAttributeReference
    Dim i As Integer
    
    For Each ent In ThisDrawing.ModelSpace
        
        If TypeOf ent Is AcadBlockReference Then
            Set blk = ent
            atts = blk.GetAttributes()
            For i = 0 To UBound(atts)
                Set att = atts(i)
                att.Layer = "Layer1"
                att.Update
            Next
        End If
        
    Next

End Sub&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jan 2015 23:05:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/change-attribute-layer-in-block-with-vba/m-p/5476428#M9951</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2015-01-20T23:05:27Z</dc:date>
    </item>
    <item>
      <title>Re: Change Attribute Layer In Block With VBA</title>
      <link>https://forums.autodesk.com/t5/vba-forum/change-attribute-layer-in-block-with-vba/m-p/5476443#M9952</link>
      <description>norman.yuan, That works perfect for what I need. Just added an "if then" to check if the attribute name found in the for loop matches the attribute i am sending from the main sub, and it works just fine. I did not think of using the "TypeOf" operator to avoid errors, that will avoid me having to send with ucase, etc. Thanks for the solution!</description>
      <pubDate>Tue, 20 Jan 2015 23:29:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/change-attribute-layer-in-block-with-vba/m-p/5476443#M9952</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-01-20T23:29:14Z</dc:date>
    </item>
    <item>
      <title>Re: Change Attribute Layer In Block With VBA</title>
      <link>https://forums.autodesk.com/t5/vba-forum/change-attribute-layer-in-block-with-vba/m-p/5476719#M9953</link>
      <description>&lt;P&gt;just out of curiosity, did you actually use ".EntityName" for attribute name checking?&lt;/P&gt;</description>
      <pubDate>Wed, 21 Jan 2015 06:59:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/change-attribute-layer-in-block-with-vba/m-p/5476719#M9953</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-01-21T06:59:06Z</dc:date>
    </item>
  </channel>
</rss>

