Try this pick as many different blocks it uses name to sort the blocks and do counts.
Code:
;http://forums.augi.com/showthread.php?171762-Extracted-attributes-from-AutoCAD-into-excel-pre-formatted-spread-sheet
; Bill tillman also
; Take a block atts and make them into a table
; counting the blocks also
; by Alan H April 2018
(defun AH:block-atts ( / x k obj obj2 ans ans2 comparelems AH:gotable)
(defun AH:gotable ( / txt)
(setq rownum (vla-get-rows obj2))
(vla-InsertRows obj2 rownum (vla-GetRowHeight obj2 (- rownum 1)) 1)
(repeat (setq k (length ans))
(setq txt (nth (setq k (- k 1)) ans))
(vla-settext obj2 rownum k txt)
)
(vla-settext obj2 rownum (- numcols 1) (rtos tot 2 0))
(setq tot 1)
)
(defun comparelems ( / )
(if (and
(= (nth 0 ans)(nth 0 ans2))
(= (nth 1 ans)(nth 1 ans2))
)
(setq tot (+ tot 1))
(AH:gotable )
)
)
(setq lst '())
(setq ss (ssget '((0 . "insert"))))
(repeat (setq x (sslength ss))
(setq lst2 '())
(setq obj (vlax-ename->vla-object (ssname ss (setq x (- x 1)))))
(if (and (vlax-property-available-p obj "hasattributes")
(setq atts (vlax-invoke obj "getattributes"))
)
(progn
(setq lst2 (cons (vla-get-EffectiveName obj) lst2))
(foreach att atts
(setq lst2 (cons (vla-get-textstring att) lst2))
)
(setq lst (cons (reverse lst2) lst))
)
)
)
; sorts on 1st two items
(setq lst (vl-sort lst '(lambda (x y)
(cond
((= (cadr x)(cadr y))
(< (car x)(car y)))
((< (cadr x)(cadr y)))
))))
(setq numcols 1)
(repeat (setq x (length lst))
(setq len (length (nth (setq x (- x 1)) lst)))
(if (> len numcols)
(setq numcols len)
)
)
(setq numcols (+ len 1))
; add better pick
(setq obj2 (vlax-ename->vla-object (car (entsel "pick table or any other object to create a table"))))
(if (/= (vla-get-objectname obj2) "AcDBtable")
(progn
(if (not AH:table_make)(load "table create2"))
(AH:table_make numcols)
(setq obj2 (vlax-ename->vla-object (entlast)))
)
(princ)
)
(setq x 0)
(setq tot 1)
(setq ans (nth x lst))
(repeat (- (length lst) 1)
(setq ans2 (nth (setq x (+ x 1)) lst))
(comparelems)
(setq ans ans2)
)
)
(AH:block-atts)