<?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 Block Parent ObjectID from Child in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/get-block-parent-objectid-from-child/m-p/8622242#M23367</link>
    <description>&lt;P&gt;I am struggling to find the parent Object ID of a child block.&amp;nbsp; I already have the ObjectID of the child object but I can't figure out how to get the parent objected without prompting the user to select it.&amp;nbsp; I was exploring GetContainer but cant get it to work without prompting the user for selection.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example: my block "FUSE-BLOCK" &lt;EM&gt;(this is variable)&lt;/EM&gt; has a child block "END-NODE" &lt;EM&gt;(this is constant)&lt;/EM&gt;.&amp;nbsp; I already have the ObjectID of the child block "END-NODE".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help is greatly appreciated, I am doing this in C#, AutoCAD 2015.&lt;/P&gt;</description>
    <pubDate>Tue, 26 Feb 2019 15:39:19 GMT</pubDate>
    <dc:creator>DirtyDanLand</dc:creator>
    <dc:date>2019-02-26T15:39:19Z</dc:date>
    <item>
      <title>Get Block Parent ObjectID from Child</title>
      <link>https://forums.autodesk.com/t5/net-forum/get-block-parent-objectid-from-child/m-p/8622242#M23367</link>
      <description>&lt;P&gt;I am struggling to find the parent Object ID of a child block.&amp;nbsp; I already have the ObjectID of the child object but I can't figure out how to get the parent objected without prompting the user to select it.&amp;nbsp; I was exploring GetContainer but cant get it to work without prompting the user for selection.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example: my block "FUSE-BLOCK" &lt;EM&gt;(this is variable)&lt;/EM&gt; has a child block "END-NODE" &lt;EM&gt;(this is constant)&lt;/EM&gt;.&amp;nbsp; I already have the ObjectID of the child block "END-NODE".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help is greatly appreciated, I am doing this in C#, AutoCAD 2015.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Feb 2019 15:39:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/get-block-parent-objectid-from-child/m-p/8622242#M23367</guid>
      <dc:creator>DirtyDanLand</dc:creator>
      <dc:date>2019-02-26T15:39:19Z</dc:date>
    </item>
    <item>
      <title>Re: Get Block Parent ObjectID from Child</title>
      <link>https://forums.autodesk.com/t5/net-forum/get-block-parent-objectid-from-child/m-p/8622358#M23368</link>
      <description>&lt;P&gt;If there can be any number of occurrences of a parent block reference, Each of which contains an occurrence of a given child element, t&lt;SPAN style="font-family: inherit;"&gt;hen you have to identify one of parents. You can do that either by prompting the user to select one or using some other criteria to find it.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Beyond that, I think you would need to further explain what your ultimate objective is and/or include some code.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/3964837"&gt;@DirtyDanLand&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am struggling to find the parent Object ID of a child block.&amp;nbsp; I already have the ObjectID of the child object but I can't figure out how to get the parent objected without prompting the user to select it.&amp;nbsp; I was exploring GetContainer but cant get it to work without prompting the user for selection.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example: my block "FUSE-BLOCK" &lt;EM&gt;(this is variable)&lt;/EM&gt; has a child block "END-NODE" &lt;EM&gt;(this is constant)&lt;/EM&gt;.&amp;nbsp; I already have the ObjectID of the child block "END-NODE".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help is greatly appreciated, I am doing this in C#, AutoCAD 2015.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Feb 2019 16:29:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/get-block-parent-objectid-from-child/m-p/8622358#M23368</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2019-02-26T16:29:00Z</dc:date>
    </item>
    <item>
      <title>Re: Get Block Parent ObjectID from Child</title>
      <link>https://forums.autodesk.com/t5/net-forum/get-block-parent-objectid-from-child/m-p/8622400#M23369</link>
      <description>&lt;P&gt;I'll try to explain better since my code is all over the place trying to figure this out...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a block named: "PARENTBLOCKA" (this will be a variable name)&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a block called: "&lt;SPAN style="display: inline !important; float: none; background-color: transparent; color: #666666; cursor: text; font-family: 'Artifakt',Tahoma,Helvetica,Arial,sans-serif; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; line-height: 27.42px; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;PARENTBLOCKB&lt;/SPAN&gt;"&amp;nbsp;&lt;SPAN style="display: inline !important; float: none; background-color: transparent; color: #666666; cursor: text; font-family: 'Artifakt',Tahoma,Helvetica,Arial,sans-serif; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; line-height: 27.42px; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;(this will be a variable name)&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="display: inline !important; float: none; background-color: transparent; color: #666666; cursor: text; font-family: 'Artifakt',Tahoma,Helvetica,Arial,sans-serif; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; line-height: 27.42px; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;Both the "PARENTBLOCKA" and "TERMBLOCK" have an attribute called "TAG"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;Within the "&lt;SPAN style="display: inline !important; float: none; background-color: transparent; color: #666666; cursor: text; font-family: 'Artifakt',Tahoma,Helvetica,Arial,sans-serif; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; line-height: 27.42px; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;PARENTBLOCKA&lt;/SPAN&gt;": there are multiple other blocks called "END-NODE" (END-NODE is always the same)&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="display: inline !important; float: none; background-color: transparent; color: #666666; cursor: text; font-family: 'Artifakt',Tahoma,Helvetica,Arial,sans-serif; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; line-height: 27.42px; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;Within the "&lt;SPAN style="background-color: transparent; box-sizing: border-box; color: #666666; cursor: text; display: inline; float: none; font-family: &amp;amp;quot; artifakt&amp;amp;quot;,tahoma,helvetica,arial,sans-serif; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; line-height: 27.42px; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;PARENTBLOCKB&lt;/SPAN&gt;": there are multiple other blocks called "END-NODE" (END-NODE is always the same)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="display: inline !important; float: none; background-color: transparent; color: #666666; cursor: text; font-family: 'Artifakt',Tahoma,Helvetica,Arial,sans-serif; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; line-height: 27.42px; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;The "END-NODE" block contains two attributes.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The startpoint of a polyline starts at the insertion point of "END-NODE" within the "&lt;SPAN style="display: inline !important; float: none; background-color: transparent; color: #666666; cursor: text; font-family: 'Artifakt',Tahoma,Helvetica,Arial,sans-serif; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; line-height: 27.42px; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;PARENTBLOCKA&lt;/SPAN&gt;".&amp;nbsp; The endpoint of the polyline ends at the insertion point of "END-NODE" within the "&lt;SPAN style="background-color: transparent; box-sizing: border-box; color: #666666; cursor: text; display: inline; float: none; font-family: &amp;amp;quot; artifakt&amp;amp;quot;,tahoma,helvetica,arial,sans-serif; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; line-height: 27.42px; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;PARENTBLOCKB&lt;/SPAN&gt;".&amp;nbsp; I am finding the "END-NODE" block by looking at the startpoint and endpoint of the polyline for a block called "END-NODE".&amp;nbsp; I need to be able to get the "TAG" attribute from the "&lt;SPAN style="display: inline !important; float: none; background-color: transparent; color: #666666; cursor: text; font-family: 'Artifakt',Tahoma,Helvetica,Arial,sans-serif; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; line-height: 27.42px; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;PARENTBLOCKA&lt;/SPAN&gt;" and "&lt;SPAN style="background-color: transparent; box-sizing: border-box; color: #666666; cursor: text; display: inline; float: none; font-family: &amp;amp;quot; artifakt&amp;amp;quot;,tahoma,helvetica,arial,sans-serif; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; line-height: 27.42px; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;PARENTBLOCKB&lt;/SPAN&gt;" for the respective "END-NODE" without prompting the user to select the object.&amp;nbsp; I already have the ObjectID of the "END-NODE" block at both ends of the polyline and I know which one is at the start and end, just need to figure out how to get the parent block of the "END-NODE".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope that makes sense...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Feb 2019 16:56:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/get-block-parent-objectid-from-child/m-p/8622400#M23369</guid>
      <dc:creator>DirtyDanLand</dc:creator>
      <dc:date>2019-02-26T16:56:41Z</dc:date>
    </item>
    <item>
      <title>Re: Get Block Parent ObjectID from Child</title>
      <link>https://forums.autodesk.com/t5/net-forum/get-block-parent-objectid-from-child/m-p/8623697#M23370</link>
      <description>&lt;P&gt;I think you should read my previous response again because you are obviously not understanding what I said perhaps I didn't explain it well enough. You cannot identify a given instance of a parent given nothing more than the object ID of a child element. Because there can be any number of instances of the parent, each having the same child element. If you don't want to require the user to select the power and send you must come up with some other means of finding them.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Feb 2019 04:56:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/get-block-parent-objectid-from-child/m-p/8623697#M23370</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2019-02-27T04:56:11Z</dc:date>
    </item>
    <item>
      <title>Re: Get Block Parent ObjectID from Child</title>
      <link>https://forums.autodesk.com/t5/net-forum/get-block-parent-objectid-from-child/m-p/8623767#M23371</link>
      <description>&lt;P&gt;How are you determining the ObjectID of the Child Block&amp;nbsp;&lt;SPAN&gt;"END-NODE" ??&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Feb 2019 06:14:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/get-block-parent-objectid-from-child/m-p/8623767#M23371</guid>
      <dc:creator>kerry_w_brown</dc:creator>
      <dc:date>2019-02-27T06:14:18Z</dc:date>
    </item>
    <item>
      <title>Re: Get Block Parent ObjectID from Child</title>
      <link>https://forums.autodesk.com/t5/net-forum/get-block-parent-objectid-from-child/m-p/8624687#M23372</link>
      <description>&lt;P&gt;I got it to work by iterating through the blocks inserted into model space.&amp;nbsp; For our use, I don't need anything from paper space.&amp;nbsp; Each block in model space is checked for a nested block with the "END-NODE" name, if it has the "END-NODE" nested block, the position of the "END-NODE" is checked to see if it is the same as the end of the polyline.&amp;nbsp; If it matches, the ObjectID of the block is returned.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code is a little rough right now and needs to be cleaned up, but it works the way I need it to.&amp;nbsp; Some of the code is modified code found elsewhere.&lt;/P&gt;
&lt;PRE&gt;        public static ObjectId FindEndNodeParent(string sEndNodeName, Point3d pntEndNodeLocation)
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;

            using (Transaction trans = doc.TransactionManager.StartTransaction())
            {
                BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
                BlockTableRecord ms = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace],OpenMode.ForRead);

                BlockTableRecordEnumerator it = ms.GetEnumerator();
                while (it.MoveNext())
                {
                    Entity ent = (Entity)trans.GetObject(it.Current, OpenMode.ForRead);
                    if (ent.GetType() == typeof(BlockReference))
                    {
                        BlockReference blkRef = (BlockReference)ent;
                        //MessageBox.Show(blkRef.Name);

                        if (IsNodeParent(blkRef, sEndNodeName, pntEndNodeLocation) == true)
                         {
                            return blkRef.ObjectId;
                        }

                        if (blkRef.IsDynamicBlock)
                        {
                            // Here you have a DynamicBlock reference.
                        }
                    }
                }
                it.Dispose();

                trans.Commit();
            }
            return ObjectId.Null;
        }

        private static Boolean IsNodeParent(BlockReference parentBlockRef, string sEndNodeName, Point3d pntEndNodeLocation)
        {
            var trans = parentBlockRef.Database.TransactionManager.TopTransaction;
            var btr = (BlockTableRecord)trans.GetObject(parentBlockRef.BlockTableRecord, OpenMode.ForRead);
            foreach (ObjectId id in btr)
            {
                if (id.ObjectClass.Name == "AcDbBlockReference")
                {
                    var nestedBlockRef = (BlockReference)trans.GetObject(id, OpenMode.ForRead);
                    if (nestedBlockRef.Name == sEndNodeName &amp;amp; nestedBlockRef.Position == pntEndNodeLocation)
                    {
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
            }
            return false;
        }
&lt;/PRE&gt;</description>
      <pubDate>Wed, 27 Feb 2019 13:45:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/get-block-parent-objectid-from-child/m-p/8624687#M23372</guid>
      <dc:creator>DirtyDanLand</dc:creator>
      <dc:date>2019-02-27T13:45:50Z</dc:date>
    </item>
  </channel>
</rss>

