0

I want to monitor my commands and save that data in a text file on the server, so people can see how many times (in 1 week, 2 weeks, 1 month) I used the line command, pline command, etc.

That text file continues counting all the time.

I already have acaddoc.lsp,and I have this lisp from Lee Mac (thanks) that is counting the commands, but I don't want them to print on the screen, only count them in the text file.

(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 "\n\n ")
           (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

1 Answer 1

1

In function

cmdspy:print

open file:

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

than change princ to (write-line ..... des)

at the end of function cmdspy:print close file

(close des)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.