<?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: How to get the position of an nested block that changes size due to constraint parameter in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/how-to-get-the-position-of-an-nested-block-that-changes-size-due/m-p/11571902#M10885</link>
    <description>&lt;P&gt;Thank you very much!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You gave me very important clues;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Since I am not very familiar with the mechanism of CAD internal block generation, it creates a new anonymous block for static blocks to show, I used the wrong way to get dynamic blocks to get static blocks;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And thank you for teaching me to use ArxDbg to view the internal relationship of graphics, this is very useful;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Finally, to share the API I found in C# to help others:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;In C#, use `GetBlockReferenceIds` API to get all reference IDs of a static block, which I think are the created anonymous block IDs;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code like:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[blockName], OpenMode.ForRead);
ObjectIdCollection blockIds = btr.GetBlockReferenceIds(true, true);
foreach (ObjectId id in blockIds)
{
    BlockReference block = (BlockReference)trans.GetObject(id, OpenMode.ForRead);
    // here can get block's position
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 23 Nov 2022 03:18:00 GMT</pubDate>
    <dc:creator>YYCad·Lover</dc:creator>
    <dc:date>2022-11-23T03:18:00Z</dc:date>
    <item>
      <title>How to get the position of an nested block that changes size due to constraint parameter</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-get-the-position-of-an-nested-block-that-changes-size-due/m-p/11566258#M10883</link>
      <description>&lt;P&gt;Hi. Thank you so much guys, for your help! this problem is bothering me.&lt;/P&gt;&lt;P&gt;Problem Description:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; 1. I have a block "door" like a rectangle that has been shaped with automatic constraints;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; 2. Then a vertical constraint parameter is built in the "Door" block: "Height", so the height is 500;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; 3. In addition, an nested block like a cross is inserted: "coordinateBlock";&lt;BR /&gt;&amp;nbsp; &amp;nbsp; 4. Create a coincidence constraint on the top of the "Height" edge of "coordinateBlock" and "Door", such that the position is (0, 500);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; 5. Insert the "Door" block reference in the new file through the C# API code, and modify the "Door" constraint parameter "Height" to change the block reference height, such as from 500 to 800;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; 6. At this time, the position of the "coordinateBlock" has changed, and it has actually followed (0, 800);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Phenomenon:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; 1. The display position of the nested block "coordinateBlock" in the "Door" block in model space has indeed become (0, 800);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; 2. I have tried many methods, but I can't get the coordinate position (0, 800) after the "coordinateBlock" changes, but can only get the insert position (0, 500);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Question:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; 1. Is there any way to get the position data of the inline block changed by constraints without explode the "Door" block;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code I use:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;
Editor ed = acDoc.Editor;
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
    BlockTable acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable;
    BlockTableRecord acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForRead) as BlockTableRecord;
    
    foreach (ObjectId acObjId in acBlkTblRec)
    {
        if (acObjId.ObjectClass.Name == "AcDbBlockReference")
        {
            BlockReference bf = acObjId.GetObject(OpenMode.ForRead) as BlockReference;
            string bname = (bf.IsDynamicBlock) ? (bf.DynamicBlockTableRecord.GetObject(OpenMode.ForRead) as BlockTableRecord).Name : bf.Name;
            
            if (bname.StartsWith("Door"))
            {
                if (bf.IsDynamicBlock)
                {
                    BlockTableRecord btr = bf.DynamicBlockTableRecord.GetObject(OpenMode.ForRead) as BlockTableRecord;
                    foreach (ObjectId item in btr)
                    {
                        if (item.ObjectClass.Name == "AcDbBlockReference")
                        {
                            BlockReference btf = item.GetObject(OpenMode.ForWrite) as BlockReference;
                            string tname = (btf.IsDynamicBlock) ? (btf.DynamicBlockTableRecord.GetObject(OpenMode.ForRead) as BlockTableRecord).Name : btf.Name;

                            if (tname.StartsWith("coordinateBlock"))
                            {
                                btf.Position; // here is not change (0, 200);
                            }
                        }
                    }
                }
            }
        }
    }
    acTrans.Commit();
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Nov 2022 03:45:24 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-get-the-position-of-an-nested-block-that-changes-size-due/m-p/11566258#M10883</guid>
      <dc:creator>YYCad·Lover</dc:creator>
      <dc:date>2022-11-21T03:45:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the position of an nested block that changes size due to constraint parameter</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-get-the-position-of-an-nested-block-that-changes-size-due/m-p/11570429#M10884</link>
      <description>&lt;P&gt;When you create a dynamic BREF with a defined parameter set, the BREF doesn't point to the original block but to an unnamed block.&lt;/P&gt;
&lt;P&gt;I used the tool ArxDbg.arx from&amp;nbsp; &amp;lt;ARX&amp;gt;\\samples\database\ARXDBG to analyse TestBlock.dwg.&amp;nbsp;&lt;BR /&gt;Call SNOOPENTS and select the 800mm BREF shows this:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="UnnamedDynBlock_SNOOPENTS.png" style="width: 931px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1142928i48097F82F73C9416/image-size/large?v=v2&amp;amp;px=999" role="button" title="UnnamedDynBlock_SNOOPENTS.png" alt="UnnamedDynBlock_SNOOPENTS.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;So you see the "real" block name is "*U7".&lt;/P&gt;
&lt;P&gt;With SNOOPDB you can examine the block *U7:&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="UnnamedDynBlock_SNOOPDB.png" style="width: 892px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1142930i49693C4D7F9D9002/image-size/large?v=v2&amp;amp;px=999" role="button" title="UnnamedDynBlock_SNOOPDB.png" alt="UnnamedDynBlock_SNOOPDB.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Expand the Block Table, select *U7 from the list and hit [Entities in Block].&lt;/P&gt;
&lt;P&gt;There you find the BREF to "coordinateBlock" at position (0,800,0).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Unfortunately I can't tell you how to code this in C# - I'm more into C++.&lt;/P&gt;
&lt;P&gt;But I think you can figure out how to do it.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In C++ I would query the objectid of the BREF's blocktablerecord, open it and search for the nested BREF to&amp;nbsp;"coordinateBlock" using an iterator.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Nov 2022 09:21:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-get-the-position-of-an-nested-block-that-changes-size-due/m-p/11570429#M10884</guid>
      <dc:creator>tbrammer</dc:creator>
      <dc:date>2022-11-23T09:21:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the position of an nested block that changes size due to constraint parameter</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-get-the-position-of-an-nested-block-that-changes-size-due/m-p/11571902#M10885</link>
      <description>&lt;P&gt;Thank you very much!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You gave me very important clues;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Since I am not very familiar with the mechanism of CAD internal block generation, it creates a new anonymous block for static blocks to show, I used the wrong way to get dynamic blocks to get static blocks;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And thank you for teaching me to use ArxDbg to view the internal relationship of graphics, this is very useful;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Finally, to share the API I found in C# to help others:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;In C#, use `GetBlockReferenceIds` API to get all reference IDs of a static block, which I think are the created anonymous block IDs;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code like:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[blockName], OpenMode.ForRead);
ObjectIdCollection blockIds = btr.GetBlockReferenceIds(true, true);
foreach (ObjectId id in blockIds)
{
    BlockReference block = (BlockReference)trans.GetObject(id, OpenMode.ForRead);
    // here can get block's position
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Nov 2022 03:18:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-get-the-position-of-an-nested-block-that-changes-size-due/m-p/11571902#M10885</guid>
      <dc:creator>YYCad·Lover</dc:creator>
      <dc:date>2022-11-23T03:18:00Z</dc:date>
    </item>
  </channel>
</rss>

