Polygon Area Export to Excel

Polygon Area Export to Excel

Anonymous
Not applicable
2,891 Views
3 Replies
Message 1 of 4

Polygon Area Export to Excel

Anonymous
Not applicable

Hello, 

 

I am new to writing programs for AutoCAD and would like to create a lisp that exports areas of polygons with their name and quantities into an excel document.

 

Essentially, I am trying to calculate the area within the white outline and export it to excel. For the area data to be of use, I will need the first line(Part ID) and the last line(Quantity) of the yellow text to be exported with each of the areas. For example, the picture attached has an ID of P2 and a quantity of 3.

 

PG4.PNG

This program would be used on dwg files that contain a hundred polygons on average which are very similar to the one shown above, but often their shapes are irregular. 

 

Note that the white outline is on the layer named "Cut" and the yellow single line text is on the layer "TEXT". 

I attached the dwg for reference. 

 

Can this be done with a lisp? If so, how should I go about this?

 

Thank you, 


Tim 

 

 

0 Likes
2,892 Views
3 Replies
Replies (3)
Message 2 of 4

Kent1Cooper
Consultant
Consultant

That can be done, though it's not trivial.

 

To start with, you would need the outlines changed to Polylines instead of independent Lines.  Assuming the Lines all meet accurately at their ends to form closed outlines, a routine could start out with this, which will do that much:

 

(setvar 'peditaccept 1); just in case

(command "_.pedit" "_multiple" (ssget "_X" '((8 . "CUT"))) "" "_join" 0 "")

 

Then it could find all resulting closed Polylines on that Layer, and step through them.  For each, it can get its area [via VLA Properties].  It would need to find the Text inside each -- there are routines around that will take the vertices and apply them as a WindowPolygon selection to do that.  It could then find the one among those with the highest insertion-point Y coordinate, and extract its content for the Part ID, and the one with the lowest, and extract its content for the Quantity.  [That assumes that the relative position of the Text objects is consistent.]  It could put the results for each into a comma-delimited string and write them all out to a .csv file.

 

So yes, it's possible....  Are you versed enough in such things to start to put it together?

 

 

Kent Cooper, AIA
0 Likes
Message 3 of 4

Anonymous
Not applicable

I found a lisp on another post that I can use to convert the lines on the cut layer to closed polyline shapes, so it's no problem getting the objects prepped for the area command.  

 

The 4 lines of text for each of the shapes is always consistent, but its location is not entirely consistent. The text will always be within the shape defined by the cut layer, in the same order from top to bottom, but the location of the 4 lines of text inside the shape can vary. 

 

I have used AutoCAD for several years, but this is my first attempt at creating a lisp. 

0 Likes
Message 4 of 4

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

.... 

The 4 lines of text for each of the shapes is always consistent, but its location is not entirely consistent. The text will always be within the shape defined by the cut layer, in the same order from top to bottom, but the location of the 4 lines of text inside the shape can vary. 

....


As long as they're always inside, and there aren't any more than the typical 4 inside any outline, a routine can find them.  Search for things similar to "find everything inside Polyline" and I think you'll get a variety of hits.

Kent Cooper, AIA
0 Likes