Export Closed Polyline Area total to Excel by Layer

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am new to the forum and have only basic knowledge of lisp routines and have been trying to search for and or create a lisp routine to export the area of multiple closed polylines by layer. I would like the lisp routine to export a .csv file with the first column having the name of the file, without .DWG, the second column would contain the area of each individual closed polyline, the third column would contain the layer name. Ideally the file would be sorted/grouped by layer type and then have a total area for each layer type. I am not even sure if this last request is possible.
Below is my attempt by using a routine I found and trying to edit it. I am unsure how to create the routine to group by layer and get the sum of each layer to display correctly. Thanks a ton for any help or insight you can give.
(defun c:EPD2 (/ ss i area layer all_data pts csv_file openfile) ; Export Polyline Data
;; pBe Sep 2018 ;;
(if (and
(setq all_data nil
ss (ssget '((0 . "LWPOLYLINE")))
)
(repeat (setq i (sslength ss))
(setq e (ssname ss (setq i (1- i)))
ent (entget e)
area ( / (vlax-curve-getarea e) (* 12 12))
data (mapcar '(lambda (d)(cdr (assoc d ent))) '( 8 70 5))
pts (mapcar 'cdr
(vl-remove-if-not
'(lambda (d)
(= 10 (car d))
)
ent
)
)
)
(setq all_data
(cons
(list
(cond
((null (setq ssText (ssget "_CP" pts '((0 . "TEXT"))))) (getvar 'dwgprefix)
(vl-filename-base (getvar 'dwgname))
)
((= (sslength ssText) 1)
(cdr (assoc 1 (entget (ssname ssText 0))))
)
((substr
(apply 'strcat
(mapcar '(lambda (st)
(strcat " | " st))
(vl-sort
(mapcar '(lambda (s)
(cdr (assoc 1 (Entget s)))
)
(vl-remove-if 'listp (mapcar 'cadr (ssnamex ssText)))
)
(function (lambda (a b)
(< a b)
)
)
)
)
)
4
)
)
)
area
(car data)
(if (zerop ( logand 1 (cadr data))) "No" "Yes")
(caddr data)
)
all_data
)
)
all_data
)
(setq csv_file (getfiled "Save CSV File"
(strcat
(getvar 'dwgprefix)
(vl-filename-base (getvar 'dwgname))
".csv"
)
"csv"
45
)
)
)
(progn
(setq openfile (open csv_file "w"))
;(write-line
;"Text inside polyline,Polyline Area (sf),Layer,Closed,Handle"
;openfile
(foreach itm (vl-sort all_data
'(lambda (a b) (< (Cadr a) (cadr b)))
)
(write-line
(Strcat (Car itm)
","
(strcat (rtos (Cadr itm) 2 2))
","
(caddr itm)
","
(cadddr itm)
","
(last itm)
)
openfile
)
)
(close openfile)
(startapp "notepad" csv_file)
)
)
(princ)
)