auto run w/ out invoke

Discussion in 'AutoCAD' started by tader1, Mar 24, 2005.

  1. tader1

    tader1 Guest

    hi, anyone give me a push. I found this lisp it records time spent on a dwg in a log file. I'd like it to run by itself whenever an existing file or new dwg is opened and append the log file. It does half of this already but you have to type lonin/log out. I'd like for it to check to see if the log file exists, if so append it. I'm not sure how to autorun is the biggest thing.
    TIA Shawn

    ;===============================================================================
    ; Chris N. Floresca
    ; e-mail:
    ;
    ;;; This file is distributed "as-is," without warranty expressed
    ;;; or implied of any kind, as "freeware" and is
    ;;; not to be sold or used as part of a package to be sold
    ;;; without the express written consent of Miles Baker. This file is
    ;;; to be distributed with the header information and credit
    ;;; for authorship being mentioned in all documentation, on disks, etc.
    ;
    ; . . . . . . . . . . . . . . . . . . . . . . . . . .
    ; logger.lsp
    ;
    ; Description: Creates a log file that keeps track of the number of hours
    ; spent on a drawing/project. It saves the log in date and the
    ; log out date and calculates the time lapse in hours.
    ;
    ; Version: 1.0
    ;
    : Date: February 14, 1996
    ;
    ; Global Vars: %in - login in time
    ; %file - project name
    ;
    ; Assumption: This program assumes user will not spend more than 24 hours
    ; per session, otherwise greater than 24 returns to zero.
    ;
    ; Usage: command: login <return> to log in
    ; command: logout <return> to log out
    ; command: log-help <return> help
    ; command: project <return> change project
    ; command: file <return> change file
    ;
    ; Note: Has a tolerance of 1 second.
    ;
    ; Detail:
    ; Files will look like:
    ; ...
    ; 02/21/93 drawing-name1 09:00:00 19:00:00 12:00:00
    ; 02/23/96 drawing-name2 08:00:00 17:00:00 11:00:00
    ; 03/25/96 drawing-name36 11:00:00 17:00:00 06:00:00
    ; 05/05/96 drawing-name-extra 14:00:00 14:50:00 00:50:00
    ; ...
    ;
    ; File name must have a (log) extension:
    ; ...
    ; example.log
    ; another.log
    ; project.log
    ; disney.log
    ; ...
    ;
    ;===============================================================================

    ;-----------------------------------------------------;
    ;; return the drawing name (only) of current drawing ;;

    (defun dwgname (/ onm nm n)
    (setq onm (getvar "dwgname")) ; original drawing name
    (if (wcmatch onm "*`/*") ; remove path if it exist
    (progn
    (setq n (strlen onm)) ; length of string(dwgname)
    (while (/= "/" (substr onm n 1)) ; keep going until char "/" is found
    (setq nm (substr onm n) ; drawing name
    n (1- n) ; move to the next character
    )
    )
    nm ; stripped drawing name
    )
    (setq nm onm) ; drawing name already stripped
    )
    )

    ;-------------------------------------------------------------------;
    ;; make string of specified length using white space (' ') to fill ;;
    ;; the rest of the spaces, if length is too small, original string ;;
    ;; is returned. ;;

    (defun strsz (string size)
    (while (< (strlen string) size)
    (setq string (strcat string " "))
    )
    string
    )

    ;--------------------------------------------------------------------;
    ;; return current date formatted to dy/mn/yr using cdate system var ;;

    (defun date (/ d)
    (setq d (rtos (getvar "CDATE") 2 0))
    (strcat (substr d 5 2) "/" (substr d 7 2) "/" (substr d 3 2))
    )

    ;------------------------------------------------------;
    ;; return current time--fraction part of julian-date ;;

    (defun time ()
    (- (getvar "date") (fix (getvar "date")))
    )

    ;------------------------------------------------------;
    ;; return the time difference between time1 and time2 ;;

    (defun time-elapse (time1 time2)
    (abs (- time1 time2))
    )

    ;----------------------------------;
    ;; format julian time to HR:MN:SC ;;

    (defun julian-time (time-only / <10)

    ;----------------------------------------------------;
    ; if number is less than 10 then prefix it with zero ;
    (defun <10 (int)
    (if (< int 10) (strcat "0" (itoa int)) (itoa int))
    )

    (setq hr (* 24 (- time-only (fix time-only))) ; hours
    mn (* 60 (- hr (fix hr))) ; minutes
    sc (* 60 (- mn (fix mn))) ; seconds
    )
    (strcat (<10 (fix hr)) ":" (<10 (fix mn)) ":" (<10 (fix sc))) ; Hr:Mn:Sc
    )

    ;---------------------------------;
    ;; set and show user log-in time ;;

    (defun login ()
    (setq %in (time))
    (princ (strcat "\nlogin: " (julian-time %in)))
    )

    ;--------------------------------------------;
    ;; AutoCAD command function to invoke login ;;

    (defun c:login ()
    (if %in
    (progn
    (write-char 7)
    (princ (strcat "\nlogin: " (julian-time %in)))
    (initget "Y N")
    (if (= "Y" (getkword "\nChange? <N>/Y: "))
    (login)
    )
    )
    (login)
    )
    (princ)
    )

    ;----------------------------;
    ;; get the file to save log ;;

    (defun getfile (aprompt)
    (setq %file (getstring T aprompt))
    (if (findfile (strcat %file ".log"))
    (setq %file (findfile (strcat %file ".log")))
    (setq %file (strcat %file ".log"))
    )
    )
    (defun c:getfile () (getfile "\nEnter the Filename <omit ext \(log\): "))
    (defun c:getproject () (getfile "\nEnter the Project Name: "))


    ;------------------------------------;
    ;; logs the information to the file ;;

    (defun logger (info)
    (if (null %file) (getfile "\nEnter File/Project Name: "))
    (setq fp (open %file "a"))
    (write-line info fp)
    (close fp)
    (princ)
    )

    ;--------------------------------------;
    ;; AutoCAD command function to logout ;;

    (defun c:logout (/ out tl info)
    (if %in
    (progn
    (setq tl (time-elapse %in (setq out (time))))

    (princ (strcat "\nlogin: " (strsz (julian-time %in) 25)
    "logout: " (strsz (julian-time out) 25)
    "time-elapse: " (julian-time tl) ))

    (setq info (strcat (strsz (date) 10)
    (strsz (dwgname) 25)
    (strsz (julian-time %in) 15)
    (strsz (julian-time out) 15)
    (strsz (julian-time tl) 8) ))

    (logger info)

    (setq %in nil)
    )
    (progn
    (write-char 7)
    (princ "\nlogin NOT set.")
    (initget "Y N")
    (if (= "Y" (getkword "\nSet login NOW? <N>/Y: "))
    (login)
    )
    )
    )
    (princ)
    )
    ;--------;
    ;; help ;;

    (defun c:log-help ()
    (textscr)
    (princ (strcat
    "AVAILABLE COMMANDS:\n\n"
    "\tlogin - set (new) log in time\n"
    "\tlogout - log out, saves information to file/project\n"
    "\tgetfile/getproject - set logfile name\n"
    "\tlog-hep - call this command\n\n\n"
    "press <enter> to continue -> "
    ))
    (getstring)
    (graphscr)
    )
     
    tader1, Mar 24, 2005
    #1
  2. tader1

    ECCAD Guest

    Shawn,
    You might place a (load "logger") in your acaddoc.lsp..
    But, that only gets it to run on New or Open..not the
    elapsed time for (current) drawing. I think you would need
    a reactor (close of dwg)..to initiate the 'automatic' save
    of the time to the log file.
    You may want to search the Discussion Group also, I seem
    to recall a nifty program to log the time.

    Bob
     
    ECCAD, Mar 24, 2005
    #2
  3. tader1

    tader1 Guest

    oh no, reactors. I was just learning what mapcar does. Anyway thnx.
     
    tader1, Mar 24, 2005
    #3
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.