<?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: C#, Get Block at Point in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/c-get-block-at-point/m-p/8189218#M34910</link>
    <description>&lt;P&gt;Just keep in mind that&lt;/P&gt;&lt;PRE&gt;btr.GetBlockReferenceIds(true, true)&lt;/PRE&gt;&lt;P&gt;will return a 0 on a dynamic block.&lt;/P&gt;&lt;P&gt;_gile himself talks about how to fetch dynamic blocks on a more recent post:&lt;/P&gt;&lt;P&gt;&lt;A href="https://forums.autodesk.com/t5/net/blockreferenceids-is-sometimes-empty/m-p/7044001#M53047" target="_blank"&gt;https://forums.autodesk.com/t5/net/blockreferenceids-is-sometimes-empty/m-p/7044001#M53047&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 09 Aug 2018 15:22:59 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2018-08-09T15:22:59Z</dc:date>
    <item>
      <title>C#, Get Block at Point</title>
      <link>https://forums.autodesk.com/t5/net-forum/c-get-block-at-point/m-p/6511299#M34901</link>
      <description>&lt;P&gt;In C#, what would be the best way to get a block inserted at a specified point?&lt;BR /&gt;&lt;BR /&gt;I am trying to get attributes from a block inserted at the endpoint of a polyline. &amp;nbsp;The endpoints of the polyline and the blockname are known.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just can not figure out how to get the block. &amp;nbsp;Once I get the block I know how to get the attributes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Dan&lt;/P&gt;</description>
      <pubDate>Fri, 19 Aug 2016 16:53:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/c-get-block-at-point/m-p/6511299#M34901</guid>
      <dc:creator>DirtyDanLand</dc:creator>
      <dc:date>2016-08-19T16:53:32Z</dc:date>
    </item>
    <item>
      <title>Re: C#, Get Block at Point</title>
      <link>https://forums.autodesk.com/t5/net-forum/c-get-block-at-point/m-p/6511343#M34902</link>
      <description>I should mention that I need to be able to do this without having the user select the block.</description>
      <pubDate>Fri, 19 Aug 2016 17:13:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/c-get-block-at-point/m-p/6511343#M34902</guid>
      <dc:creator>DirtyDanLand</dc:creator>
      <dc:date>2016-08-19T17:13:51Z</dc:date>
    </item>
    <item>
      <title>Re: C#, Get Block at Point</title>
      <link>https://forums.autodesk.com/t5/net-forum/c-get-block-at-point/m-p/6511508#M34903</link>
      <description>&lt;P&gt;With some help from this site, this is what I came up with... &amp;nbsp;Wondering, if there is a better way?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;            using (Transaction tr = acCurDb.TransactionManager.StartTransaction())
            {

                BlockTable acBlkTble = tr.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable;

                foreach (ObjectId btrObjId in acBlkTble)
                {
                    BlockTableRecord btr = tr.GetObject(btrObjId, OpenMode.ForRead) as BlockTableRecord;

                    ObjectIdCollection objIdColl = btr.GetBlockReferenceIds(true, true);

                    foreach (ObjectId objId_loopVariable in objIdColl)
                    {
                        BlockReference blk = (BlockReference)tr.GetObject(objId_loopVariable, OpenMode.ForRead);
                        blockName = blk.Name.ToUpper();

                        if (blockName.IndexOf("WIRE-END") != -1)
                        {
                            pntBlockOrigin = blk.Position;
                            if (pntBlockOrigin == pntPolyBeg)
                            {
                                //get the attributes
                                AttributeCollection attCol = blk.AttributeCollection;
                                foreach (ObjectId attId in attCol)
                                {
                                    AttributeReference attRef = (AttributeReference)tr.GetObject(attId, OpenMode.ForRead);

                                    switch (attRef.Tag.ToUpper())
                                    {
                                        case "END-ID":
                                            attBegValue[0] = attRef.TextString;
                                            break;
                                        case "END-TERM":
                                            attBegValue[1] = attRef.TextString;
                                            break;
                                    }
                                }
                            }
                            else if (pntBlockOrigin == pntPolyEnd)
                            {
                                //get the attributes
                                AttributeCollection attCol = blk.AttributeCollection;
                                foreach (ObjectId attId in attCol)
                                {
                                    AttributeReference attRef = (AttributeReference)tr.GetObject(attId, OpenMode.ForRead);

                                    switch (attRef.Tag.ToUpper())
                                    {
                                        case "END-ID":
                                            attEndValue[0] = attRef.TextString;
                                            break;
                                        case "END-TERM":
                                            attEndValue[1] = attRef.TextString;
                                            break;
                                    }
                                }
                            }

                        }
                    }
                }
                tr.Commit();
            }&lt;/PRE&gt;</description>
      <pubDate>Fri, 19 Aug 2016 18:27:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/c-get-block-at-point/m-p/6511508#M34903</guid>
      <dc:creator>DirtyDanLand</dc:creator>
      <dc:date>2016-08-19T18:27:30Z</dc:date>
    </item>
    <item>
      <title>Re: C#, Get Block at Point</title>
      <link>https://forums.autodesk.com/t5/net-forum/c-get-block-at-point/m-p/6511540#M34904</link>
      <description>&lt;P&gt;Create a pair of Point3D objects that define a window. &amp;nbsp;P3D1 will be bottom right, and P3D2 will be top left. &amp;nbsp;I use the term "aperture" - the last value I used was 20 metres. &amp;nbsp;This creates a window that is 40 metres square, with your endpoint in the centre.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;double aperture = 20.0;&lt;/P&gt;
