eachy斑主:
其实我对lisp是不太懂的,我只会利用。统计文字个数对于我来说非常重要,因为我经常要统计料单,统计图块的程序我目前用的非常成熟,希望统计文字能够好像以下统计图块这样方便运用,非常感谢!
 - (defun lststr (str / pos numlst chr len wrd wrdlst)
- (setq pos 1)
- (setq numlst '())
- (setq wrdlst '())
- (setq chr (substr str pos 1))
- (while (/= chr "")
- (if (= chr ",")
- (setq numlst (append numlst (list pos)))
- )
- (setq pos (1+ pos))
- (setq chr (substr str pos 1))
- );while
- (setq numlst (append numlst (list (1+ (strlen str)))))
- (setq pos 1)
- (setq len (1- (car numlst)))
- (setq wrd (substr str pos len))
- (while (/= wrd "")
- (setq wrdlst (append wrdlst (list wrd)))
- (setq pos (1+ (car numlst)))
- (if (> (length numlst) 1)
- (setq len (1- (- (cadr numlst) (car numlst) )) )
- )
- (setq numlst (cdr numlst))
- (setq wrd (substr str pos len))
- )
- wrdlst
- )
- (Defun addsp (strn / scount)
- (setq scount (strlen strn))
- (repeat (- 10 scount)
- (setq strn (strcat strn " "))
- )
- strn
- )
- (defun c:blcount (/ record blnme name v1 outfl blklst bllst blist)
- (SETVAR "CMDECHO" 0)
- (setq blist (STRCASE (getstring "\nEnter name(s) of blocks to count or RETURN for all: ")))
- (if (= Blist "")
- (setq record (cdr (assoc 2 (tblnext "block" t))))
- (setq record (car (setq blist2 (lststr blist))))
- )
- (setq blklst '())
- (princ "\nSearching for blocks... Please wait. ")
- (while record
- (setq blnme (cons 2 record))
- (setq v1 (ssget "x" (list blnme) ))
- (if v1
- (progn
- (setq bllst (strcat (addsp record) "\t" (itoa (sslength v1)) "\n"))
- (princ bllst)
- (setq blklst (append blklst (list bllst)))
- );progn
- );if
- (if (= Blist "")
- (setq record (cdr (assoc 2 (tblnext "block"))))
- (progn
- (setq blist2 (cdr blist2))
- (setq record (car blist2))
- )
- )
- (princ "\nSearching for blocks... Please wait. ")
- );while
- (princ "\n图块数量已经统计到")(princ "临时")
- (setq outfl (open "d:/临时.xls" "w"))
- (foreach n blklst (princ n outfl))
- (close outfl)
- (command "_ai_editcustfile" "d:/临时.xls")
- (princ)
- )
|