TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: civil.eng on December 29, 2020, 04:15:34 PM

Title: Select nearest boundary to a text
Post by: civil.eng on December 29, 2020, 04:15:34 PM
Hello everyone,
I' trying to write a function to find a nearest closed polyline to a text with this algorithm :

1 - Select a text
2 - Find and select a boundary nearest to the text automatically

In the attached image I have shown the boundary that I need to select automatically after "Entsel" the text. (all Closed Polyline have a text)

Could someone give me a guidance?

Thanks in advance.
Title: Re: Select nearest boundary to a text
Post by: BIGAL on December 29, 2020, 05:58:29 PM
One method would be to create a Bounding box around the text and offset a small amount repeatedly till it touches say a Pline. The only complication is for angled text but using UCS will make a angled bounding box. Hope you understand big hint "Boundingbox". Use say ssget "F" *pline option with the 4 corners as points. It will return 1 as it will find bounding box but once the sslength is 2 you have another object.
Title: Re: Select nearest boundary to a text
Post by: civil.eng on December 31, 2020, 05:58:30 AM
Thanks for replying, it's a good idea for select the boundary by offset bounding box, but how many offset do‌es the bounding box need to get the boundary if distance of the boundary is much greater than the bounding box? Doesn't it affect the speed of the program if lots of texts is selected?

Title: Re: Select nearest boundary to a text
Post by: Lee Mac on December 31, 2020, 12:55:17 PM
I would personally suggest calculating the coordinates of the centre of the text box (or perhaps using the text insertion point) with a ray-casting algorithm to determine whether such point lies inside the rectangular polylines in your drawing.
Title: Re: Select nearest boundary to a text
Post by: civil.eng on January 02, 2021, 02:35:47 AM
I would personally suggest calculating the coordinates of the centre of the text box (or perhaps using the text insertion point) with a ray-casting algorithm to determine whether such point lies inside the rectangular polylines in your drawing.

Thank you lee.mac, that is a good method to get boundary with Ray.
Title: Re: Select nearest boundary to a text
Post by: BIGAL on January 04, 2021, 11:56:10 PM
Nice idea Lee can use ssget "F" cenpt otherpt for the ray as only really need 1 direction , could use some form of strlen* text ht to limit a bit the selection of multi rectangs from centre look at image left/right make a list of intersectwith saving distance and entity name then sort list shortest distance is the closest.