Get object(s) at point.

Get object(s) at point.

Anonymous
Not applicable
940 Views
8 Replies
Message 1 of 9

Get object(s) at point.

Anonymous
Not applicable

Hello!

I'm learning AutoCAD's api and it's going pretty good 🙂

But I have problem. 

 

I would like to let user select some objects in model. 

In model space we have few blocks (filled circles with center point). I'm iterating through the objects, and storing center points into some array (just example).

 

To this moment everything is pretty easy. 

 

Now I would like to check if at each point I have specify object (like line, polyline, etc), so in other way - if my object is intersecting with line/polyline.

 

Method IntersectWith determine points between two objects, but I know (and if yes to get) if there is line/polyline at this point.

 

Is there any smart way to do this? Instead of iterating each block through each line/polyline?

0 Likes
941 Views
8 Replies
Replies (8)
Message 2 of 9

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

>> Is there any smart way to do this? Instead of iterating each block through each line/polyline?

By default and globally answered ==> NO.

 

What you can do is if all layers thawed and on you may create a selection before using th extents of your BlockReference, but be carefull that the area around the BlockReference is visible on screen otherwise the creation of a selection using Windows- or CrossingWindow-mode may fail to see the entities.

 

If you are not sure that you have all items visible on screen you could first scan through all elements, store them with their extents in an array and before doing any IntersectWith-tests (which are slow) you can first verify if the objects-extents are around the BlockReference-extents.

 

- alfred -

 

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 3 of 9

Anonymous
Not applicable

Hey Alfred,

 

Thanks for the reply. 

 

Could you explain me this:

 

What you can do is if all layers thawed and on you may create a selection before using th extents of your BlockReference, but be carefull that the area around the BlockReference is visible on screen otherwise the creation of a selection using Windows- or CrossingWindow-mode may fail to see the entities.

 

You mean Extents3d property at BlockReference? Could you tell me what this property is doing? I was looking for some examples/docs, but didn't find anything. This could help me with decrease the range of iterating objects?

0 Likes
Message 4 of 9

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

>> Could you explain me this:

You can create a selectionset that selects all entities within a crossing-window, the coords for the window can be grapped from the extents of your BlockReferenc.

...Extents for an entity is a virtual rectangle (or 3d ==> quader) around your object, parallel to wcs, that defines minimum and maximum x- and y-values of your entity.

When you now know the extents of your BlockReference you can make a selection to get other entities within or crossing the extents-area of your BlockReference. Now you can check for intersection-points with just a few elements and not all from the modelspace.

TO BE CAREFUL with this method: the building of a selectionset based on window-coordinates only works if your given coordinates are visible on screen (or at least visible for the display-list), otherwise you may get no entities selected even if there are any within this area. So check your visible area first.

 

Hope this answered your questions, - alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 5 of 9

Anonymous
Not applicable

Thanks mate,

 

How about dimensions and custom blocks? I tried this code:

 

       public static void BoundBoxExplode()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;
            PromptEntityResult per = ed.GetEntity("Select a Entity\n");
            if (per.Status == PromptStatus.OK)
            {
                using (Transaction trx = db.TransactionManager.StartTransaction())
                {
                    BlockTableRecord msBtr = SymbolUtilityServices.GetBlockModelSpaceId(db).GetObject(OpenMode.ForWrite) as BlockTableRecord;
                    Entity ent = trx.GetObject(per.ObjectId, OpenMode.ForRead) as Entity;

                    DBObjectCollection dbObjColl = new DBObjectCollection();
                    ent.Explode(dbObjColl);
                    foreach (Entity entExplode in dbObjColl)
                    {
                        Autodesk.AutoCAD.Geometry.Point3d min = entExplode.GeometricExtents.MinPoint;
                        Autodesk.AutoCAD.Geometry.Point3d max = entExplode.GeometricExtents.MaxPoint;

                        Polyline pl = new Polyline();
                        pl.SetDatabaseDefaults();
                        Autodesk.AutoCAD.Geometry.Point2d p1 = new Autodesk.AutoCAD.Geometry.Point2d(min.X, min.Y);
                        Autodesk.AutoCAD.Geometry.Point2d p2 = new Autodesk.AutoCAD.Geometry.Point2d(min.X, max.Y);
                        Autodesk.AutoCAD.Geometry.Point2d p3 = new Autodesk.AutoCAD.Geometry.Point2d(max.X, max.Y);
                        Autodesk.AutoCAD.Geometry.Point2d p4 = new Autodesk.AutoCAD.Geometry.Point2d(max.X, min.Y);
                        pl.AddVertexAt(0, p1, 0, 0, 0);
                        pl.AddVertexAt(1, p2, 0, 0, 0);
                        pl.AddVertexAt(2, p3, 0, 0, 0);
                        pl.AddVertexAt(3, p4, 0, 0, 0);
                        pl.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByAci, 2);
                        pl.Closed = true;
                        msBtr.AppendEntity(pl);
                        trx.AddNewlyCreatedDBObject(pl, true);

                    }
                    trx.Commit();
                }
            }
        }

 

For dimensions I'm getting lots of points. For my custom block I'm getting eNullExtents error 😞

0 Likes
Message 6 of 9

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

can you add the drawing also?

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 7 of 9

Anonymous
Not applicable

The problem occurs for clean acadiso template with simple rotated dimension.

 

Please tell me one thing - am I able to get intersect points between line/polyline and custom object (with specified only inserction point)? 

 

0 Likes
Message 8 of 9

Anonymous
Not applicable

What I mean - I have line/polyline. And block where I have text, lines, circles, etc.

 

I want to get intersect point between line/polyline and block's inserction point.

0 Likes
Message 9 of 9

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

>> Please tell me one thing - am I able to get intersect points between line/polyline

>> and custom object (with specified only inserction point)?

...and next message:

>> I want to get intersect point between line/polyline and block's inserction point.

I think the used vocables are problematic! At least: curves can intersect, but points can not. Also it is not possible to get intersections calculated between a curve and a points.

Are you trying to verify if a point is "on a curve", is that what you are looking for?

 

Next problematic phrase is "custom object". A custom object (speaking between developers) is an object that you define by code. Is an AutoCAD -blockdefinition a custom object for you?

 

And looking to your code: I see you try to explode a selected object (be carefull because AttributeReferences with text-values are destroyed back to Attributes(-definitions) and ... value is lost then), then you scan through all entities in the collection of the resulting entities and draw a rectangle around then. But I don't see anything with intersection-points, so I don't see what your goal is with your code.

 

>> For my custom block I'm getting eNullExtents error

That is why I tried to get your drawing, because I don't know how your "custom block" is structured. If there is no curve-geom but only text or attributes or points then calculation of extents may be critical.

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes