(defun c:foo (/ a b c d e l n p pr s)
(defun _wf (fn l / f)
(cond ((and (eq 'str (type fn)) (setq f (open fn "w")))
(foreach x l (write-line x f))
(close f)
fn
)
)
)
(setq pr "RG")
(cond ((and (setq s (ssget "_a" (list '(0 . "lwpolyline") '(90 . 4) (cons 410 (getvar 'ctab))))))
(setq l '("ID,LENGTH,WIDTH"))
(setq n 0)
(foreach x (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
(vla-getboundingbox (vlax-ename->vla-object x) 'a 'b)
(setq c (mapcar 'vlax-safearray->list (list a b)))
(setq d (vl-sort (mapcar 'abs (mapcar '- (car c) (cadr c))) '>))
(setq p (mapcar '+ (mapcar '/ (mapcar '+ (car c) (cadr c)) '(2. 2.))))
(entmakex (list '(0 . "TEXT")
'(100 . "AcDbEntity")
'(8 . "ID_Text")
'(100 . "AcDbText")
(cons 10 p)
(cons 40 (cadr d))
(cons 1 (setq e (strcat pr (itoa (setq n (1+ n))))))
'(50 . 0.0)
'(41 . 1.0)
'(51 . 0.0)
'(7 . "Standard")
'(71 . 0)
'(72 . 1)
(cons 11 p)
'(210 0.0 0.0 1.0)
'(100 . "AcDbText")
'(73 . 2)
)
)
(setq
l (cons (strcat e "," (vl-princ-to-string (car d)) "," (vl-princ-to-string (cadr d))) l)
)
)
;; Writes CSV text file to same directory as drawing
(_wf (strcat (getvar 'dwgprefix) (vl-filename-base (getvar 'dwgname)) ".csv") (reverse l))
)
)
(princ)
)
(vl-load-com)