Author Topic: Select nearest boundary to a text  (Read 378 times)

0 Members and 1 Guest are viewing this topic.

civil.eng

• Mosquito
• Posts: 18
Select nearest boundary to a text
« 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?

BIGAL

• Swamp Rat
• Posts: 581
• 30 + years of using Autocad
Re: Select nearest boundary to a text
« Reply #1 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.

civil.eng

• Mosquito
• Posts: 18
Re: Select nearest boundary to a text
« Reply #2 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?

Lee Mac

• Seagull
• Posts: 12424
• London, England
Re: Select nearest boundary to a text
« Reply #3 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.

civil.eng

• Mosquito
• Posts: 18
Re: Select nearest boundary to a text
« Reply #4 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.

BIGAL

• Swamp Rat
• Posts: 581
• 30 + years of using Autocad
Re: Select nearest boundary to a text
« Reply #5 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.