Find all the points inside a polyline

Find all the points inside a polyline

Anonymous
Not applicable
2,003 Views
8 Replies
Message 1 of 9

Find all the points inside a polyline

Anonymous
Not applicable

Hi, I am looking for a way to find all the points inside a polyline, enclosed and not enclosed. Thanks!

0 Likes
Accepted solutions (1)
2,004 Views
8 Replies
Replies (8)
Message 2 of 9

ActivistInvestor
Mentor
Mentor

Search this discussion group for the keyword "PointContainment"

0 Likes
Message 3 of 9

_gile
Consultant
Consultant
Accepted solution

Hi,

 

As @ActivistInvestor (is it you Tony?) said, you'll find some ways to evaluate if a point is inside a polyline from this thread.

 

Anyway, if the polyline does not have bulges (i.e., a polygon) you can also try a more trivial way using a polygonal selection.

 

        [CommandMethod("TEST")]
        public void Test()
        {
            var doc = Application.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;

            var options = new PromptEntityOptions("\nSelect a polyline: ");
            options.SetRejectMessage("\nSelected object is not a polyline.");
            options.AddAllowedClass(typeof(Polyline), true);
            var result = ed.GetEntity(options);
            if (result.Status != PromptStatus.OK)
                return;

            var polygon = new Point3dCollection();
            var ucs = ed.CurrentUserCoordinateSystem;
            Extents3d extents;
            using (var tr = db.TransactionManager.StartOpenCloseTransaction())
            {
                var pline = (Polyline)tr.GetObject(result.ObjectId, OpenMode.ForRead);
                extents = pline.GeometricExtents;
                for (int i = 0; i < pline.NumberOfVertices; i++)
                {
                    polygon.Add(pline.GetPoint3dAt(i).TransformBy(ucs));
                }
                tr.Commit();
            }

            var filter = new SelectionFilter(new[] { new TypedValue(0, "POINT") });
            dynamic acadApp = Application.AcadApplication;
            acadApp.ZoomWindow(extents.MinPoint.ToArray(), extents.MaxPoint.ToArray());
            var selection = ed.SelectCrossingPolygon(polygon, filter);
            acadApp.ZoomPrevious();
            if (selection.Status == PromptStatus.OK)
                ed.SetImpliedSelection(selection.Value);
        }


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 4 of 9

Anonymous
Not applicable

Thanks _gile!

 

The link you directed me to worked really well. Code worked very well if I am picking the point manually but in our case we have to find enclosed or intersecting entity inside a enclosed polyline.

 

Suppose EntA is enclosed structure, EntB is inside or on the border. EntB can be closed or not closed object.

 

Instead of me selecting a point manually if I can know all the points on EntB I can really use this code. Or if there is any other suggestion you have it is greatly appreciated.

0 Likes
Message 5 of 9

_gile
Consultant
Consultant

Did you read / try the code I provided upper?



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 6 of 9

BKSpurgeon
Collaborator
Collaborator

why not calculate the intersection points of the two entities and then incorporate that into Gilles' code?

Message 7 of 9

Anonymous
Not applicable

Yes I did. My selection is empty. Here's the screen shot.Selection.PNG

0 Likes
Message 8 of 9

_gile
Consultant
Consultant

The code I puposed make a filtered selection of the points (DBPoint entities) inside the polyline becaus it was my understanding of your first message.

If you want to select anothe type of entities, modify the selection filter to suit your needs.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 9 of 9

Anonymous
Not applicable

Thank you _gile this discussion was very helpful!

0 Likes