<?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 Get all entities inside a blockreference in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/get-all-entities-inside-a-blockreference/m-p/10771795#M14525</link>
    <description>&lt;P&gt;Hi, I've had some problems trying to get all entities inside a blockreference. As the following pic, there are 4 lines and another blockreference inside a blockreference.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="niaxiapiaF4Z8Y_0-1637495933716.png" style="width: 400px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/992005iF575BF1F22D73505/image-size/medium?v=v2&amp;amp;px=400" role="button" title="niaxiapiaF4Z8Y_0-1637495933716.png" alt="niaxiapiaF4Z8Y_0-1637495933716.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;var entities = new List&amp;lt;Entity&amp;gt;();
var objects = new DBObjectCollection();
block.Explode(objects);&lt;/LI-CODE&gt;&lt;P&gt;the objects returns me only 4 lines but no blockreference.&lt;/P&gt;&lt;P&gt;What is amazing is that when I mirror the whole&amp;nbsp;blockreference and execute the code again, I can get 4 lines and a blockreference from the mirrored blockreference.&lt;/P&gt;&lt;P&gt;Is there sth wrong with my code, or is there a better way to get all entities inside a blockreference.&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
    <pubDate>Sun, 21 Nov 2021 12:00:13 GMT</pubDate>
    <dc:creator>哀家爆</dc:creator>
    <dc:date>2021-11-21T12:00:13Z</dc:date>
    <item>
      <title>Get all entities inside a blockreference</title>
      <link>https://forums.autodesk.com/t5/net-forum/get-all-entities-inside-a-blockreference/m-p/10771795#M14525</link>
      <description>&lt;P&gt;Hi, I've had some problems trying to get all entities inside a blockreference. As the following pic, there are 4 lines and another blockreference inside a blockreference.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="niaxiapiaF4Z8Y_0-1637495933716.png" style="width: 400px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/992005iF575BF1F22D73505/image-size/medium?v=v2&amp;amp;px=400" role="button" title="niaxiapiaF4Z8Y_0-1637495933716.png" alt="niaxiapiaF4Z8Y_0-1637495933716.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;var entities = new List&amp;lt;Entity&amp;gt;();
var objects = new DBObjectCollection();
block.Explode(objects);&lt;/LI-CODE&gt;&lt;P&gt;the objects returns me only 4 lines but no blockreference.&lt;/P&gt;&lt;P&gt;What is amazing is that when I mirror the whole&amp;nbsp;blockreference and execute the code again, I can get 4 lines and a blockreference from the mirrored blockreference.&lt;/P&gt;&lt;P&gt;Is there sth wrong with my code, or is there a better way to get all entities inside a blockreference.&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Sun, 21 Nov 2021 12:00:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/get-all-entities-inside-a-blockreference/m-p/10771795#M14525</guid>
      <dc:creator>哀家爆</dc:creator>
      <dc:date>2021-11-21T12:00:13Z</dc:date>
    </item>
    <item>
      <title>Re: Get all entities inside a blockreference</title>
      <link>https://forums.autodesk.com/t5/net-forum/get-all-entities-inside-a-blockreference/m-p/10771808#M14526</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;A block reference (BlockReference) does not contain entities, it is just a reference to a block definition (BlockTableRecord) which does contain entities.&lt;/P&gt;
