<?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 Spatial Query in Autocad 2010 in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/spatial-query-in-autocad-2010/m-p/5304221#M42598</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to know if a point is into a polygon, developing in VB.NET fro Autocad 2010.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is this possible? Or is any method to do something similar?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
    <pubDate>Mon, 29 Sep 2014 08:36:04 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2014-09-29T08:36:04Z</dc:date>
    <item>
      <title>Spatial Query in Autocad 2010</title>
      <link>https://forums.autodesk.com/t5/net-forum/spatial-query-in-autocad-2010/m-p/5304221#M42598</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to know if a point is into a polygon, developing in VB.NET fro Autocad 2010.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is this possible? Or is any method to do something similar?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 29 Sep 2014 08:36:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/spatial-query-in-autocad-2010/m-p/5304221#M42598</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-09-29T08:36:04Z</dc:date>
    </item>
    <item>
      <title>Re : Spatial Query in Autocad 2010</title>
      <link>https://forums.autodesk.com/t5/net-forum/spatial-query-in-autocad-2010/m-p/5304535#M42599</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use a MPolygon, a MAP entity which is also available in vanilla while the AcMPolygonObj##.dbx module is loaded.&lt;/P&gt;
&lt;P&gt;In your project, you'll also have to add a reference to the AcMPolygonMGD.dll (you'll find it in the AutoCAD installation folder.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a little sample with a testing command, it implements IExtensionApplication interface to load the module at startup.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;

namespace PointInside
{
    public class CommandMethods : IExtensionApplication
    {
        public void Initialize()
        {
            SystemObjects.DynamicLinker.LoadModule(
                "AcMPolygonObj" + Application.Version.Major + ".dbx", false, false);
        }

        public void Terminate() { }

        private bool IsPointInside(Point3d point, Polyline pline)
        {
            double tolerance = Tolerance.Global.EqualPoint;
            using (MPolygon mpg = new MPolygon())
            {
                mpg.AppendLoopFromBoundary(pline, true, tolerance);
                return mpg.IsPointInsideMPolygon(point, tolerance).Count == 1;
            }
        }

        [CommandMethod("Test")]
        public void Test()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;

            PromptEntityOptions peo = new PromptEntityOptions("\nSelect a polyline: ");
            peo.SetRejectMessage("Only a polyline !");
            peo.AddAllowedClass(typeof(Polyline), true);
            PromptEntityResult per = ed.GetEntity(peo);
            if (per.Status != PromptStatus.OK) 
                return;

            using (Transaction tr = db.TransactionManager.StartOpenCloseTransaction())
            {
                Polyline pline = (Polyline)tr.GetObject(per.ObjectId, OpenMode.ForRead);
                PromptPointOptions ppo = new PromptPointOptions("\nPick a point &amp;lt;quit&amp;gt;: ");
                ppo.AllowNone = true;
                while (true)
                {
                    PromptPointResult ppr = ed.GetPoint(ppo);
                    if (ppr.Status != PromptStatus.OK) 
                        break;
                    Application.ShowAlertDialog(
                        IsPointInside(ppr.Value, pline) ? "Inside" : "Outside");
                }
            }
        }
    }
}
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Sep 2014 12:14:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/spatial-query-in-autocad-2010/m-p/5304535#M42599</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2014-09-29T12:14:22Z</dc:date>
    </item>
    <item>
      <title>Re : Spatial Query in Autocad 2010</title>
      <link>https://forums.autodesk.com/t5/net-forum/spatial-query-in-autocad-2010/m-p/5304875#M42600</link>
      <description>&lt;P&gt;Thanks Gilles!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am testing your code, and it crashes in method "IsPointInside" when trying to create the MPolygon object. Exception throws this message:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;"Se produjo una excepción de tipo 'System.IO.FileLoadException' en AcMPolygonMGD.dll pero no se controló en el código del usuario&lt;/P&gt;&lt;P&gt;Información adicional: acmpolygonobj18d.dbx"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What is the problem?&lt;/P&gt;</description>
      <pubDate>Mon, 29 Sep 2014 14:30:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/spatial-query-in-autocad-2010/m-p/5304875#M42600</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-09-29T14:30:05Z</dc:date>
    </item>
    <item>
      <title>Re : Spatial Query in Autocad 2010</title>
      <link>https://forums.autodesk.com/t5/net-forum/spatial-query-in-autocad-2010/m-p/5305009#M42601</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are many ways to test if a point it's inside a polygon, the more direct from the API is editor.TraceBoundary(TestPoint) it returns a dbObjectCollection, if empty the point it's outside, otherwise you have your point.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also this link may help : &lt;A target="_blank" href="http://www.theswamp.org/index.php?topic=43572.msg488632#msg488632"&gt;Containment&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Gaston Nunez&lt;/P&gt;</description>
      <pubDate>Mon, 29 Sep 2014 15:18:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/spatial-query-in-autocad-2010/m-p/5305009#M42601</guid>
      <dc:creator>hgasty1001</dc:creator>
      <dc:date>2014-09-29T15:18:36Z</dc:date>
    </item>
    <item>
      <title>Re : Spatial Query in Autocad 2010</title>
      <link>https://forums.autodesk.com/t5/net-forum/spatial-query-in-autocad-2010/m-p/5305441#M42602</link>
      <description>&lt;P&gt;Oh yes, I remember now.&lt;/P&gt;
&lt;P&gt;There's a bug in the AutoCad 2010 version of AcMPolygonMGD.dll which tries to load AcMPolygonObj18&lt;SPAN style="color: #ff0000;"&gt;&lt;STRONG&gt;d&lt;/STRONG&gt;&lt;/SPAN&gt;.dll instead of AcMPolygonObj18.dll (AFAIK this bug haven't been fixed for this version).&lt;/P&gt;
&lt;P&gt;As Gaston said, you can use the Editor.TraceBoundary() method or use the boundary representation API (Brep) as shown by Tony Tanzillo in the link Gaston provided.&lt;/P&gt;</description>
      <pubDate>Mon, 29 Sep 2014 18:31:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/spatial-query-in-autocad-2010/m-p/5305441#M42602</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2014-09-29T18:31:38Z</dc:date>
    </item>
    <item>
      <title>Re : Spatial Query in Autocad 2010</title>
      <link>https://forums.autodesk.com/t5/net-forum/spatial-query-in-autocad-2010/m-p/5306907#M42603</link>
      <description>&lt;P&gt;Ok, I will try the solution exposed by Gaston&lt;/P&gt;</description>
      <pubDate>Tue, 30 Sep 2014 11:30:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/spatial-query-in-autocad-2010/m-p/5306907#M42603</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-09-30T11:30:06Z</dc:date>
    </item>
    <item>
      <title>Re : Spatial Query in Autocad 2010</title>
      <link>https://forums.autodesk.com/t5/net-forum/spatial-query-in-autocad-2010/m-p/5307259#M42604</link>
      <description>&lt;P&gt;Gilles,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The method "&lt;SPAN&gt;editor.TraceBoundary(TestPoint)" doesn´t exist in AutoCad 2010...&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Sep 2014 13:31:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/spatial-query-in-autocad-2010/m-p/5307259#M42604</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-09-30T13:31:19Z</dc:date>
    </item>
    <item>
      <title>Re : Spatial Query in Autocad 2010</title>
      <link>https://forums.autodesk.com/t5/net-forum/spatial-query-in-autocad-2010/m-p/5307623#M42605</link>
      <description>&lt;P&gt;So, you can try the Brep route as shown by Tony Tanzillo &lt;A href="http://www.theswamp.org/index.php?topic=43572.msg488632#msg488632" target="_blank"&gt;here&lt;/A&gt; (you have to add reference to acdbmgdbrep.dll and Import Autodesk.AutoCAD.BoundaryRepresentation namespace).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a little example largely inspired by Tony's one which works with polylines on AutoCAD 2010.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;        [CommandMethod("TEST")]
        public void Test()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;

            PromptEntityOptions peo = new PromptEntityOptions("\nSelect a polyline: ");
            peo.SetRejectMessage("Only a polyline !");
            peo.AddAllowedClass(typeof(Polyline), true);
            PromptEntityResult per = ed.GetEntity(peo);
            if (per.Status != PromptStatus.OK)
                return;

            using (Transaction tr = db.TransactionManager.StartOpenCloseTransaction())
            {
                Polyline pline = (Polyline)tr.GetObject(per.ObjectId, OpenMode.ForRead);
                if (!pline.Closed)
                {
                    ed.WriteMessage("\nPolyline must be closed.");
                    return;
                }
                DBObjectCollection curves = new DBObjectCollection();
                curves.Add(pline);
                try
                {
                    using (DBObjectCollection regions = Region.CreateFromCurves(curves))
                    using (Region region = (Region)regions[0])
                    {
                        PromptPointOptions ppo = new PromptPointOptions("\nPick a point &amp;lt;quit&amp;gt;: ");
                        ppo.AllowNone = true;
                        while (true)
                        {
                            PromptPointResult ppr = ed.GetPoint(ppo);
                            if (ppr.Status != PromptStatus.OK)
                                break;
                            Application.ShowAlertDialog(
                                GetPointContainment(region, ppr.Value).ToString());
                        }
                    }
                }
                catch (System.Exception exn)
                {
                    ed.WriteMessage("\nError: " + exn.Message);
                }
            }
        }

        private PointContainment GetPointContainment(Region region, Point3d point)
        {
            PointContainment result = PointContainment.Outside;
            using (Brep brep = new Brep(region))
            {
                if (brep != null)
                {
                    using (BrepEntity ent = brep.GetPointContainment(point, out result))
                    {
                        if (ent is Autodesk.AutoCAD.BoundaryRepresentation.Face)
                        {
                            result = PointContainment.Inside;
                        }
                    }
                }
            }
            return result;
        }&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Sep 2014 15:13:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/spatial-query-in-autocad-2010/m-p/5307623#M42605</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2014-09-30T15:13:28Z</dc:date>
    </item>
    <item>
      <title>Re : Spatial Query in Autocad 2010</title>
      <link>https://forums.autodesk.com/t5/net-forum/spatial-query-in-autocad-2010/m-p/5307961#M42606</link>
      <description>&lt;P&gt;Thanks Gilles!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It works! Now, I have to make some changes to work as I want. First of all, do you know how can I select a polyline from my dwg without user interaction?&lt;/P&gt;</description>
      <pubDate>Tue, 30 Sep 2014 16:30:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/spatial-query-in-autocad-2010/m-p/5307961#M42606</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-09-30T16:30:57Z</dc:date>
    </item>
    <item>
      <title>Re : Spatial Query in Autocad 2010</title>
      <link>https://forums.autodesk.com/t5/net-forum/spatial-query-in-autocad-2010/m-p/5309565#M42607</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use Editor.SelectAll() method with an appropriate selection filter or iterate through the entities contained in the model space (and/or paper spaces) to look for polylines.&lt;/P&gt;
