How to automatically create closed polylines from intersections using .NET C#

How to automatically create closed polylines from intersections using .NET C#

artillis_prado
Enthusiast Enthusiast
430 Views
3 Replies
Message 1 of 4

How to automatically create closed polylines from intersections using .NET C#

artillis_prado
Enthusiast
Enthusiast

I have a drawing with a Polyline boundary and several lines inside that boundary. In AutoCAD, using the BOUNDARY command and clicking in the middle of each enclosed region, it automatically creates a closed Polyline (square, triangle, or any other shape).

I would like to know if it is possible, through the AutoCAD .NET C# API, to automate this process, so that all the internal regions formed by the intersections of the lines inside the boundary are automatically converted into closed shapes, without needing to click manually on each one.

 

 

var hatch = HatchPolyLine(poly2d.Id);
hatch.AddToDocument(btr, act);

DBObjectCollection explodedObjects = new DBObjectCollection();
hatch.Explode(explodedObjects);

 

 

artillis_prado_1-1738162442433.png

Apply Boundary

artillis_prado_0-1738162388448.png

 

0 Likes
Accepted solutions (1)
431 Views
3 Replies
Replies (3)
Message 2 of 4

jreidKVSUZ
Advocate
Advocate

I did a search for LISP file that does Boundaries.

I have created a LISP file called BM.lsp

It works great. Takes some time, but let it run and it will give you what you want.

Original creator link: https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/create-boundary-automatically/td-p/1...

Hope this helps! If so please select Solution Solved button.

JRR!

0 Likes
Message 3 of 4

artillis_prado
Enthusiast
Enthusiast

Very nice! The Lisp solution is interesting, but I'm looking for a .NET C# approach.

0 Likes
Message 4 of 4

JamesMaeding
Advisor
Advisor
Accepted solution

@artillis_prado 

That type of tool has been created many times by various developers, and is a classic GIS problem.

The trick is to handle lines and arcs, and fast as brute force intersection detection is too slow.

I did one for our company, and the approach is likely the same for most that want to handle large scale data sets.

You basically take all the segments and find all intersections with other segments.

That is not trivial, and you optimize checking by first looking for bounding box overlap.

Once you have the ints, you chop up the segments into pieces between them.

Then gather any "chains" which are pieces end to end between intersections.

Then create "hubs" which are points that know what chains end at their location.

Then loop through the segs and hubs, finding the closed shapes by "next" clockwise chain on the hub you end at, until you get back to the starting hub.

Mark the segs as done that direction, and do the next chain on the hub.

I think it must be done that way, as the classic "sweep-line" approaches for intersections computational geometry people use only work on lines.

I'm always looking for "no, use this super fast GIS library instead" answers.

Many are C++ though and I can read the code but can't maintain projects in C++ yet.

Funny thing is I do all the time for arduino, somehow that is easy but in acad its hard? Oh well.


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

0 Likes