autocad命令计数器和存储数据



我想监控我的命令并将数据保存在服务器上的文本文件中,这样人们就可以看到我使用line命令,pline命令等的次数(1周,2周,1个月)

这个文本文件一直在计数。

我已经有acaddoc.lsp,我有这个lisp从李Mac(谢谢),是计数命令,但我不希望他们在屏幕上打印,只计数他们在文本文件。

(defun c:viewcmd nil
(if (or cmdspy:endlst cmdspy:unklst cmdspy:canlst)
(progn
(mapcar 'cmdspy:print
'("Completed Commands" "Cancelled Commands" "Unknown Commands")
(list cmdspy:endlst cmdspy:canlst cmdspy:unklst)
)
(textscr)
)
(princ "nNo command history found.")
)
(princ)
)
(defun cmdspy:updatelist ( cmd lst / itm )
(if (setq itm (assoc cmd lst))
(subst (cons cmd (1+ (cdr itm))) itm lst)
(cons  (cons cmd 1) lst)
)
)
(defun cmdspy:print ( hed lst / len )
(if lst
(progn
(setq len (/ (- 30 (strlen hed)) 2))
(princ "nn ")
(repeat len (princ "-"))
(princ " ") (princ  hed) (princ " ")
(repeat len (princ "-")) 
(foreach itm (vl-sort lst '(lambda ( a b ) (> (cdr a) (cdr b))))
(princ  (strcat "n " (car itm) " "))
(repeat (- 30 (strlen (car itm)) (strlen (itoa (cdr itm)))) (princ "."))
(princ  (strcat " " (itoa (cdr itm))))
)
(princ (strcat "n TOTAL: " (itoa (apply '+ (mapcar 'cdr lst)))))
)
)
)
(   (lambda nil
(vl-load-com)
(mapcar
'(lambda ( s1 s2 )
(eval
(list 'defun s1 '( obj arg )
(list 'setq s2 (list 'cmdspy:updatelist '(strcase (car arg)) s2))
)
)
)
'(cmdspy:endfun cmdspy:unkfun cmdspy:canfun)
'(cmdspy:endlst cmdspy:unklst cmdspy:canlst)
)
(if (null cmdspy:reactor)
(setq cmdspy:reactor
(vlr-command-reactor "cmdspy"
'(
(:vlr-commandended     . cmdspy:endfun)
(:vlr-unknowncommand   . cmdspy:unkfun)
(:vlr-commandcancelled . cmdspy:canfun)
)
)
)
)
(princ)
)
)
; Edited July 21, 2015 by Lee Mac

In function

cmdspy:print

打开文件:

(setq des (open "C:\MyTextFile.txt" "a"))

princ改为(write-line ..... des)

在函数cmdspy:print结束时关闭文件

(close des)

相关内容

  • 没有找到相关文章

最新更新