<?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 find attribute definition value in one shot in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/find-attribute-definition-value-in-one-shot/m-p/6710524#M33729</link>
    <description>&lt;P&gt;hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a block definition which has 15 attribute definitions in my drawing.&amp;nbsp;I need to know one of the attribute definition value of a block reference. In order to do that I have to loop all the attrribute collection of my block reference and load the object by its ID . this way, I have a performance problem. is there an easy way to find a block's attdef in one shot?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;----------------------------------&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;here is my method:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;public String GetAttDefOfABlock(BlockReference br,String attributeName)&lt;BR /&gt;{&lt;BR /&gt;String returnValue = "";&lt;BR /&gt;foreach (ObjectId id in br.AttributeCollection)&lt;BR /&gt;{&lt;BR /&gt;AttributeReference attRef = (AttributeReference)HandleToBlockReference(id.Handle.ToString()); // this line loads the object to get its value&lt;BR /&gt;if (attRef.Tag.ToString() == attributeName)&lt;BR /&gt;{&lt;BR /&gt;returnValue = attRef.TextString;&lt;BR /&gt;break;&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;return returnValue;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="my debug screen" style="width: 705px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/296475i0A062A877FA6CFA1/image-size/large?v=v2&amp;amp;px=999" role="button" title="attributedeffs.png" alt="attributedeffs.png" /&gt;&lt;/span&gt;﻿&lt;/P&gt;</description>
    <pubDate>Sat, 26 Nov 2016 08:26:25 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2016-11-26T08:26:25Z</dc:date>
    <item>
      <title>find attribute definition value in one shot</title>
      <link>https://forums.autodesk.com/t5/net-forum/find-attribute-definition-value-in-one-shot/m-p/6710524#M33729</link>
      <description>&lt;P&gt;hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a block definition which has 15 attribute definitions in my drawing.&amp;nbsp;I need to know one of the attribute definition value of a block reference. In order to do that I have to loop all the attrribute collection of my block reference and load the object by its ID . this way, I have a performance problem. is there an easy way to find a block's attdef in one shot?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;----------------------------------&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;here is my method:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;public String GetAttDefOfABlock(BlockReference br,String attributeName)&lt;BR /&gt;{&lt;BR /&gt;String returnValue = "";&lt;BR /&gt;foreach (ObjectId id in br.AttributeCollection)&lt;BR /&gt;{&lt;BR /&gt;AttributeReference attRef = (AttributeReference)HandleToBlockReference(id.Handle.ToString()); // this line loads the object to get its value&lt;BR /&gt;if (attRef.Tag.ToString() == attributeName)&lt;BR /&gt;{&lt;BR /&gt;returnValue = attRef.TextString;&lt;BR /&gt;break;&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;return returnValue;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="my debug screen" style="width: 705px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/296475i0A062A877FA6CFA1/image-size/large?v=v2&amp;amp;px=999" role="button" title="attributedeffs.png" alt="attributedeffs.png" /&gt;&lt;/span&gt;﻿&lt;/P&gt;</description>
      <pubDate>Sat, 26 Nov 2016 08:26:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/find-attribute-definition-value-in-one-shot/m-p/6710524#M33729</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-11-26T08:26:25Z</dc:date>
    </item>
    <item>
      <title>Re : find attribute definition value in one shot</title>
      <link>https://forums.autodesk.com/t5/net-forum/find-attribute-definition-value-in-one-shot/m-p/6710563#M33730</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;AFAIK, you can't get an attribute reference "in one shot". But I never notice any "performance issue" even with much more attributes than 15.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't know what doe's the HandleToBlockReference() method but it's perhaps the cause of the "performance issue".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this way (assuming the method is called from within a transaction):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;        public string GetAttValue(BlockReference br, string attributeTag)
        {
            string returnValue = "";
            foreach (ObjectId id in br.AttributeCollection)
            {
                AttributeReference attRef = (AttributeReference)id.GetObject(OpenMode.ForRead);
                if (attRef.Tag == attributeTag)
                {
                    returnValue = attRef.TextString;
                    break;
                }
            }
            return returnValue;
        }&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PS: the value you want has nothing to do with an attribute definition, it's the value of the attribute reference. An AttributeDefinition typically owns to a block definition (BlockTableRecord).&lt;/P&gt;</description>
      <pubDate>Sat, 26 Nov 2016 09:59:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/find-attribute-definition-value-in-one-shot/m-p/6710563#M33730</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2016-11-26T09:59:25Z</dc:date>
    </item>
  </channel>
</rss>

