Code Red => AutoLISP (Vanilla / Visual) => Topic started by: civil.eng on September 03, 2022, 04:28:11 AM
Title: Find the polyline around a text
Post by: civil.eng on September 03, 2022, 04:28:11 AM
Hello everyone, Long before, someone had given me a function to select a text inside of a polygon, now I need the opposite of it that way I can find the polygon (Entity name of it) for a selected text. I know a way that it's can be done by "Cadr (Entsel text)" and then creating a boundary for the point , but I need the get the entity name of the main boundary around the text.
Thanks in advance.
Title: Re: Find the polyline around a text
Post by: Lee Mac on September 03, 2022, 09:36:40 AM
Upon obtaining the insertion point of the text object, you can use either a ray casting algorithm or winding algorithm to determine within which of the candidate polylines it resides - you may wish to refer to this thread (http://www.theswamp.org/index.php?topic=47969.0).
Title: Re: Find the polyline around a text
Post by: Stefan on September 03, 2022, 10:05:33 AM
A common method is ray tracing, counting the number of intersection with the polyline segments. Even number of intersections means that the tested point is outside, It fails in some particular situations because the considered ray may lie exactly on a vertex of the polyline. My idea is to apply this method 4 times, aiming some random points near the polyline's boundingbox corners. If at least 3 of these 4 points returns Odd number of intersections, consider the point inside. I'm using this method quite often and it never fails.
Title: Re: Find the polyline around a text
Post by: BIGAL on September 03, 2022, 08:21:16 PM
If you draw a random line say vertically from text can use (ssget "F" and get objects that line touches then use intersectwith to get a object and distance from text point, so a simple sort based on dist is the closest object and the one you want. Use extmax to get say maximum Y value for drawing the line.
((dist1 ent1)(dist2 ent2)..........)
Title: Re: Find the polyline around a text
Post by: mhupp on September 04, 2022, 12:42:49 AM
You could make a selection of the polylines. then use their cords with (ssget "_WP") if text selected is in selection = inside polyline. "_WP" would be fully inside "_CP" would just need to be crossing or fully inside.