<?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: Transform point coordinates in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/transform-point-coordinates/m-p/7986617#M26052</link>
    <description>&lt;P&gt;i mean what i read &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; sry for my englisch ... if there is way how to use it i would like to know:)&lt;/P&gt;</description>
    <pubDate>Tue, 08 May 2018 08:52:50 GMT</pubDate>
    <dc:creator>BestFriendCZ</dc:creator>
    <dc:date>2018-05-08T08:52:50Z</dc:date>
    <item>
      <title>Transform point coordinates</title>
      <link>https://forums.autodesk.com/t5/net-forum/transform-point-coordinates/m-p/7982411#M26042</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;Could somebody help me with the transformation of points? I have point of nested block which have totally different coordinates like in UI.&amp;nbsp;I have some confusion about it. i tested some type of transformation but without success. Thanks for any help &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;my code&lt;/P&gt;&lt;PRE&gt; [CommandMethod("Test", CommandFlags.Session)]
        public void Test()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                db.ResolveXrefs(true, false);
                BlockTableRecord mspace =(BlockTableRecord)tr.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(db), OpenMode.ForRead);
                BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
                string blkName = "CP DIGGING HOLE_3";
                if (bt.Has(blkName))
                {
                    BlockTableRecord btr =(BlockTableRecord)tr.GetObject(bt[blkName], OpenMode.ForRead);
                    foreach (ObjectId id in btr.GetBlockReferenceIds(true, false))
                    {
                        BlockReference br = (BlockReference)tr.GetObject(id, OpenMode.ForRead);
                    }
                }
                tr.Commit();
            }
        }&lt;/PRE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Pic 1" style="width: 999px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/496989i06E53C959C5BCECF/image-size/large?v=v2&amp;amp;px=999" role="button" title="file1.png" alt="Pic 1" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Pic 1&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Pic2" style="width: 522px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/496990iA62D5535AA83310D/image-size/large?v=v2&amp;amp;px=999" role="button" title="file2.png" alt="Pic2" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Pic2&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 05 May 2018 19:39:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/transform-point-coordinates/m-p/7982411#M26042</guid>
      <dc:creator>BestFriendCZ</dc:creator>
      <dc:date>2018-05-05T19:39:17Z</dc:date>
    </item>
    <item>
      <title>Re: Transform point coordinates</title>
      <link>https://forums.autodesk.com/t5/net-forum/transform-point-coordinates/m-p/7982436#M26043</link>
      <description>&lt;P&gt;Little progress BlockTableRecord does not contains my blocks without explode parent block. Doesn't matter of using COM API or .NET. API. Hmmm this is bad ... It look like there is no possible get coordinates of nested&amp;nbsp; block without explode parent block... Or am i wrong? &lt;span class="lia-unicode-emoji" title=":smiling_face_with_smiling_eyes:"&gt;😊&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 05 May 2018 20:12:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/transform-point-coordinates/m-p/7982436#M26043</guid>
      <dc:creator>BestFriendCZ</dc:creator>
      <dc:date>2018-05-05T20:12:10Z</dc:date>
    </item>
    <item>
      <title>Re: Transform point coordinates</title>
      <link>https://forums.autodesk.com/t5/net-forum/transform-point-coordinates/m-p/7982981#M26044</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the block references you're looking for positions are first level nested, you can use tne blockTransform matrix of the parent block reference.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;        [CommandMethod("Test")]
        public static void Test()
        {
            var doc = Application.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;
            using (var tr = db.TransactionManager.StartTransaction())
            {
                db.ResolveXrefs(true, false);
                var mspace = (BlockTableRecord)tr.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(db), OpenMode.ForRead);
                var bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
                string blkName = "bloc"; //string blkName = "CP DIGGING HOLE_3";
                if (bt.Has(blkName))
                {
                    var btr = (BlockTableRecord)tr.GetObject(bt[blkName], OpenMode.ForRead);
                    foreach (ObjectId id in btr.GetBlockReferenceIds(true, false))
                    {
                        var br = (BlockReference)tr.GetObject(id, OpenMode.ForRead);
                        var owner = (BlockTableRecord)tr.GetObject(br.OwnerId, OpenMode.ForRead);
                        // if the owner is a layout (i.e., the block reference is not nested)
                        if (owner.IsLayout)
                        {
                            ed.WriteMessage("\nPosition: {0}", br.Position);
                        }
                        // else, the owner is a block definition (i.e., the block reference is nested)
                        else
                        {
                            foreach (ObjectId parentId in owner.GetBlockReferenceIds(true, false))
                            {
                                var parent = (BlockReference)tr.GetObject(parentId, OpenMode.ForRead);
                                ed.WriteMessage("\nPosition: {0}", br.Position.TransformBy(parent.BlockTransform));
                            }
                        }
                    }
                }
                tr.Commit();
            }
        }&lt;/PRE&gt;