&lt;P&gt;Point3d P3D1 = new Point3d(yourpolylineendpoint.X - aperture, yourpolylineendpoint.Y - aperture, 0);&lt;BR /&gt; Point3d P3D2 = new Point3d(yourpolylineendpoint.X + aperture, yourpolylineendpoint.Y + aperture, 0);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Define a typedvalue and selection filter for "INSERT".&lt;/P&gt;
&lt;P&gt;acdb.TypedValue[] values = { new acdb.TypedValue((int)acdb.DxfCode.Start, "INSERT") };&lt;BR /&gt; SelectionFilter sf = new SelectionFilter(values);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Create a prompt for select crossing window using your new points.&lt;BR /&gt; PromptSelectionResult psr = doc.Editor.SelectCrossingWindow(P3D1, P3D2, sf);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Check the status and see if there are any inserts within the window.&lt;/P&gt;
&lt;P&gt;if (psr.Status == PromptStatus.OK &amp;amp;&amp;amp; psr.Value.Count &amp;gt; 0)&lt;BR /&gt; {&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;acdb.ObjectIdCollection psrobjids = new acdb.ObjectIdCollection(psr.Value.GetObjectIds());&lt;BR /&gt; foreach (acdb.ObjectId oid in psrobjids)&lt;BR /&gt; {&lt;BR /&gt; acdb.BlockReference myblk = (acdb.BlockReference)tx.GetObject(oid, acdb.OpenMode.ForRead);&lt;BR /&gt; if (myblk.Name == "the block you are looking for")&lt;BR /&gt; {&lt;BR /&gt;&amp;nbsp; // do what you need to do&lt;BR /&gt;&amp;nbsp; // break;&lt;BR /&gt; }&lt;BR /&gt; }&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;lt;edit&amp;gt;&lt;/P&gt;
&lt;P&gt;I am not sure if this way is any better than your last post. &amp;nbsp;It looks like that works as well. &amp;nbsp;Your way will work even if the block is not visible in the editor. &amp;nbsp;I believe that object selection using window crossing implies that the object is visible in the editor window. If that's correct, your way is better.&lt;/P&gt;
&lt;P&gt;&amp;lt;/edit&amp;gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Aug 2016 18:44:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/c-get-block-at-point/m-p/6511540#M34904</guid>
      <dc:creator>fieldguy</dc:creator>
      <dc:date>2016-08-19T18:44:43Z</dc:date>
    </item>
    <item>
      <title>Re: C#, Get Block at Point</title>
      <link>https://forums.autodesk.com/t5/net-forum/c-get-block-at-point/m-p/6511562#M34905</link>
      <description>&lt;P&gt;thanks for the reply... the only problem is I can not have anything else getting selected since my palette and the information it receives is based on a single selected polyline. It would create more of a headache iterating through the selected objects since the polyline needs to stay selected.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Aug 2016 18:45:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/c-get-block-at-point/m-p/6511562#M34905</guid>
      <dc:creator>DirtyDanLand</dc:creator>
      <dc:date>2016-08-19T18:45:09Z</dc:date>
    </item>
    <item>
      <title>Re: C#, Get Block at Point</title>
      <link>https://forums.autodesk.com/t5/net-forum/c-get-block-at-point/m-p/6511572#M34906</link>
      <description>&lt;P&gt;The user selection and your program selection are not the same. &amp;nbsp;The user is not involved with (and does not see) the crossing window selection.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Aug 2016 18:50:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/c-get-block-at-point/m-p/6511572#M34906</guid>
      <dc:creator>fieldguy</dc:creator>
      <dc:date>2016-08-19T18:50:40Z</dc:date>
    </item>
    <item>
      <title>Re: C#, Get Block at Point</title>
      <link>https://forums.autodesk.com/t5/net-forum/c-get-block-at-point/m-p/6511583#M34907</link>
      <description>&lt;P&gt;I did not know that, thanks...&lt;/P&gt;</description>
      <pubDate>Fri, 19 Aug 2016 18:55:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/c-get-block-at-point/m-p/6511583#M34907</guid>
      <dc:creator>DirtyDanLand</dc:creator>
      <dc:date>2016-08-19T18:55:30Z</dc:date>
    </item>
    <item>
      <title>Re: C#, Get Block at Point</title>
      <link>https://forums.autodesk.com/t5/net-forum/c-get-block-at-point/m-p/6512363#M34908</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The GetBlockReferenceIds() route is fine, but your code can be optimized:&lt;/P&gt;
&lt;P&gt;- get directly the block table record in the block table using its name instead of scaning the whole block table ;&lt;/P&gt;
&lt;P&gt;- exit the foreach loop as soon as a matching position block is found.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;            using (Transaction tr = acCurDb.TransactionManager.StartTransaction())
            {
                BlockTable acBlkTble = tr.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable;

                // directly get the record in the table using its name
                BlockTableRecord btr = tr.GetObject(acBlkTble["WIRE-END"], OpenMode.ForRead) as BlockTableRecord;

                foreach (ObjectId objId_loopVariable in btr.GetBlockReferenceIds(true, true))
                {
                    BlockReference blk = (BlockReference)tr.GetObject(objId_loopVariable, OpenMode.ForRead);

                    if (blk.Position == pntPolyBeg)
                    {
                        //get the attributes
                        AttributeCollection attCol = blk.AttributeCollection;
                        foreach (ObjectId attId in attCol)
                        {
                            AttributeReference attRef = (AttributeReference)tr.GetObject(attId, OpenMode.ForRead);

                            switch (attRef.Tag.ToUpper())
                            {
                                case "END-ID":
                                    attBegValue[0] = attRef.TextString;
                                    break;
                                case "END-TERM":
                                    attBegValue[1] = attRef.TextString;
                                    break;
                            }
                        }
                        break; // exit the foreach loop as soon as the block is found
                    }
                    else if (blk.Position == pntPolyEnd)
                    {
                        //get the attributes
                        AttributeCollection attCol = blk.AttributeCollection;
                        foreach (ObjectId attId in attCol)
                        {
                            AttributeReference attRef = (AttributeReference)tr.GetObject(attId, OpenMode.ForRead);

                            switch (attRef.Tag.ToUpper())
                            {
                                case "END-ID":
                                    attEndValue[0] = attRef.TextString;
                                    break;
                                case "END-TERM":
                                    attEndValue[1] = attRef.TextString;
                                    break;
                            }
                        }
                        break;  // exit the foreach loop as soon as the block is found
                    }
                }
                tr.Commit();
            }&lt;/PRE&gt;</description>
      <pubDate>Sat, 20 Aug 2016 12:07:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/c-get-block-at-point/m-p/6512363#M34908</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2016-08-20T12:07:14Z</dc:date>
    </item>
    <item>
      <title>Re: C#, Get Block at Point</title>
      <link>https://forums.autodesk.com/t5/net-forum/c-get-block-at-point/m-p/6514308#M34909</link>
      <description>&lt;P&gt;thanks for the tip...&lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2016 12:13:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/c-get-block-at-point/m-p/6514308#M34909</guid>
      <dc:creator>DirtyDanLand</dc:creator>
      <dc:date>2016-08-22T12:13:45Z</dc:date>
    </item>
    <item>
      <title>Re: C#, Get Block at Point</title>
      <link>https://forums.autodesk.com/t5/net-forum/c-get-block-at-point/m-p/8189218#M34910</link>
      <description>&lt;P&gt;Just keep in mind that&lt;/P&gt;&lt;PRE&gt;btr.GetBlockReferenceIds(true, true)&lt;/PRE&gt;&lt;P&gt;will return a 0 on a dynamic block.&lt;/P&gt;&lt;P&gt;_gile himself talks about how to fetch dynamic blocks on a more recent post:&lt;/P&gt;&lt;P&gt;&lt;A href="https://forums.autodesk.com/t5/net/blockreferenceids-is-sometimes-empty/m-p/7044001#M53047" target="_blank"&gt;https://forums.autodesk.com/t5/net/blockreferenceids-is-sometimes-empty/m-p/7044001#M53047&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Aug 2018 15:22:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/c-get-block-at-point/m-p/8189218#M34910</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-08-09T15:22:59Z</dc:date>
    </item>
  </channel>
</rss>

