I am looking for a way to automatically detect rectangles of certain size in an autocad file and add a numbering attribute to it which later could be exported in the form of a csv report.
In the attached dwg file you will find a set of rectangles which are arranged in the form of an array with 6 columns and 4 rows although they have not been constructed using array function in Autocad. The program should automatically number them as follows:
19 20 21 22 23 24
13 14 15 16 17 18
07 08 09 10 11 12
01 02 03 04 05 06
Is this something doable in Autocad?
Take a look at this thread about Blocks, and this related one [which has a link to the former] about Text. I don't think it would be difficult to modify either of those to sort Polylines into a similar list, sorting from the Bottom row first and from the Left in each row. An initial selection of Polylines could be stepped through to keep only those of a certain size, or within a certain size range, or whatever your criteria would be, before applying the sorting operation. It could then use the resulting sorted list of Polyline entity names to place sequential Text elements. [The exporting to .csv I leave to others.] Does that seem worth pursuing?
You can try attached ALTEXT.vlx.
There are 2 methods to do it.
Method 1
1. Create a text object in the middle of each rectangle.
2. Use ALTEXT to select texts.
3. Select "Left-Right / Up-Down" option in "Sort selection" part.
4. Mirror the result.
->
->
Method 2
1. Create a text object in the middle of each rectangle.
2. Use ALTEXT to select texts.
3. Create a polyline / polylines to present the number sequence. (You can create 1 part, array it then JOIN all parts as one polyline)
4. Select "Along paths" option in "Sort selection" part.
5. Select the polyline(s) in Step 3.
->
If you need leading zero in the result, just put a leading zero in original texts, eg. "01"