&lt;P&gt;If the refernces may be deeper nested, you have to do this recursively.&lt;/P&gt;</description>
      <pubDate>Sun, 06 May 2018 13:00:31 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/transform-point-coordinates/m-p/7982981#M26044</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2018-05-06T13:00:31Z</dc:date>
    </item>
    <item>
      <title>Re: Transform point coordinates</title>
      <link>https://forums.autodesk.com/t5/net-forum/transform-point-coordinates/m-p/7983048#M26045</link>
      <description>&lt;P&gt;Hi Gile,&lt;/P&gt;&lt;P&gt;thanks for information. I will try make it recursively because my block is on 3.level . BTW: I still learn AutoCAD API and in past i used many your code examples on this forum. Really good job ... newcomers will appreciate it &lt;span class="lia-unicode-emoji" title=":smiling_face_with_smiling_eyes:"&gt;😊&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 06 May 2018 14:30:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/transform-point-coordinates/m-p/7983048#M26045</guid>
      <dc:creator>BestFriendCZ</dc:creator>
      <dc:date>2018-05-06T14:30:44Z</dc:date>
    </item>
    <item>
      <title>Re: Transform point coordinates</title>
      <link>https://forums.autodesk.com/t5/net-forum/transform-point-coordinates/m-p/7983269#M26046</link>
      <description>&lt;P&gt;it's working:) thank for teach me something new&lt;/P&gt;</description>
      <pubDate>Sun, 06 May 2018 18:58:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/transform-point-coordinates/m-p/7983269#M26046</guid>
      <dc:creator>BestFriendCZ</dc:creator>
      <dc:date>2018-05-06T18:58:23Z</dc:date>
    </item>
    <item>
      <title>Re: Transform point coordinates</title>
      <link>https://forums.autodesk.com/t5/net-forum/transform-point-coordinates/m-p/7983305#M26047</link>
      <description>&lt;P&gt;josef,&lt;/P&gt;&lt;P&gt;because you are new to the API and keeping in mind people looking for this solution in the future, it would be a good idea for you to post your solution.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 06 May 2018 19:43:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/transform-point-coordinates/m-p/7983305#M26047</guid>
      <dc:creator>kerry_w_brown</dc:creator>
      <dc:date>2018-05-06T19:43:18Z</dc:date>
    </item>
    <item>
      <title>Re: Transform point coordinates</title>
      <link>https://forums.autodesk.com/t5/net-forum/transform-point-coordinates/m-p/7983390#M26048</link>
      <description>&lt;P&gt;Hi Kdub,&lt;/P&gt;&lt;P&gt;i just only modified sample code for my purpose. Here is&amp;nbsp;current test code&lt;/P&gt;&lt;PRE&gt;[CommandMethod("GetBlockPosition", CommandFlags.Session)]
        public void GetBlockPosition()
        {
            var doc = Application.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;
            try
            {
                using (var tr = db.TransactionManager.StartTransaction())
                {
                    var bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
                    string blkName = "bloc"; //string blkName = "CP DIGGING HOLE_3";
                    if (bt.Has(blkName))
                    {
                        var btr = (BlockTableRecord)tr.GetObject(bt[blkName], OpenMode.ForRead);
                        foreach (ObjectId id in btr.GetBlockReferenceIds(true, false))
                        {
                            var br = (BlockReference)tr.GetObject(id, OpenMode.ForRead);
                            var owner = (BlockTableRecord)tr.GetObject(br.OwnerId, OpenMode.ForRead);
                            // if the owner is a layout (i.e., the block reference is not nested)
                            if (owner.IsLayout)
                            {
                                ed.WriteMessage("\nPosition: {0}", br.Position);
                            }
                            // else, the owner is a block definition (i.e., the block reference is nested)
                            else
                            {
                                foreach (ObjectId parentId in owner.GetBlockReferenceIds(true, false))
                                {
                                    var parent = (BlockReference)tr.GetObject(parentId, OpenMode.ForRead);
                                    ed.WriteMessage("\nPosition: {0}", TransformCordinates(parent, tr, br.Position.TransformBy(parent.BlockTransform)));
                                }
                            }
                        }
                    }
                    tr.Commit();
                }
            }
            catch (Exception e)
            {
                ed.WriteMessage($" Critical error: { e.Message} ");
                return;
            }       
        }
        private Point3d TransformRecursively(BlockReference btr, Transaction tr, Point3d nestedPoint)
        {
            try
            {
                var owner = (BlockTableRecord)tr.GetObject(btr.OwnerId, OpenMode.ForRead);
                BlockReference parent =null;
                foreach (ObjectId parentId in owner.GetBlockReferenceIds(true, false))
                {
                    parent = (BlockReference)tr.GetObject(parentId, OpenMode.ForRead);
                    nestedPoint = nestedPoint.TransformBy(parent.BlockTransform);
                    break;
                }
                if (parent != null)
                    TransformRecursively(parent, tr, nestedPoint);
                return nestedPoint;
            }
            catch 
            {
                return new Point3d();
            }          
        }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 06 May 2018 21:47:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/transform-point-coordinates/m-p/7983390#M26048</guid>
      <dc:creator>BestFriendCZ</dc:creator>
      <dc:date>2018-05-06T21:47:10Z</dc:date>
    </item>
    <item>
      <title>Re: Transform point coordinates</title>
      <link>https://forums.autodesk.com/t5/net-forum/transform-point-coordinates/m-p/7984664#M26049</link>
      <description>&lt;P&gt;Do you think it will be possible ... write something similar without COM API? only using AcadBlockReference and etc..&lt;/P&gt;</description>
      <pubDate>Mon, 07 May 2018 13:19:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/transform-point-coordinates/m-p/7984664#M26049</guid>
      <dc:creator>BestFriendCZ</dc:creator>
      <dc:date>2018-05-07T13:19:32Z</dc:date>
    </item>
    <item>
      <title>Re: Transform point coordinates</title>
      <link>https://forums.autodesk.com/t5/net-forum/transform-point-coordinates/m-p/7985622#M26050</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/5730818"&gt;@BestFriendCZ&lt;/a&gt;wrote:&lt;BR /&gt;&lt;P&gt;Do you think it will be possible ... write something similar without COM API? only using AcadBlockReference and etc..&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;I can't see any references to&amp;nbsp;COM code in your posted example.&lt;/P&gt;&lt;P&gt;I can't imagine why you would want to use COM code.&lt;/P&gt;</description>
      <pubDate>Mon, 07 May 2018 20:19:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/transform-point-coordinates/m-p/7985622#M26050</guid>
      <dc:creator>kerry_w_brown</dc:creator>
      <dc:date>2018-05-07T20:19:07Z</dc:date>
    </item>
    <item>
      <title>Re: Transform point coordinates</title>
      <link>https://forums.autodesk.com/t5/net-forum/transform-point-coordinates/m-p/7985829#M26051</link>
      <description>&lt;P&gt;meaby i wrong described it.....but this code i can't use in exe application ... and this is my main problem atm...&amp;nbsp;&amp;nbsp;i need modify one function in large project which is wrote using another API...code work with object like&amp;nbsp;acadblockreference&amp;nbsp; and not with blockrerefence...&amp;nbsp;if i will use any objects from Acdbmgd or another dll like this so exe app fire error immediately....what i wrote on forum there is no way use this dll in exe app...My plan is change this project to this API but it will takes some time ... so i try to find faster solution&lt;/P&gt;</description>
      <pubDate>Mon, 07 May 2018 22:59:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/transform-point-coordinates/m-p/7985829#M26051</guid>
      <dc:creator>BestFriendCZ</dc:creator>
      <dc:date>2018-05-07T22:59:49Z</dc:date>
    </item>
    <item>
      <title>Re: Transform point coordinates</title>
      <link>https://forums.autodesk.com/t5/net-forum/transform-point-coordinates/m-p/7986617#M26052</link>
      <description>&lt;P&gt;i mean what i read &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; sry for my englisch ... if there is way how to use it i would like to know:)&lt;/P&gt;</description>
      <pubDate>Tue, 08 May 2018 08:52:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/transform-point-coordinates/m-p/7986617#M26052</guid>
      <dc:creator>BestFriendCZ</dc:creator>
      <dc:date>2018-05-08T08:52:50Z</dc:date>
    </item>
    <item>
      <title>Re: Transform point coordinates</title>
      <link>https://forums.autodesk.com/t5/net-forum/transform-point-coordinates/m-p/7987354#M26053</link>
      <description>&lt;P&gt;I am not sure the other post about nested block's coordinate was also from you (using different user name alias?). After all the discussion, and you say you are doing EXE. So, yes, you are correct that AutoCAD .NET API dlls cannot be used with EXE app (at least not directly). While I am not fan of using EXE to control AutoCAD (via AutoCAD COM API), which can hardly be a good business solution in most cases, it is rather simple to do what you want (getting real location/coordinates of a nested block presenting inside a block reference) with COM API. Here is sample code in AutoCAD VBA that just does that (assume only one level of nesting for simplicity):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Option Explicit

