1
2
初来乍到
使用道具 举报
10
8258
8335
39
180
141
初露锋芒
; TXTCNT.lsp - Count how many times each text entity appears.; Display the results sorted in a dialog box. ; BY jeffery p sanders(defun C:TXTCNT () ;define a sort routine - Usage: (srt list) - Let's not go into this yet! It works. (defun srt (alist / n) (setq lcup nil rcup nil ) (defun cts (a b) (cond ((> a b) t) ((= a b) t) (t nil) ) ) (foreach n alist (while (and rcup (cts n (car rcup))) (setq lcup (cons (car rcup) lcup) rcup (cdr rcup) ) ) (while (and lcup (cts (car lcup) n)) (setq rcup (cons (car lcup) rcup) lcup (cdr lcup) ) ) (setq rcup (cons n rcup)) ) (append (reverse lcup) rcup) ) ;turn the command echo off (setvar "cmdecho" 0) ;setup a variable to hold the data (setq datalist (list)) ;select objects (if (setq eset (ssget)) (progn ;set a counter to the first item in the selection set (setq cntr 0) ;loop through each selected entity (while (< cntr (sslength eset)) ;grab the entity's name (setq en (ssname eset cntr)) ;grab the DXF group codes of the entity (setq enlist (entget en)) ;ignore the entity if it is not a TEXT entity (if (= "TEXT" (cdr (assoc 0 enlist))) (progn ;get the text value from the DXF Group Code (setq str (cdr (assoc 1 enlist))) ;setup a variable to check if the entity exist in the datalist list (setq existing 0) ;loop through the datalist to find out if it is a new entity that needs ;to be added to the list or if it already exist and it's counter needs ;to be incremented (foreach a datalist (if (= (car a) str) (setq existing 1) ) ) ;if the entity is new then (if (= existing 0) ;do this - Add the item to the datalist along with a counter that starts at 1 (setq datalist (append datalist (list (cons str 1)))) ;else it's cntr needs to be incremented (setq datalist (subst (cons str (+ 1 (cdr (assoc str datalist)))) (assoc str datalist) datalist ) ) ) ) ) ;increment the entity counter (setq cntr (+ cntr 1)) ) ) ) ;setup a variable to hold the data again, this time in a different fashion (setq newList (list)) ;rearrange the list (foreach a datalist (setq newList (append newList (list (strcat (substr (strcat (car a) " . . . . . . . . . . . . . . . . . . . . . . . . . . " ) 1 50 ) " - " (itoa (cdr a)) ) ) ) )