@harsh ,
Here is a BLKOUT command to extract your blocks to csv file. (you can save it as xlsx and import it back to AutoCAD with TABLE command.)
blocks with the exact Name, xscale, yscale, zscale will be consider the same.
note that if there would be a small difference in scale, they will consider as 2, so blkout uses the current luprec (sysvar) to compare scales. this is 4 digits by default.
The following code lines declares two constants:
(setq PREC (getvar "luprec"))
(setq FUZZ (read (strcat "1e-" (itoa PREC))))
PREC controls the scale precision format for the csv file. you can set a new luprec value in your drawing or hardcode it in the lisp. FUZZ is for the scale comparison and it leans on PREC but you can hardcode it as well.
Note that DIMZIN is effecting scale values.
enjoy
Moshe
(defun c:blkout (/ is_equal nformat ; local functions
PREC FUZZ fname ss elist bname item0 item1 data^ f)
(defun is_equal (itm0 itm1)
(vl-every
'(lambda (a0 a1)
(cond
((= (type a0) 'STR)
(eq a0 a1)
)
( t
(equal a0 a1 FUZZ)
)
); cond
)
itm0 itm1
)
); is_equal
(defun nformat (v)
(rtos v 2 PREC)
)
; here start c:blkout
;
; const
(setq PREC (getvar "luprec"))
(setq FUZZ (read (strcat "1e-" (itoa PREC))))
(if (and
(setq fname (getfiled "Excel file name" (vl-filename-base (getvar "dwgname")) "csv" 1))
(setq ss (ssget '((0 . "insert"))))
)
(progn
(foreach ename (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
(setq elist (entget ename))
(setq bname (strcase (cdr (assoc '2 elist))))
(setq item0 (list bname (cdr (assoc '41 elist)) (cdr (assoc '42 elist)) (cdr (assoc '43 elist))))
(if (and (setq item1 (assoc bname data^))
(is_equal item0 (reverse (cdr (reverse item1))))
)
(progn
(setq item0 (append item0 (list (1+ (last item1))))) ; inc by 1
(setq data^ (cons item0 (vl-remove item1 data^))) ; replace item in data^
)
(setq data^ (cons (append item0 (list 1)) data^)) ; append new item to data^
)
); foreach
; create excel file
(if (not (setq f (open fname "w")))
(prompt (strcat "\nfail to open " fname " for write."))
(progn
(prompt (strcat "\nCreating file " fname))
(write-line "Name,x scale,y scale,z scale,Nos" f) ; header
(foreach item data^
(write-line (strcat "\n" (car item) "," (nformat (cadr item)) "," (nformat (caddr item)) "," (nformat (cadddr item)) "," (rtos (last item) 2 0)) f)
)
(setq f (close f))
); progn
); if
); progn
); if
(princ)
); c:blkout