.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Get the type of entity that intersected with a polyline

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
OCODER
473 Views, 7 Replies

Get the type of entity that intersected with a polyline

Hi All,


I need to get the type of entities which intersect with a specific polyline.
Exactly i need to know if the type is (Block Reference) or no.


Please help me


Thanks in advance.

7 REPLIES 7
Message 2 of 8
SENL1362
in reply to: OCODER

This sample may help:

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

            try
            {
                PromptEntityOptions peo = new PromptEntityOptions("Select Polyline");
                peo.AllowNone = true;
                PromptEntityResult per = null;
                do
                {
                    per = ed.GetEntity(peo);
                    if (per.Status == PromptStatus.Cancel)
                        return;
                } while (per.Status != PromptStatus.OK && per.ObjectId.ObjectClass.DxfName != "LWPOLYLINE");
                ObjectId polyId = per.ObjectId;

                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    Polyline poly = (Polyline)tr.GetObject(polyId, OpenMode.ForRead);
                    //polySpace could be any Block: ms, ps or blocks
                    BlockTableRecord polySpace = (BlockTableRecord)tr.GetObject(poly.BlockId, OpenMode.ForRead);
                    foreach (ObjectId entId in polySpace)
                    {
                        //remove next 2 lines to test intersection with all kind of entities
                        if (entId.ObjectClass.DxfName != "INSERT")
                            continue;
                        Entity ent = (Entity)tr.GetObject(entId, OpenMode.ForRead);

                        //quick test based on extents
                        if (ent.GeometricExtents.MinPoint.X > ent.GeometricExtents.MaxPoint.X)
                            continue;   //Ent left from Poly
                        if (ent.GeometricExtents.MinPoint.Y > ent.GeometricExtents.MaxPoint.Y)
                            continue;   //Ent above from Poly
                        if (ent.GeometricExtents.MaxPoint.X < ent.GeometricExtents.MinPoint.X)
                            continue;   //Ent right from Poly
                        if (ent.GeometricExtents.MaxPoint.Y < ent.GeometricExtents.MinPoint.Y)
                            continue;   //Ent below from Poly

                        Point3dCollection intersections = new Point3dCollection();
                        poly.IntersectWith(ent, Intersect.OnBothOperands, intersections, IntPtr.Zero, IntPtr.Zero);
                        if (intersections != null && intersections.Count > 0)
                        {
                            switch (entId.ObjectClass.DxfName)
                            {
                                case "INSERT":
                                    BlockReference blkRef = (BlockReference)ent;
                                    ed.WriteMessage("\n Insert: {0} intersect with Poly", blkRef.Name);
                                    break;
                                default:
                                    ed.WriteMessage("\n {0}: {1} intersect with Poly", entId.ObjectClass.DxfName, ent.Handle);
                                    break;
                            }
                        }
                    }
                    tr.Commit();
                }
            }
            catch (System.Exception ex)
            {
                ed.WriteMessage(ex.Message);
            }
        }

 

 

 

Message 3 of 8
hgasty1001
in reply to: OCODER

Hi,

 

Another idea, use the polyline coordinates in a fence selection.

 

Gaston Nunez

Message 4 of 8
SENL1362
in reply to: hgasty1001

Correct for Ms and Ps, but not for any BlockTableRecord.
Message 5 of 8
OCODER
in reply to: SENL1362

Thank you SENL1362

I will try and tell you about result
but i did not understand what do you mean by (Ms) and (Ps).

Thank you again
Message 6 of 8
OCODER
in reply to: SENL1362

Thank you gasty1001
I will try and tell you about result.
Message 7 of 8
SENL1362
in reply to: OCODER

Sorry about that:
Ms is short for ModelSpace
Ps is short for PaperSpace(also known as Active Paper Layout)
Message 8 of 8
OCODER
in reply to: SENL1362

Thank you for your time

My problem solved with your code.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost