<?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: Get text (MText) entity (inside) a polyline or block in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/get-text-mtext-entity-inside-a-polyline-or-block/m-p/5426512#M42077</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To check if a point is inside a polyline, two ways are described &lt;A href="https://forums.autodesk.com/t5/net/spatial-query-in-autocad-2010/m-p/5304221/highlight/true#M42039" target="_blank"&gt;here,&lt;/A&gt; one using a MPolygon, the other using the BoundaryRepresentation (Brep) API.&lt;/P&gt;</description>
    <pubDate>Thu, 27 Nov 2014 12:48:17 GMT</pubDate>
    <dc:creator>_gile</dc:creator>
    <dc:date>2014-11-27T12:48:17Z</dc:date>
    <item>
      <title>Get text (MText) entity (inside) a polyline or block</title>
      <link>https://forums.autodesk.com/t5/net-forum/get-text-mtext-entity-inside-a-polyline-or-block/m-p/5424932#M42075</link>
      <description>&lt;P&gt;Hi All&lt;BR /&gt;&lt;BR /&gt;I need to get (read) a text entity that resides (inside) a polyline or inside a block.&lt;BR /&gt;&lt;BR /&gt;Thanks in advance for your help.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Nov 2014 08:46:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/get-text-mtext-entity-inside-a-polyline-or-block/m-p/5424932#M42075</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-11-26T08:46:49Z</dc:date>
    </item>
    <item>
      <title>Re: Get text (MText) entity (inside) a polyline or block</title>
      <link>https://forums.autodesk.com/t5/net-forum/get-text-mtext-entity-inside-a-polyline-or-block/m-p/5425116#M42076</link>
      <description>&lt;PRE&gt;        //Note: both arguments may be virtual, i.e. not added to te database, therefore db as separate argument
        public static bool IsPartialInside(Database db, Polyline poly, ObjectId entId)
        {
            bool isPartialInside=false;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                Entity ent=(Entity)tr.GetObject(entId, OpenMode.ForRead);
                isPartialInside = IsPartialInside(poly, ent);

                tr.Commit();
            }

            return isPartialInside;
        }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;        //Note: both arguments may be virtual, i.e. not added to te database
        public static bool IsPartialInside(Polyline poly, Entity ent)
        {
            try
            {
                //Quick scan based on Bounding Box
                if (ent.GeometricExtents.MinPoint.X &amp;gt; poly.GeometricExtents.MaxPoint.X)
                    return false;
                if (ent.GeometricExtents.MinPoint.Y &amp;gt; poly.GeometricExtents.MaxPoint.Y)
                    return false;
                if (ent.GeometricExtents.MinPoint.Z &amp;gt; poly.GeometricExtents.MaxPoint.Z)
                    return false;

                if (ent.GeometricExtents.MaxPoint.X &amp;lt; poly.GeometricExtents.MinPoint.X)
                    return false;
                if (ent.GeometricExtents.MaxPoint.Y &amp;lt; poly.GeometricExtents.MinPoint.Y)
                    return false;
                if (ent.GeometricExtents.MaxPoint.Z &amp;lt; poly.GeometricExtents.MinPoint.Z)
                    return false;

                Point3dCollection plPoints = AcadPolyTools.PolyToPoints(poly);
                Point3dCollection entPoints = GetBoundingPoints(ent);
                //add center of entity
                entPoints.Add(new Point3d(
                                            0.5 * (ent.GeometricExtents.MinPoint.X + ent.GeometricExtents.MaxPoint.X),
                                            0.5 * (ent.GeometricExtents.MinPoint.Y + ent.GeometricExtents.MaxPoint.Y),
                                            0.5 * (ent.GeometricExtents.MinPoint.Z + ent.GeometricExtents.MaxPoint.Z)));

                foreach (Point3d point in entPoints)
                    if (IsInside(plPoints, point))
                        return true;
            }
            catch
            {
                //if (ent is DBText)
                //{
                //    DBText tmpText = (DBText)ent;
                //    Document doc = Application.DocumentManager.MdiActiveDocument;
                //    Database db = doc.Database;
                //    Editor ed = doc.Editor;

                //    ed.WriteMessage("\n ***ToDo: SkipEmptyObjects: TextString='', Polyline.length=0, LineLength=0");
                //}
            }

            return false;
        }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;        public static bool IsInside(Point3dCollection polyPoint, Point3d pnt)
        {
            int i, j = polyPoint.Count - 1;
            bool oddNodes = false;

            for (i = 0; i &amp;lt; polyPoint.Count; i++)
            {
                Point3d pi = polyPoint[i];
                Point3d pj = polyPoint[j];

                //quicker for large number of points to test, but need Init procedure for Multiple[] and Constant[]
                //if ((pi.Y &amp;lt; pnt.Y &amp;amp;&amp;amp; pj.Y &amp;gt;= pnt.Y || pj.Y &amp;lt; pnt.Y &amp;amp;&amp;amp; pi.Y &amp;gt;= pnt.Y))
                //    oddNodes ^= (pnt.Y * Multiple[i] + Constant[i] &amp;lt; pnt.X);


                if ((pi.Y &amp;lt; pnt.Y &amp;amp;&amp;amp; pj.Y &amp;gt;= pnt.Y || pj.Y &amp;lt; pnt.Y &amp;amp;&amp;amp; pi.Y &amp;gt;= pnt.Y) &amp;amp;&amp;amp;
                    (pi.X &amp;lt;= pnt.X || pj.X &amp;lt;= pnt.X))
                    oddNodes ^= (pi.X + (pnt.Y - pi.Y) / (pj.Y - pi.Y) * (pj.X - pi.X) &amp;lt; pnt.X);

                j = i;
            }
            return oddNodes;
        }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;        public static Point3dCollection PolyToPoints(Polyline pl)
        {
            Point3dCollection plPoints = new Point3dCollection();

            for (int i = 0; i &amp;lt; pl.NumberOfVertices; i++)
                plPoints.Add(pl.GetPoint3dAt(i));
            return plPoints;
        }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Nov 2014 12:26:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/get-text-mtext-entity-inside-a-polyline-or-block/m-p/5425116#M42076</guid>
      <dc:creator>SENL1362</dc:creator>
      <dc:date>2014-11-26T12:26:51Z</dc:date>
    </item>
    <item>
      <title>Re: Get text (MText) entity (inside) a polyline or block</title>
      <link>https://forums.autodesk.com/t5/net-forum/get-text-mtext-entity-inside-a-polyline-or-block/m-p/5426512#M42077</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To check if a point is inside a polyline, two ways are described &lt;A href="https://forums.autodesk.com/t5/net/spatial-query-in-autocad-2010/m-p/5304221/highlight/true#M42039" target="_blank"&gt;here,&lt;/A&gt; one using a MPolygon, the other using the BoundaryRepresentation (Brep) API.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Nov 2014 12:48:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/get-text-mtext-entity-inside-a-polyline-or-block/m-p/5426512#M42077</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2014-11-27T12:48:17Z</dc:date>
    </item>
    <item>
      <title>Re: Get text (MText) entity (inside) a polyline or block</title>
      <link>https://forums.autodesk.com/t5/net-forum/get-text-mtext-entity-inside-a-polyline-or-block/m-p/5426520#M42078</link>
      <description>&lt;P&gt;Hi Gile,&lt;BR /&gt;I'm normally a big fan of TT code but the BREP solution appeared to be too slow for my particular problem.&lt;BR /&gt;I wasn't aware of the MPolygon functionality and thus converted old C code into a C# solution.&lt;BR /&gt;I might have a look at the MPolygon object later on, the code seems to be short and easy which is always good.&lt;BR /&gt;Thanks to point me into that direction.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Nov 2014 13:13:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/get-text-mtext-entity-inside-a-polyline-or-block/m-p/5426520#M42078</guid>
      <dc:creator>SENL1362</dc:creator>
      <dc:date>2014-11-27T13:13:44Z</dc:date>
    </item>
    <item>
      <title>Re: Get text (MText) entity (inside) a polyline or block</title>
      <link>https://forums.autodesk.com/t5/net-forum/get-text-mtext-entity-inside-a-polyline-or-block/m-p/5462194#M42081</link>
      <description>Hi Giles&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Thank you for your time.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;i wrote polyline instead of polygon mistakenly in the title, sorry for that.&lt;BR /&gt;I tried the two ways, they work fine with normal polyline. i tried to use the code with polygone but it reads the polygon as a polyline&amp;gt;&lt;BR /&gt;Also tried to convert the polygon to a polyline but i failed.&lt;BR /&gt;My problem exactly that i need to search for BlockReferences or polygons on PS or MS, then find any Text (Inside) the block or (Inside) the polygon.&lt;BR /&gt;The BlockReferences option is my favourite, but it is not necessary.&lt;BR /&gt;</description>
      <pubDate>Thu, 08 Jan 2015 06:16:16 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/get-text-mtext-entity-inside-a-polyline-or-block/m-p/5462194#M42081</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-01-08T06:16:16Z</dc:date>
    </item>
  </channel>
</rss>

