Hi,
I'd like to get areas from all closed loop polygons of my drawing and save them.
From my point of view, the function would be to:
- hatch every polygon of my drawing
- for each hatch do
- extract area and put it in an array with the variables (name of polygon and area).
and then is it possible to save it in a DWG or DXF file in order to reuse these areas by another program ?
Is there an easier way of doing this task ?
Thanks in advance for your help.
Solved! Go to Solution.
Solved by DRossger. Go to Solution.
Solved by hmsilva. Go to Solution.
@suisse_power wrote:....
I'd like to get areas from all closed loop polygons of my drawing and save them.
From my point of view, the function would be to:
- hatch every polygon of my drawing
- for each hatch do
- extract area and put it in an array with the variables (name of polygon and area).
....
Is there an easier way of doing this task ?
....
For the extract-the-areas part of the question, if the only reason you want to Hatch all polygons is to find their areas, you can skip the Hatching part.
(command "_.area" "_object" PolylineEntityName)
will result in the Polyline's area being stored in the AREA System Variable, which you can pull out of it with:
(getvar 'area)
For the "put it in an array" part of the question, what do you mean by that? A chart-like arrangement of Text entities? A Table? An Mtext object with all of them in one? An AutoLISP list?
And does "name of polygon" mean the entity name of the Polyline entity? If you want that in Text/Mtext content, that could be hard -- I'm not sure you can turn an entity name into a text string [it's a completely different kind of information from most entity data entries].
Thanks Kent,
Once I pull out the areas with "getvar 'area" is it possible to save the values in a DWG or DXF file ?
For the Array question, don't worry it was solved by the first part of your answer.
@suisse_power wrote:....
Once I pull out the areas with "getvar 'area" is it possible to save the values in a DWG or DXF file ?
....
To do that would, I assume, mean making Text or Mtext that contains the area information, and sending it out with something like WBLOCK or DXFOUT [but I think the latter will take the whole drawing, not just the area information] to another file. You originally asked about making a DWG/DXF file for use by another program -- what kind of program? Would it be able to get string-content information from Text in a DWG/DXF file? Would it be better to write the areas out to a plain .TXT file, or something else?
I understand,
In fact, I convert a DWG to SVG in order to use it in HTML.
So basically, I get all the layout, but I wanted to extract the area values.
What would you recommend ? Extracting areas to a json file and "trying" to link them with the svg ?
@suisse_power wrote:... I convert a DWG to SVG in order to use it in HTML.
So basically, I get all the layout, but I wanted to extract the area values.
What would you recommend ? Extracting areas to a json file and "trying" to link them with the svg ?
Sorry, but you've gone beyond my area of experience; someone else will need to recommend an approach. If in the end you want a plain-text file via (open)/(write-line)/(close), or a .DWG file via WBLOCK, I could work out how to do those.
I think writing all the areas in a plain text file is the best solution to start with.
Could you please guide me ?
I'll think afterwards on how to exploit it for my purposes.
suisse_power wrote:
I think writing all the areas in a plain text file is the best solution to start with.
Could you please guide me ?
I'll think afterwards on how to exploit it for my purposes.
maybe something like this, will write the Entity name and the area
(defun c:test (/ OFile itm num name area) (if (setq ss (ssget "x" '((0 . "*POLYLINE") (70 . 1)))) (progn (setq OFile (open "C:\\Test\\Area.txt" "W"));; change the path and file name (setq itm 0 num (sslength ss) ) (while (< itm num) (setq name (vl-princ-to-string (car (entget (ssname ss itm))))) (setq name (vl-string-left-trim "(-1 . <Entity name: " name)) (setq name (vl-string-right-trim ">)" name)) (if (vlax-property-available-p (vlax-ename->vla-object (ssname ss itm)) 'Area ) (setq area (vla-get-area (vlax-ename->vla-object (ssname ss itm))) ) (setq name "Object without area") );; if (write-line (strcat name " " (rtos area 2 2)) OFile) (setq itm (1+ itm)) );; while (close OFile) );; progn );; if (setq ss nil) (princ) )
Hope that helps
Henrique
Thanks Kent1Cooper and HmSilva for your help.
I have now a much more precise idea on how to solve my problem.
@hmsilva wrote:....
(defun c:test (/ OFile itm num name area) (if (setq ss (ssget "x" '((0 . "*POLYLINE") (70 . 1)))) ........
I think that needs to be more sophisticated. (70 . 1) will be there only for 2D "heavy" or LWPolylines that are closed but that are not curve-fit or splined and do not have linetype generation enabled. Various other bit components can be added into the (70) value for other Polylines that you would presumably want to include -- 2 for curve-fit, 4 for splined, 8 for 3D even if it's flat so that it has an Area property, a few for polygon and polyface meshes, 128 if linetype generation is on. Polylines with any of those other qualities, even if they're closed, will be omitted by that (ssget) filter. You may need to find them all without that filter, and step through and check whether each one is closed along with checking whether it has Area.
Kent1Cooper wrote:
think that needs to be more sophisticated. (70 . 1) will be there only for 2D "heavy" or LWPolylines that are closed but that are not curve-fit or splined and do not have linetype generation enabled. Various other bit components can be added into the (70) value for other Polylines that you would presumably want to include -- 2 for curve-fit, 4 for splined, 8 for 3D even if it's flat so that it has an Area property, a few for polygon and polyface meshes, 128 if linetype generation is on. Polylines with any of those other qualities, even if they're closed, will be omitted by that (ssget) filter. You may need to find them all without that filter, and step through and check whether each one is closed along with checking whether it has Area.
Kent, the OP asked to "Saving areas of all closed polygon", may be mistaken, but polygons are closed shapes with straight sides, therefore I did not see necessity to other bit components to curve-fit or splined *polylines, but I think that should add 8 for 3D and 128 if linetype generation is on (I forgot linetype generation).
Henrique
I had have the same problem. In my blogg http://cadplayerlounge.blogspot.se/2013/01/calculate-area-from-polylines.html you can see a beginning. Build in closed polyline selection and you a nearly perfect tool.