<?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: BLockReference.AttributeCollection has actual attribute references within!? in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/blockreference-attributecollection-has-actual-attribute/m-p/7117738#M31244</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt; wrote:&lt;BR /&gt;&lt;P&gt;You can get the child block reference position within the parent block definition, then just transfrom this postion with the parent block reference BlockTransform property.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;. While the &lt;STRONG&gt;BlockTransform&lt;/STRONG&gt; property can be used to transform coordinates or objects from the block's model space to the ECS of the block reference, it cannot account for attributes that have been edited, and have had their position/rotation, etc modified from the 'default' position/rotation, etc.&lt;/P&gt;</description>
    <pubDate>Tue, 30 May 2017 18:40:27 GMT</pubDate>
    <dc:creator>ActivistInvestor</dc:creator>
    <dc:date>2017-05-30T18:40:27Z</dc:date>
    <item>
      <title>BLockReference.AttributeCollection has actual attribute references within!?</title>
      <link>https://forums.autodesk.com/t5/net-forum/blockreference-attributecollection-has-actual-attribute/m-p/7113609#M31238</link>
      <description>&lt;P&gt;I've been using this to get access to attributes in a blockReference&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;foreach (ObjectId objectId in block.AttributeCollection)&lt;/PRE&gt;&lt;P&gt;But today, I exploded a block to get it's child blocks and I wanted to iterate over the child block Attribute collection.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I got an invalid cast exception at the above line.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I looked at the&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;block.AttributeCollection&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;I found it had actual AttributeReferences inside and not the ObjectIds I was expecting.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How on earth are we to deal with a collection which does not know what it is a collection of: a collection of ObjectIds or a collection of actual AttributeReferences?&lt;BR /&gt;&lt;BR /&gt;Anyone come across this and got a good way of dealing with this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 28 May 2017 16:22:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/blockreference-attributecollection-has-actual-attribute/m-p/7113609#M31238</guid>
      <dc:creator>oneMSN</dc:creator>
      <dc:date>2017-05-28T16:22:41Z</dc:date>
    </item>
    <item>
      <title>Re: BLockReference.AttributeCollection has actual attribute references within!?</title>
      <link>https://forums.autodesk.com/t5/net-forum/blockreference-attributecollection-has-actual-attribute/m-p/7113705#M31239</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;While dealing with nested block attributes, you do no need to explode the parent block, just inspect the parent definition (BlockTable Record) to find the nested block reference and get its attributes.&lt;/P&gt;</description>
      <pubDate>Sun, 28 May 2017 18:39:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/blockreference-attributecollection-has-actual-attribute/m-p/7113705#M31239</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2017-05-28T18:39:17Z</dc:date>
    </item>
    <item>
      <title>Re: BLockReference.AttributeCollection has actual attribute references within!?</title>
      <link>https://forums.autodesk.com/t5/net-forum/blockreference-attributecollection-has-actual-attribute/m-p/7113710#M31240</link>
      <description>&lt;P&gt;Unfortunately that was no use for me.&amp;nbsp; I needed to know the child block Positions with respect to model space to locate them on the Drawing.&amp;nbsp; Looking only at the parent definition gives positions relative to parent block.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Besides It still leaves the question unanswered. How can&amp;nbsp;the block AttributeCollection be returning unexpected reference entities when every example I've seen shows that I should be expecting ObjectIds in there.&lt;/P&gt;</description>
      <pubDate>Sun, 28 May 2017 18:45:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/blockreference-attributecollection-has-actual-attribute/m-p/7113710#M31240</guid>
      <dc:creator>oneMSN</dc:creator>
      <dc:date>2017-05-28T18:45:30Z</dc:date>
    </item>
    <item>
      <title>Re: BLockReference.AttributeCollection has actual attribute references within!?</title>
      <link>https://forums.autodesk.com/t5/net-forum/blockreference-attributecollection-has-actual-attribute/m-p/7113804#M31241</link>
      <description>&lt;P&gt;You can get the child block reference position within the parent block definition, then just transfrom this postion with the parent block reference BlockTransform property.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;        private Point3d GetNestedBlockPosition (BlockReference parentBlockRef, string nestedBlockName)
        {
            var tr = parentBlockRef.Database.TransactionManager.TopTransaction;
            var btr = (BlockTableRecord)tr.GetObject(parentBlockRef.BlockTableRecord, OpenMode.ForRead);
            foreach(ObjectId id in btr)
            {
                if (id.ObjectClass.Name == "AcDbBlockReference")
                {
                    var nestedBlockRef = (BlockReference)tr.GetObject(id, OpenMode.ForRead);
                    if (nestedBlockRef.Name == nestedBlockName)
                    {
                        return nestedBlockRef.Position.TransformBy(parentBlockRef.BlockTransform);
                    }
                }
            }
            throw new ArgumentException($"Block {nestedBlockName} not found.");
        }&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 28 May 2017 21:37:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/blockreference-attributecollection-has-actual-attribute/m-p/7113804#M31241</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2017-05-28T21:37:06Z</dc:date>
    </item>
    <item>
      <title>Re: BLockReference.AttributeCollection has actual attribute references within!?</title>
      <link>https://forums.autodesk.com/t5/net-forum/blockreference-attributecollection-has-actual-attribute/m-p/7115621#M31242</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/585727"&gt;@oneMSN&lt;/a&gt; wrote:&lt;BR /&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Besides It still leaves the question unanswered. How can&amp;nbsp;the block AttributeCollection be returning unexpected reference entities when every example I've seen shows that I should be expecting ObjectIds in there.&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;The Explode() method creates objects that are not in a database, and you must either add them to a database or dispose them. Because those objects are not in a database, they have no ObjectIds, and they are already open, newly-created objects.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When you explode a BlockReference&amp;nbsp;that contains other BlockReferences&amp;nbsp;with attributes, the resulting BlockReferences are not database-resident, and so there is no way to get their AttributeReferences using ObjectIds.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That's why their AttributeCollections will contain AttributeReferences.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you want to write code that can deal with both database-resident and in-memory BlockReferences with attributes, you can use something like this extension method:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;public static IEnumerable&amp;lt;AttributeReference&amp;gt; GetAttributes(this BlockReference owner, Transaction trans)
{
   if(owner == null)
      throw new ArgumentNullException("owner");
   if(trans == null)
      throw new ArgumentNullException("trans");
   if(owner.Database != null)
   {
      foreach(ObjectId id in owner.AttributeCollection)
         yield return (AttributeReference) trans.GetObject(id, OpenMode.ForRead);
   }
   else
   {
      foreach(AttributeReference att in owner.AttributeCollection)
         yield return att;
   }
}&lt;/PRE&gt;</description>
      <pubDate>Tue, 30 May 2017 00:26:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/blockreference-attributecollection-has-actual-attribute/m-p/7115621#M31242</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2017-05-30T00:26:57Z</dc:date>
    </item>
    <item>
      <title>Re: BLockReference.AttributeCollection has actual attribute references within!?</title>
      <link>https://forums.autodesk.com/t5/net-forum/blockreference-attributecollection-has-actual-attribute/m-p/7117720#M31243</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/4591287"&gt;@Activist_Investor&lt;/a&gt; wrote:&lt;BR /&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;If you want to write code that can deal with both database-resident and in-memory BlockReferences with attributes, you can use something like this extension method:&lt;/BLOCKQUOTE&gt;&lt;P&gt;I neglected to notice that the example code above doesn't allow for opening the AttributeReferences for write, so......&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;public static IEnumerable&amp;lt;AttributeReference&amp;gt; GetAttributes(this BlockReference owner, OpenMode mode = OpenMode.ForRead, Transaction trans = null)
{
   if(owner == null)
      throw new ArgumentNullException("owner");
   if(owner.Database != null)
   {&lt;BR /&gt;      trans = trans ?? owner.Database.TransactionManager.TopTransaction;&lt;BR /&gt;      if(trans == null)&lt;BR /&gt;         throw new Autodesk.AutoCAD.Runtime.Exception(ErrorStatus.NoActiveTransactions);
      foreach(ObjectId id in owner.AttributeCollection)
         yield return (AttributeReference) trans.GetObject(id, mode);
   }
   else
   {
      foreach(AttributeReference att in owner.AttributeCollection)
         yield return att;
   }
}&lt;/PRE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 May 2017 18:46:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/blockreference-attributecollection-has-actual-attribute/m-p/7117720#M31243</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2017-05-30T18:46:44Z</dc:date>
    </item>
    <item>
      <title>Re: BLockReference.AttributeCollection has actual attribute references within!?</title>
      <link>https://forums.autodesk.com/t5/net-forum/blockreference-attributecollection-has-actual-attribute/m-p/7117738#M31244</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt; wrote:&lt;BR /&gt;&lt;P&gt;You can get the child block reference position within the parent block definition, then just transfrom this postion with the parent block reference BlockTransform property.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;. While the &lt;STRONG&gt;BlockTransform&lt;/STRONG&gt; property can be used to transform coordinates or objects from the block's model space to the ECS of the block reference, it cannot account for attributes that have been edited, and have had their position/rotation, etc modified from the 'default' position/rotation, etc.&lt;/P&gt;</description>
      <pubDate>Tue, 30 May 2017 18:40:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/blockreference-attributecollection-has-actual-attribute/m-p/7117738#M31244</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2017-05-30T18:40:27Z</dc:date>
    </item>
    <item>
      <title>Re: BLockReference.AttributeCollection has actual attribute references within!?</title>
      <link>https://forums.autodesk.com/t5/net-forum/blockreference-attributecollection-has-actual-attribute/m-p/7117759#M31245</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;Activist_Investor a écrit&amp;nbsp;:&lt;BR /&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Hi&amp;nbsp;&lt;A href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424" target="_blank"&gt;@_gile&lt;/A&gt;. While the &lt;STRONG&gt;BlockTransform&lt;/STRONG&gt; property can be used to transform coordinates or objects from the block's model space to the ECS of the block reference, it cannot account for attributes that have been edited, and have had their position/rotation, etc modified from the 'default' position/rotation, etc.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/4476837"&gt;@ActivistInvestor&lt;/a&gt; you're right, but it should work with attributes which have position locked.&lt;/P&gt;</description>
      <pubDate>Tue, 30 May 2017 18:47:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/blockreference-attributecollection-has-actual-attribute/m-p/7117759#M31245</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2017-05-30T18:47:33Z</dc:date>
    </item>
    <item>
      <title>Re: BLockReference.AttributeCollection has actual attribute references within!?</title>
      <link>https://forums.autodesk.com/t5/net-forum/blockreference-attributecollection-has-actual-attribute/m-p/7117799#M31246</link>
      <description>&lt;P&gt;Exactly what I needed to know. Great explanation.&lt;/P&gt;</description>
      <pubDate>Tue, 30 May 2017 19:07:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/blockreference-attributecollection-has-actual-attribute/m-p/7117799#M31246</guid>
      <dc:creator>oneMSN</dc:creator>
      <dc:date>2017-05-30T19:07:10Z</dc:date>
    </item>
  </channel>
</rss>