&lt;P&gt;If you want to select a particular polyline, you'd have to check for some particularity (geometry, xdata, ...) of this polyline.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Oct 2014 09:23:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/spatial-query-in-autocad-2010/m-p/5309565#M42607</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2014-10-01T09:23:20Z</dc:date>
    </item>
    <item>
      <title>Re: Spatial Query in Autocad 2010</title>
      <link>https://forums.autodesk.com/t5/net-forum/spatial-query-in-autocad-2010/m-p/5459771#M42609</link>
      <description>&lt;P&gt;Hi Giles&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Thank you for your time.&lt;/P&gt;&lt;P&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 &lt;STRONG&gt;&lt;SPAN style="text-decoration: underline;"&gt;BlockReferences&lt;/SPAN&gt; &lt;/STRONG&gt;or &lt;STRONG&gt;&lt;SPAN style="text-decoration: underline;"&gt;polygons&lt;/SPAN&gt; &lt;/STRONG&gt;on PS or MS, then find any Text (Inside) the block or (Inside) the polygon.&lt;BR /&gt;The &lt;STRONG&gt;&lt;SPAN style="text-decoration: underline;"&gt;BlockReferences&lt;/SPAN&gt; &lt;/STRONG&gt;option is my favourite, but it is not necessary.&lt;BR /&gt;&lt;BR /&gt;Any help please.&lt;BR /&gt;&lt;BR /&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jan 2015 11:19:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/spatial-query-in-autocad-2010/m-p/5459771#M42609</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-01-06T11:19:01Z</dc:date>
    </item>
  </channel>
</rss>