&lt;P&gt;You can get the ObjectId of the block definition using the BlockReference.BlockTableRecord property, open the BlockTablerecord for read and iterate through its contents.&lt;/P&gt;</description>
      <pubDate>Sun, 21 Nov 2021 12:12:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/get-all-entities-inside-a-blockreference/m-p/10771808#M14526</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2021-11-21T12:12:55Z</dc:date>
    </item>
    <item>
      <title>Re: Get all entities inside a blockreference</title>
      <link>https://forums.autodesk.com/t5/net-forum/get-all-entities-inside-a-blockreference/m-p/10771872#M14527</link>
      <description>&lt;P&gt;Thanks for your answer.&amp;nbsp;&lt;/P&gt;&lt;P&gt;How am I supposed to understand that we can obtain the&amp;nbsp;DBObjectCollection by using :&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;blockReference.Explode();&lt;/LI-CODE&gt;&lt;P&gt;And&amp;nbsp;I did get what I wanted by using the 'Explode()' method in most cases.&lt;/P&gt;&lt;P&gt;In the example above, the blockReference consists of four lines and another blockReference. In general, I can get what I want.&amp;nbsp;Just this time I do not know what reason cause the 'Explode()' method to lose a blockReference.&lt;/P&gt;</description>
      <pubDate>Sun, 21 Nov 2021 13:23:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/get-all-entities-inside-a-blockreference/m-p/10771872#M14527</guid>
      <dc:creator>哀家爆</dc:creator>
      <dc:date>2021-11-21T13:23:38Z</dc:date>
    </item>
    <item>
      <title>Re: Get all entities inside a blockreference</title>
      <link>https://forums.autodesk.com/t5/net-forum/get-all-entities-inside-a-blockreference/m-p/10771926#M14528</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;Please look at this is&lt;/P&gt;&lt;P&gt;&lt;A href="https://forums.autodesk.com/t5/net/how-to-get-poin-center-of-circle-in-block/m-p/10354555" target="_blank"&gt;https://forums.autodesk.com/t5/net/how-to-get-poin-center-of-circle-in-block/m-p/10354555&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Change this&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;id.ObjectClass.DxfName.ToUpper() == "CIRCLE")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;id.ObjectClass.DxfName.ToUpper() == "line")&lt;/LI-CODE&gt;</description>
      <pubDate>Sun, 21 Nov 2021 14:42:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/get-all-entities-inside-a-blockreference/m-p/10771926#M14528</guid>
      <dc:creator>hosneyalaa</dc:creator>
      <dc:date>2021-11-21T14:42:34Z</dc:date>
    </item>
    <item>
      <title>Re: Get all entities inside a blockreference</title>
      <link>https://forums.autodesk.com/t5/net-forum/get-all-entities-inside-a-blockreference/m-p/10771991#M14529</link>
      <description>&lt;P&gt;Hi, _gile&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;var blockTableRecordId = block.BlockTableRecord;
BlockTableRecord blockTableRecord = null;
using (var ts = block.Database.TransactionManager.StartTransaction())
{
    blockTableRecord = ts.GetObject(blockTableRecordId, OpenMode.ForRead) as BlockTableRecord;
    foreach (var id in blockTableRecord)
    {
        var ent = (Entity)ts.GetObject(id, OpenMode.ForRead);
        ent.TransformBy(block.BlockTransform);
        entities.Add(ent);
     }
}&lt;/LI-CODE&gt;&lt;P&gt;Now I use your way to get all entities from a blockreference (throuth the blocktablerecord), and get the correct result.&lt;/P&gt;&lt;P&gt;But the following statement :&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;ent.TransformBy(block.BlockTransform);&lt;/LI-CODE&gt;&lt;P&gt;throw a exception :&lt;/P&gt;&lt;P&gt;Autodesk.AutoCAD.Runtime.Exception:“eMissingSymbolTableRec”&lt;/P&gt;&lt;P&gt;What is wrong with this?&lt;/P&gt;&lt;P&gt;Best regards!~&lt;/P&gt;</description>
      <pubDate>Sun, 21 Nov 2021 15:27:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/get-all-entities-inside-a-blockreference/m-p/10771991#M14529</guid>
      <dc:creator>哀家爆</dc:creator>
      <dc:date>2021-11-21T15:27:03Z</dc:date>
    </item>
    <item>
      <title>Re: Get all entities inside a blockreference</title>
      <link>https://forums.autodesk.com/t5/net-forum/get-all-entities-inside-a-blockreference/m-p/10771992#M14530</link>
      <description>&lt;P&gt;Hi, _gile&lt;/P&gt;&lt;P&gt;Now I use your way to get all entities from a blockreference (throuth the blocktablerecord), and get the correct result.&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;var blockTableRecordId = block.BlockTableRecord;
