Ok try this:
Code:
(defun c:tsel (/ *error* doc spc ss bPt
lst tss olst tblObj i)
(vl-load-com)
(defun *error* (msg)
(and doc (vla-EndUndoMark doc))
(if
(not
(wcmatch
(strcase msg)
"*BREAK,*CANCEL*,*EXIT*"))
(princ
(strcat
"\n<< Error: " msg " >>")))
(princ))
(setq doc
(vla-get-ActiveDocument
(vlax-get-Acad-Object))
spc (if
(zerop
(vla-get-activespace doc))
(if (= (vla-get-mspace doc) :vlax-true)
(vla-get-modelspace doc)
(vla-get-paperspace doc))
(vla-get-modelspace doc)) i 2)
(cond ((eq 4 (logand 4 (cdr (assoc 70 (tblsearch "LAYER" (getvar "CLAYER"))))))
(princ "\n<< Current Layer Locked >>"))
(t
(if (and (setq ss (ssget '((0 . "*TEXT"))))
(setq bPt (getpoint "\nSelect Point for Table: ")))
(progn
(vla-StartUndoMark doc)
(setq lst
(mapcar
(function
(lambda (x)
(vla-get-TextString
(vlax-ename->vla-object x))))
(vl-remove-if 'listp
(mapcar 'cadr (ssnamex ss)))))
(foreach str (unique lst)
(if (setq tss
(ssget "_X"
(list '(0 . "*TEXT") (cons 1 str))))
(setq olst
(cons
(cons str (sslength tss)) olst))
(setq olst
(cons
(cons str 0.) olst))))
(setq tblObj
(vla-addTable spc
(vlax-3D-point bPt)
(+ 2 (length olst)) 2 (* 1.5 (getvar "DIMTXT"))
(* (apply 'max
(mapcar 'strlen
(append '("String")
(apply 'append
(mapcar
(function
(lambda (x)
(list (car x)
(rtos (cdr x) 2 0)))) olst)))))
1.5 (getvar "DIMTXT"))))
(vla-setText tblObj 0 0 "String Counter")
(vla-setText tblObj 1 0 "String")
(vla-setText tblObj 1 1 "Count")
(foreach x (vl-sort olst
(function
(lambda (a b)
(< (car a) (car b)))))
(vla-setText tblObj i 0 (car x))
(vla-setText tblObj i 1 (rtos (cdr x) 2 0))
(setq i (1+ i)))
(vla-EndUndoMark doc)))))
(princ))
;; CAB
(defun unique (lst / result)
(reverse
(while (setq itm (car lst))
(setq lst (vl-remove itm lst)
result (cons itm result)))))
Bookmarks