Public Sub TestNestedBlock()

    Dim ent As AcadEntity
    Dim blk As AcadBlockReference
    Dim pt As Variant
    
    On Error Resume Next
    ThisDrawing.Utility.GetEntity ent, pt, vbCr &amp;amp; "Select a block:"
    
    If ent Is Nothing Then Exit Sub
    If TypeOf ent Is AcadBlockReference Then
        Set blk = ent
        FindNestedBlockLocations blk
    Else
        MsgBox "Selected entity is not a block!"
    End If
    
End Sub

Private Sub FindNestedBlockLocations(bref As AcadBlockReference)
    
    Dim blk As AcadBlock
    Dim ent As AcadEntity
    Dim nestedBlk As AcadBlockReference
    Dim count As Integer
    
    Set blk = ThisDrawing.Blocks(bref.Name)
    For Each ent In blk
        If TypeOf ent Is AcadBlockReference Then
            Set nestedBlk = ent
            GetNestedBlockLocation nestedBlk.InsertionPoint, bref.InsertionPoint
            count = count + 1
        End If
    Next
    
    If count = 0 Then
        MsgBox "Selected block does not have a nested block inside!"
    Else
        MsgBox count &amp;amp; " nested block(s) found!"
    End If

End Sub

Private Sub GetNestedBlockLocation(basePt As Variant, brefPt As Variant)

    Dim location(0 To 2) As Double

    location(0) = brefPt(0) + basePt(0)
    location(1) = brefPt(1) + basePt(1)
    location(2) = brefPt(2) + basePt(2)
    
    MsgBox "Found nested block at: " &amp;amp; vbCr &amp;amp; _
        "X=" &amp;amp; location(0) &amp;amp; vbCr &amp;amp; _
        "Y=" &amp;amp; location(1) &amp;amp; vbCr &amp;amp; _
        "Z=" &amp;amp; location(2)