BlockTableRecord blockTableRecord = null;
using (var ts = block.Database.TransactionManager.StartTransaction())
{
    blockTableRecord = ts.GetObject(blockTableRecordId, OpenMode.ForRead) as BlockTableRecord;
    foreach (var id in blockTableRecord)
    {
        var ent = (Entity)ts.GetObject(id, OpenMode.ForRead);
        ent.TransformBy(block.BlockTransform);
        entities.Add(ent);
     }
}&lt;/LI-CODE&gt;&lt;P&gt;But the following statement :&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt; ent.TransformBy(block.BlockTransform); &lt;/LI-CODE&gt;&lt;P&gt;throw a exception : Autodesk.AutoCAD.Runtime.Exception:“eMissingSymbolTableRec”&lt;/P&gt;&lt;P&gt;What is wrong with this? Best regards!~&lt;/P&gt;</description>
      <pubDate>Sun, 21 Nov 2021 15:29:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/get-all-entities-inside-a-blockreference/m-p/10771992#M14530</guid>
      <dc:creator>哀家爆</dc:creator>
      <dc:date>2021-11-21T15:29:22Z</dc:date>
    </item>
    <item>
      <title>Re: Get all entities inside a blockreference</title>
      <link>https://forums.autodesk.com/t5/net-forum/get-all-entities-inside-a-blockreference/m-p/10772001#M14531</link>
      <description>&lt;P&gt;I was just trying to reply to your question : "is there a better way to get all entities inside a blockreference."&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;        private static IEnumerable&amp;lt;Entity&amp;gt; GetEntitiesWithinBlock(BlockReference br) =&amp;gt;
            ((BlockTableRecord)br.BlockTableRecord.GetObject(OpenMode.ForRead))
            .Cast&amp;lt;ObjectId&amp;gt;()
            .Select(id =&amp;gt; (Entity)id.GetObject(OpenMode.ForRead));&lt;/LI-CODE&gt;</description>
      <pubDate>Sun, 21 Nov 2021 15:36:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/get-all-entities-inside-a-blockreference/m-p/10772001#M14531</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2021-11-21T15:36:30Z</dc:date>
    </item>
    <item>
      <title>Re: Get all entities inside a blockreference</title>
      <link>https://forums.autodesk.com/t5/net-forum/get-all-entities-inside-a-blockreference/m-p/10772012#M14532</link>
      <description>&lt;P&gt;You should not tranform the entity within the block definition, you should clone it and transform the clone.&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;        private static IEnumerable&amp;lt;Entity&amp;gt; GetEntitiesWithinBlock(BlockReference br)
        {
            var btr = (BlockTableRecord)br.BlockTableRecord.GetObject(OpenMode.ForRead);
            var ids = new ObjectIdCollection(btr.Cast&amp;lt;ObjectId&amp;gt;().ToArray());
            var mapping = new IdMapping();
            br.Database.DeepCloneObjects(ids, br.OwnerId, mapping, false);
            foreach (IdPair pair in mapping)
            {
                if (pair.IsCloned &amp;amp;&amp;amp; pair.IsPrimary)
                {
                    var entity = (Entity)pair.Value.GetObject(OpenMode.ForWrite);
                    entity.TransformBy(br.BlockTransform);
                    yield return entity;
                }
            }
        }&lt;/LI-CODE&gt;</description>
      <pubDate>Sun, 21 Nov 2021 15:44:47 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/get-all-entities-inside-a-blockreference/m-p/10772012#M14532</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2021-11-21T15:44:47Z</dc:date>
    </item>
    <item>
      <title>Re: Get all entities inside a blockreference</title>
      <link>https://forums.autodesk.com/t5/net-forum/get-all-entities-inside-a-blockreference/m-p/10772019#M14533</link>
      <description>&lt;P&gt;thanks a lot，I will try again.&lt;/P&gt;</description>
      <pubDate>Sun, 21 Nov 2021 15:49:15 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/get-all-entities-inside-a-blockreference/m-p/10772019#M14533</guid>
      <dc:creator>哀家爆</dc:creator>
      <dc:date>2021-11-21T15:49:15Z</dc:date>
    </item>
    <item>
      <title>Re: Get all entities inside a blockreference</title>
      <link>https://forums.autodesk.com/t5/net-forum/get-all-entities-inside-a-blockreference/m-p/10775630#M14534</link>
      <description>&lt;P class=""&gt;What if I want to get all entities recursively?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;public static void GetEntitiesWithinBlock(BlockReference br, Document doc, ref List&amp;lt;Entity&amp;gt; entities)
        {
            using (var ts = doc.Database.TransactionManager.StartTransaction())
            {
                var btr = (BlockTableRecord)br.BlockTableRecord.GetObject(OpenMode.ForRead);
                var ids = new ObjectIdCollection(btr.Cast&amp;lt;ObjectId&amp;gt;().ToArray());
                var mapping = new IdMapping();
                br.Database.DeepCloneObjects(ids, br.OwnerId, mapping, false);
                var asd = br.BlockTransform;
                foreach (IdPair pair in mapping)
                {
                    if (pair.IsCloned &amp;amp;&amp;amp; pair.IsPrimary)
                    {
                        var entity = (Entity)ts.GetObject(pair.Value, OpenMode.ForWrite);
                        if (entity is BlockReference blockReference)
                        {
                            GetEntitiesWithinBlock(blockReference, doc, ref entities);
                        }
                        else
                        {
                            entity.TransformBy(br.BlockTransform);
                            entities.Add(entity);
                        }
                    }
                }
            }
        }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And the statement: entity.TransformBy(br.BlockTransform); throw a new exception:&amp;nbsp;eCannotScaleNonUniformly.&lt;/P&gt;&lt;P&gt;Thanks a lot!&lt;/P&gt;</description>
      <pubDate>Tue, 23 Nov 2021 07:43:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/get-all-entities-inside-a-blockreference/m-p/10775630#M14534</guid>
      <dc:creator>哀家爆</dc:creator>
      <dc:date>2021-11-23T07:43:08Z</dc:date>
    </item>
    <item>
      <title>Re: Get all entities inside a blockreference</title>
      <link>https://forums.autodesk.com/t5/net-forum/get-all-entities-inside-a-blockreference/m-p/10775762#M14535</link>
      <description>&lt;LI-CODE lang="csharp"&gt;        private static IEnumerable&amp;lt;Entity&amp;gt; GetEntitiesWithinBlock(BlockReference br)
        {
            var btr = (BlockTableRecord)br.BlockTableRecord.GetObject(OpenMode.ForRead);
            var ids = new ObjectIdCollection(btr.Cast&amp;lt;ObjectId&amp;gt;().ToArray());
            var mapping = new IdMapping();
            br.Database.DeepCloneObjects(ids, br.OwnerId, mapping, false);
            foreach (IdPair pair in mapping)
            {
                if (pair.IsCloned &amp;amp;&amp;amp; pair.IsPrimary)
                {
                    var entity = (Entity)pair.Value.GetObject(OpenMode.ForWrite);
                    if (entity is BlockReference)
                    {
                        entity.TransformBy(br.BlockTransform);
                        foreach (var ent in GetEntitiesWithinBlock((BlockReference)entity))
                        {
                            yield return ent;
                        }
                        entity.Erase();
                    }
                    else
                    {
                        entity.TransformBy(br.BlockTransform);
                        yield return entity;
                    }
                }
            }
        }&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 23 Nov 2021 08:46:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/get-all-entities-inside-a-blockreference/m-p/10775762#M14535</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2021-11-23T08:46:13Z</dc:date>
    </item>
    <item>
      <title>Re: Get all entities inside a blockreference</title>
      <link>https://forums.autodesk.com/t5/net-forum/get-all-entities-inside-a-blockreference/m-p/10775808#M14536</link>
      <description>&lt;P&gt;When the entity is BlockReference,&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;entity.TransformBy(br.BlockTransform);&lt;/LI-CODE&gt;&lt;P&gt;throw the exception:&amp;nbsp;eMissingSymbolTableRec.&lt;/P&gt;&lt;P&gt;It seems that AutoCAD doesn't allow us to transform a&amp;nbsp;blockReference which is within another&amp;nbsp;blockReference .&lt;/P&gt;</description>
      <pubDate>Tue, 23 Nov 2021 09:13:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/get-all-entities-inside-a-blockreference/m-p/10775808#M14536</guid>
      <dc:creator>哀家爆</dc:creator>
      <dc:date>2021-11-23T09:13:35Z</dc:date>
    </item>
    <item>
      <title>Re: Get all entities inside a blockreference</title>
      <link>https://forums.autodesk.com/t5/net-forum/get-all-entities-inside-a-blockreference/m-p/10775872#M14537</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/9902882"&gt;@哀家爆&lt;/a&gt;&amp;nbsp; a écrit&amp;nbsp;:&lt;BR /&gt;
&lt;P&gt;When the entity is BlockReference,&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;entity.TransformBy(br.BlockTransform);&lt;/LI-CODE&gt;
&lt;P&gt;throw the exception:&amp;nbsp;eMissingSymbolTableRec.&lt;/P&gt;
&lt;P&gt;It seems that AutoCAD doesn't allow us to transform a&amp;nbsp;blockReference which is within another&amp;nbsp;blockReference .&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;We do not transform the block reference which is within the block definition, we transform the clone.&lt;/P&gt;
&lt;P&gt;The upper code works for me.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Nov 2021 09:41:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/get-all-entities-inside-a-blockreference/m-p/10775872#M14537</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2021-11-23T09:41:01Z</dc:date>
    </item>
    <item>
      <title>Re: Get all entities inside a blockreference</title>
      <link>https://forums.autodesk.com/t5/net-forum/get-all-entities-inside-a-blockreference/m-p/10775882#M14538</link>
      <description>&lt;P&gt;Could you please help me to test the attached dwg file.&lt;/P&gt;&lt;P&gt;I've no idea why the exception happens in my test.&lt;/P&gt;&lt;P&gt;Thank you very much !&lt;/P&gt;</description>
      <pubDate>Tue, 23 Nov 2021 09:47:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/get-all-entities-inside-a-blockreference/m-p/10775882#M14538</guid>
      <dc:creator>哀家爆</dc:creator>
      <dc:date>2021-11-23T09:47:34Z</dc:date>
    </item>
    <item>
      <title>Re: Get all entities inside a blockreference</title>
      <link>https://forums.autodesk.com/t5/net-forum/get-all-entities-inside-a-blockreference/m-p/10776893#M14539</link>
      <description>&lt;P&gt;In the "blocktest"drawing, the block is not uniformy scaled.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Nov 2021 16:42:16 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/get-all-entities-inside-a-blockreference/m-p/10776893#M14539</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2021-11-23T16:42:16Z</dc:date>
    </item>
    <item>
      <title>Re: Get all entities inside a blockreference</title>
      <link>https://forums.autodesk.com/t5/net-forum/get-all-entities-inside-a-blockreference/m-p/12757285#M14540</link>
      <description>&lt;P&gt;hi there: I am facing the same problem. I want to transform inner objects within a non uniformy scaled blockrefernce. So what should I do if the blockrefernce is not uniform scaled?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;all the best&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 May 2024 07:56:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/get-all-entities-inside-a-blockreference/m-p/12757285#M14540</guid>
      <dc:creator>NSJamieLiu</dc:creator>
      <dc:date>2024-05-07T07:56:09Z</dc:date>
    </item>
  </channel>
</rss>