End Sub&lt;/PRE&gt;
&lt;P&gt;Well, if you go the COM API route, then it would be better to post &lt;A href="https://forums.autodesk.com/t5/visual-basic-customization/bd-p/33" target="_blank"&gt;here.&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HTH&lt;/P&gt;</description>
      <pubDate>Tue, 08 May 2018 14:04:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/transform-point-coordinates/m-p/7987354#M26053</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2018-05-08T14:04:56Z</dc:date>
    </item>
    <item>
      <title>Re: Transform point coordinates</title>
      <link>https://forums.autodesk.com/t5/net-forum/transform-point-coordinates/m-p/7987564#M26054</link>
      <description>&lt;P&gt;Hi Norman,&lt;BR /&gt;no i write on forum only under my nick. SporadicCoder have totally different level englisch opposite me. To this problem i created only this post:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Transform point coordinates&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;Alternative COM API vs .NET API&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;Problem about coordinates&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and reason was becuase i found everytime additional problem. I am not fan using EXE too and i agree with your opinion on it but if you have to modify large project (thousand and thousand line of code) which was created by someone else like exe App so it is problem.&lt;BR /&gt;My plan is rewrite complete project like DLL but it takes some time and i am still learn AutoCAD... Thank you for your sample i will test it and i apologize for the inaccurate description of my problem.&lt;/P&gt;</description>
      <pubDate>Tue, 08 May 2018 15:28:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/transform-point-coordinates/m-p/7987564#M26054</guid>
      <dc:creator>BestFriendCZ</dc:creator>
      <dc:date>2018-05-08T15:28:33Z</dc:date>
    </item>
    <item>
      <title>Re: Transform point coordinates</title>
      <link>https://forums.autodesk.com/t5/net-forum/transform-point-coordinates/m-p/7988176#M26055</link>
      <description>&lt;P&gt;I tested sample code and it return the wrong coordinates ...i tryed to make recursively and after only explode parent block and select child block which contains nested block and result was wrong too.. &lt;SPAN&gt;sample code works only on first nested block in&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;base block&lt;/SPAN&gt;&lt;BR /&gt;I decided to rewrite this part of code to DLL and return result somehow... but now i have problem with rotation all coordinates are good&lt;BR /&gt;Parent block have good rotation ... first nested block have good rotation too but second nested block have rotation 0 and good is 1.5.... (90°). I would like to know what is wrong at this code?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt; [CommandMethod("ScanBlocks")]
        public void ScanBlocks()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            using (DocumentLock acLckDoc = doc.LockDocument())//lock mother window during print
            {
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    RXClass blockReferenceType = RXClass.GetClass(typeof(BlockReference));
                    DBDictionary layouts = (DBDictionary)tr.GetObject(db.LayoutDictionaryId, OpenMode.ForRead);
                    foreach (var lay in layouts)
                    {
                        if (lay.Key.ToLower() == "model")
                        {
                            Layout layout = (Layout)tr.GetObject(lay.Value, OpenMode.ForRead);
                            BlockTableRecord btr = (BlockTableRecord)tr.GetObject(layout.BlockTableRecordId, OpenMode.ForRead);
                            foreach (ObjectId id in btr)
                            {
                                if (id.ObjectClass == blockReferenceType)
                                {
                                    //get all blocks which are type BlockReference on first level in model layout
                                    BlockReference baseBlock = (BlockReference)tr.GetObject(id, OpenMode.ForRead);
                                    //loop through all blocks reference
                                    LoopNestedBlocks(tr, baseBlock,null);
                                }
                            }
                        }
                    }
                }
            }
        }
       private static void LoopNestedBlocks(Transaction trParent, BlockReference brChild, BlockReference brParent)
        {
            BlockTableRecord btr = (BlockTableRecord)trParent.GetObject(brChild.BlockTableRecord, OpenMode.ForRead);
            if (btr != null)
            {
                Point3d bockPosition;
                if (brParent != null)
                {
                    bockPosition = TransformPositionRecursively(brParent, trParent, brChild.Position.TransformBy(brParent.BlockTransform));
                }
                else { bockPosition = brChild.Position; }
                Debug.Print(brChild.Name + "  " + bockPosition.X + "  " + bockPosition.Y + "  " + bockPosition.Z + "  " + brChild.Rotation);
                foreach (ObjectId id in btr)
                {
                    Entity blockEntity = (Entity)trParent.GetObject(id, OpenMode.ForRead);

                    if (blockEntity is BlockReference)
                        LoopNestedBlocks(trParent, (BlockReference)blockEntity, brChild);
                }
            }
        }
        private static Point3d TransformPositionRecursively(BlockReference btr, Transaction trParent, Point3d nestedPoint)
        {
            try
            {
                BlockTableRecord owner = (BlockTableRecord)trParent.GetObject(btr.OwnerId, OpenMode.ForRead);
                BlockReference parent = null;
                foreach (ObjectId parentId in owner.GetBlockReferenceIds(true, false))
                {
                    parent = (BlockReference)trParent.GetObject(parentId, OpenMode.ForRead);
                    nestedPoint = nestedPoint.TransformBy(parent.BlockTransform);            
                    break;
                }
                if (parent != null)
                    TransformPositionRecursively(parent, trParent, nestedPoint);
                return nestedPoint;
            }
            catch
            {
                return new Point3d();
            }
        }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 May 2018 18:55:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/transform-point-coordinates/m-p/7988176#M26055</guid>
      <dc:creator>BestFriendCZ</dc:creator>
      <dc:date>2018-05-08T18:55:03Z</dc:date>
    </item>
    <item>
      <title>Re: Transform point coordinates</title>
      <link>https://forums.autodesk.com/t5/net-forum/transform-point-coordinates/m-p/7988376#M26056</link>
      <description>&lt;P&gt;ok i found another bug in sampe code up... will be long night:(. i stopped focus on my block and tryed to test function on large structure and position are wrong atleast some of them.&lt;BR /&gt;reason is because this row returns colection parent of blockreference and me need only one right parent blockreference for my child blockreference.&lt;/P&gt;&lt;P&gt;BlockTableRecord owner = (BlockTableRecord)trParent.GetObject(btr.OwnerId, OpenMode.ForRead);&lt;/P&gt;</description>
      <pubDate>Tue, 08 May 2018 20:24:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/transform-point-coordinates/m-p/7988376#M26056</guid>
      <dc:creator>BestFriendCZ</dc:creator>
      <dc:date>2018-05-08T20:24:53Z</dc:date>
    </item>
    <item>
      <title>Re: Transform point coordinates</title>
      <link>https://forums.autodesk.com/t5/net-forum/transform-point-coordinates/m-p/7988633#M26057</link>
      <description>&lt;P&gt;i tried modify function but without success.Is there some way how to indetify parent blockreference?&lt;BR /&gt;because every parent block contains reference to child block with same name, ID,BlockID but in different position.&lt;BR /&gt;Is there a way how to find that right? BTW i use this way because i try to keep the block list as in the old application&lt;/P&gt;&lt;PRE&gt;  private static Point3d TransformPositionRecursively(BlockReference btr, Transaction trParent, Point3d nestedPoint)
        {
            try
            {
                Point3d point3D;
                BlockTableRecord owner = (BlockTableRecord)trParent.GetObject(btr.OwnerId, OpenMode.ForRead);
                BlockReference parent = null;
                foreach (ObjectId parentId in owner.GetBlockReferenceIds(true, false))
                {
                    parent = (BlockReference)trParent.GetObject(parentId, OpenMode.ForRead);

                    BlockTableRecord btr2 = (BlockTableRecord)trParent.GetObject(parent.BlockTableRecord, OpenMode.ForRead);
                    if (btr2 != null)
                    {
                        foreach (ObjectId id in btr2)
                        {
                            Entity blockEntity = (Entity)trParent.GetObject(id, OpenMode.ForRead);
                            if (blockEntity is BlockReference)
                            {
                                BlockReference testBlocRef = (BlockReference)blockEntity;
                                if (testBlocRef.Id == btr.Id)
                                {
                                    point3D = nestedPoint.TransformBy(parent.BlockTransform);
                                    break;
                                }
                            }
                        }
                    }
                }
                if (parent != null)
                    TransformPositionRecursively(parent, trParent, nestedPoint);
                return nestedPoint;
            }
            catch ()
            {
                return new Point3d();
            }
        }&lt;/PRE&gt;</description>
      <pubDate>Tue, 08 May 2018 22:41:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/transform-point-coordinates/m-p/7988633#M26057</guid>
      <dc:creator>BestFriendCZ</dc:creator>
      <dc:date>2018-05-08T22:41:46Z</dc:date>
    </item>
    <item>
      <title>Re: Transform point coordinates</title>
      <link>https://forums.autodesk.com/t5/net-forum/transform-point-coordinates/m-p/7989085#M26058</link>
      <description>&lt;P&gt;Try this one:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;        [CommandMethod("Test")]
        public static void Test()
        {
            var doc = Application.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;
            using (var tr = db.TransactionManager.StartTransaction())
            {
                db.ResolveXrefs(true, false);
                var mspace = (BlockTableRecord)tr.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(db), OpenMode.ForRead);
                var bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
                string blkName = "CP DIGGING HOLE_3";
                if (bt.Has(blkName))
                {
                    var btr = (BlockTableRecord)tr.GetObject(bt[blkName], OpenMode.ForRead);
                    foreach (Point3d pt in GetNestedPositions(btr, Point3d.Origin, tr))
                    {
                        ed.WriteMessage($"\n{pt}");
                    }
                }
                tr.Commit();
            }
        }

        private static List&amp;lt;Point3d&amp;gt; GetNestedPositions(BlockTableRecord btr, Point3d position, Transaction tr)
        {
            List&amp;lt;Point3d&amp;gt; positions = new List&amp;lt;Point3d&amp;gt;();
            foreach (ObjectId id in btr.GetBlockReferenceIds(true, false))
            {
                var br = (BlockReference)tr.GetObject(id, OpenMode.ForRead);
                var owner = (BlockTableRecord)tr.GetObject(br.OwnerId, OpenMode.ForRead);
                if (owner.IsLayout)
                {
                    positions.Add(position.TransformBy(br.BlockTransform));
                }
                else
                {
                    positions.AddRange(GetNestedPositions(owner, position.TransformBy(br.BlockTransform), tr));
                }
            }
            return positions;
        }&lt;/PRE&gt;</description>
      <pubDate>Wed, 09 May 2018 06:05:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/transform-point-coordinates/m-p/7989085#M26058</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2018-05-09T06:05:11Z</dc:date>
    </item>
    <item>
      <title>Re: Transform point coordinates</title>
      <link>https://forums.autodesk.com/t5/net-forum/transform-point-coordinates/m-p/7989514#M26059</link>
      <description>&lt;P&gt;Hi Gile,&lt;/P&gt;&lt;P&gt;thank you for your sample but i know about this but this is not exactly what i need. I try to explain on the picture.&amp;nbsp; I have DWG which contains many block like CP130100-07 and these blocks contains for example nested block CP DIGGING HOLE_1. Function returns list of block CP DIGGING HOLE_1 with corect coordination but how can i identify right parent block reference for populate list of block like is on picture.&amp;nbsp;This list contains complete list of block with specific order.&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-inline" image-alt="pic3.png" style="width: 870px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/498259i09528D4604D1BC82/image-size/large?v=v2&amp;amp;px=999" role="button" title="pic3.png" alt="pic3.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;this list is result similar functions as this&lt;/P&gt;&lt;PRE&gt;    [CommandMethod("ScanBlocks")]
        public void ScanBlocks()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            using (DocumentLock acLckDoc = doc.LockDocument())//lock mother window during print
            {
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    RXClass blockReferenceType = RXClass.GetClass(typeof(BlockReference));
                    DBDictionary layouts = (DBDictionary)tr.GetObject(db.LayoutDictionaryId, OpenMode.ForRead);
                    foreach (var lay in layouts)
                    {
                        if (lay.Key.ToLower() == "model")
                        {
                            Layout layout = (Layout)tr.GetObject(lay.Value, OpenMode.ForRead);
                            BlockTableRecord btr = (BlockTableRecord)tr.GetObject(layout.BlockTableRecordId, OpenMode.ForRead);
                            foreach (ObjectId id in btr)
                            {
                                if (id.ObjectClass == blockReferenceType)
                                {
                                    BlockReference baseBlock = (BlockReference)tr.GetObject(id, OpenMode.ForRead);
                                    LoopNestedBlocks( tr, baseBlock);
                                }
                            }
                        }
                    }
                }
            }
        }
        private static void LoopNestedBlocks(Transaction trParent, BlockReference brCurrent)
        {
            BlockTableRecord btr = (BlockTableRecord)trParent.GetObject(brCurrent.BlockTableRecord, OpenMode.ForRead);
            if (btr != null)
            {
                Debug.Print(brCurrent.Name);
                foreach (ObjectId id in btr)
                {
                    Entity childEntity = (Entity)trParent.GetObject(id, OpenMode.ForRead);
                    if (childEntity is BlockReference)
                        LoopNestedBlocks(trParent, (BlockReference)childEntity);
                }
            }
        }&lt;/PRE&gt;</description>
      <pubDate>Wed, 09 May 2018 09:50:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/transform-point-coordinates/m-p/7989514#M26059</guid>
      <dc:creator>BestFriendCZ</dc:creator>
      <dc:date>2018-05-09T09:50:05Z</dc:date>
    </item>
    <item>
      <title>Re: Transform point coordinates</title>
      <link>https://forums.autodesk.com/t5/net-forum/transform-point-coordinates/m-p/7990099#M26060</link>
      <description>&lt;P&gt;i tried use another way transform coordinates from parent to child but nested coordinate are wrong and from child to parent i don't know have how identify parent reference for my sample. I'm getting a little desperate &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt; [CommandMethod("ScanBlocks")]
        public void ScanBlocks()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            using (DocumentLock acLckDoc = doc.LockDocument())//lock mother window during print
            {
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    RXClass blockReferenceType = RXClass.GetClass(typeof(BlockReference));
                    DBDictionary layouts = (DBDictionary)tr.GetObject(db.LayoutDictionaryId, OpenMode.ForRead);
                    foreach (var lay in layouts)
                    {
                        if (lay.Key.ToLower() == "model")
                        {
                            Layout layout = (Layout)tr.GetObject(lay.Value, OpenMode.ForRead);
                            BlockTableRecord btr = (BlockTableRecord)tr.GetObject(layout.BlockTableRecordId, OpenMode.ForRead);
                            foreach (ObjectId id in btr)
                            {
                                if (id.ObjectClass == blockReferenceType)
                                {
                                    BlockReference baseBlock = (BlockReference)tr.GetObject(id, OpenMode.ForRead);
                                    List&amp;lt;DrawingElement&amp;gt; test = new List&amp;lt;DrawingElement&amp;gt;();
                                    LoopNestedBlocks(test, tr, baseBlock, new PointTransformed());

                                    foreach (DrawingElement item in test)
                                    {
                                        //roration is 0 in second level nested block?
                                        Debug.Print(item.BlocName + " " + item.Cordinate.Position.X + " " + item.Cordinate.Position.Y + " " + item.Cordinate.Position.Z + " " + item.Cordinate.Rotation);
                                    }


                                }
                            }
                        }
                    }
                }
            }
        }
        class DrawingElement
        {
            public string BlocName { get; set; }
            public PointTransformed Cordinate { get; set; }
        }
        class PointTransformed
        {
            public Point3d Position { get; set; }
            public Boolean IsNull { get; set; } = true;
            public double Rotation { get; set; }
        }
        private static List&amp;lt;DrawingElement&amp;gt; LoopNestedBlocks(List&amp;lt;DrawingElement&amp;gt; currentList, Transaction trParent, BlockReference brCurrent, PointTransformed pointParent)
        {
            BlockTableRecord btr = (BlockTableRecord)trParent.GetObject(brCurrent.BlockTableRecord, OpenMode.ForRead);
            if (btr != null)
            {
                PointTransformed pointCurrent;
                if (!pointParent.IsNull)
                {
                    pointCurrent = new PointTransformed()
                    {
                        Position = pointParent.Position.TransformBy(brCurrent.BlockTransform),
                        IsNull = false
                    };
                }
                else
                {
                    pointCurrent = pointCurrent = new PointTransformed()
                    {
                        Position = brCurrent.Position,
                        IsNull = false
                    };
                }
                DrawingElement currentElement = new DrawingElement();
                currentElement.Cordinate = pointCurrent;
                currentElement.BlocName = brCurrent.Name;
                currentElement.Cordinate.Rotation = brCurrent.Rotation;
                currentList.Add(currentElement);

                foreach (ObjectId id in btr)
                {
                    Entity childEntity = (Entity)trParent.GetObject(id, OpenMode.ForRead);
                    if (childEntity is BlockReference)
                        LoopNestedBlocks(currentList, trParent, (BlockReference)childEntity, pointCurrent);
                }
            }
            return currentList;
        }&lt;/PRE&gt;</description>
      <pubDate>Wed, 09 May 2018 13:40:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/transform-point-coordinates/m-p/7990099#M26060</guid>
      <dc:creator>BestFriendCZ</dc:creator>
      <dc:date>2018-05-09T13:40:09Z</dc:date>
    </item>
    <item>
      <title>Re: Transform point coordinates</title>
      <link>https://forums.autodesk.com/t5/net-forum/transform-point-coordinates/m-p/7991742#M26061</link>
      <description>&lt;P&gt;Looks like it works ... i checked on few DWG and it works correct...last problem are rotations. &lt;STRONG&gt;Does anybody know how to get rotation from nested block? because blockreference rotation doesn't have property TransformBy&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt; [CommandMethod("ScanBlocks")]
        public void ScanBlocks()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            using (DocumentLock acLckDoc = doc.LockDocument())//lock mother window
            {
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    RXClass blockReferenceType = RXClass.GetClass(typeof(BlockReference));
                    DBDictionary layouts = (DBDictionary)tr.GetObject(db.LayoutDictionaryId, OpenMode.ForRead);
                    foreach (var lay in layouts)
                    {
                        if (lay.Key.ToLower() == "model")
                        {
                            Layout layout = (Layout)tr.GetObject(lay.Value, OpenMode.ForRead);
                            BlockTableRecord btr = (BlockTableRecord)tr.GetObject(layout.BlockTableRecordId, OpenMode.ForRead);
                            foreach (ObjectId id in btr)
                            {
                                if (id.ObjectClass == blockReferenceType)
                                {
                                    BlockReference baseBlock = (BlockReference)tr.GetObject(id, OpenMode.ForRead);
                                    List&amp;lt;DrawingElement&amp;gt; test = new List&amp;lt;DrawingElement&amp;gt;();
                                    List&amp;lt;BlockReference&amp;gt; parentReferenceList = new List&amp;lt;BlockReference&amp;gt;();
                                    int level = 0;
                                    LoopNestedBlocks(test, tr, baseBlock, parentReferenceList, ref level);
                                    if (baseBlock.Name == "BaseBlock") /*A$C70C23CFC*/
                                    {
                                        foreach (DrawingElement item in test)
                                        {
                                            Debug.Print(item.BlocName + " " + item.Cordinate.Position.X + " " + item.Cordinate.Position.Y + " " + item.Cordinate.Position.Z);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        class DrawingElement
        {
            public string BlocName { get; set; }
            public PointTransformed Cordinate { get; set; }
        }
        class PointTransformed
        {
            public Point3d Position { get; set; }
            public Boolean IsNull { get; set; } = true;
            public double Rotation { get; set; }
        }

        private static void LoopNestedBlocks(List&amp;lt;DrawingElement&amp;gt; currentList, Transaction trParent, BlockReference brCurrent, List&amp;lt;BlockReference&amp;gt; parentReferenceList, ref int parentLevel)
        {
            try
            {
                BlockTableRecord btr = (BlockTableRecord)trParent.GetObject(brCurrent.BlockTableRecord, OpenMode.ForRead);
                if (btr != null)
                {
                    List&amp;lt;DrawingElement&amp;gt; subList = new List&amp;lt;DrawingElement&amp;gt;();
                    int currentBlockLevel = 0;
                    GetCurrentLevel(brCurrent, trParent, ref currentBlockLevel, parentReferenceList);
                    if (currentBlockLevel != parentReferenceList.Count)
                        parentReferenceList.RemoveRange(currentBlockLevel, parentReferenceList.Count - currentBlockLevel);
                    Point3d currentBlockPosition = brCurrent.Position;
                    for (int i = parentReferenceList.Count; i &amp;gt; 0; i--)
                    {
                        BlockReference parentBlockRef = parentReferenceList[i - 1];
                        currentBlockPosition = currentBlockPosition.TransformBy(parentBlockRef.BlockTransform);
                    }
                    PointTransformed pointCurrent;
                    pointCurrent = new PointTransformed()
                    {
                        Position = currentBlockPosition,
                        IsNull = false
                    };
                    DrawingElement currentElement = new DrawingElement()
                    {
                        Cordinate = pointCurrent,
                        BlocName = brCurrent.Name
                    };
                    currentList.Add(currentElement);
                    parentReferenceList.Add(brCurrent);
                    parentLevel = currentBlockLevel;
                    foreach (ObjectId id in btr)
                    {
                        Entity childEntity = (Entity)trParent.GetObject(id, OpenMode.ForRead);
                        if (childEntity is BlockReference)
                            LoopNestedBlocks(currentList, trParent, (BlockReference)childEntity, parentReferenceList, ref parentLevel);
                    }
                }
            }
            catch { }
        }
        private static void GetCurrentLevel(BlockReference btr, Transaction trParent, ref int currentLevel, List&amp;lt;BlockReference&amp;gt; parentReferenceList)
        {
            try
            {
                BlockReference parent = null;
                BlockTableRecord owner = (BlockTableRecord)trParent.GetObject(btr.OwnerId, OpenMode.ForRead);
                foreach (ObjectId parentId in owner.GetBlockReferenceIds(true, false))
                {
                    parent = (BlockReference)trParent.GetObject(parentId, OpenMode.ForRead);
                    if (parentReferenceList.Contains(parent))
                    {
                        break;
                    }
                }
                if (parent != null)
                {
                    currentLevel++;
                    GetCurrentLevel(parent, trParent, ref currentLevel, parentReferenceList);
                }
            }
            catch { }
        }&lt;/PRE&gt;</description>
      <pubDate>Thu, 10 May 2018 01:40:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/transform-point-coordinates/m-p/7991742#M26061</guid>
      <dc:creator>BestFriendCZ</dc:creator>
      <dc:date>2018-05-10T01:40:23Z</dc:date>
    </item>
  </channel>
</rss>

