Author Topic: (challenge) Save editing time to a log file  (Read 10262 times)

0 Members and 1 Guest are viewing this topic.

Dommy2Hotty

  • Swamp Rat
  • Posts: 1127
Re: (challenge) Save editing time to a log file
« Reply #15 on: October 11, 2005, 04:38:37 PM »
Okay, I assume that I placed your cond in the right spot ( in place of the appending part ).  When a drawing is opened I receive the error that S::STARTUP function defined by defun, not defun-q.  Does that help diagnose the problem?

Code: [Select]
;;;OPEN DRAWING LOGFILE SECTION**********************

 

(defun timedate (/ cdate ctime ampm stime)
 (setq cdate (rtos (fix (getvar 'cdate)) 2 0)
          ctime (rtos (rem (getvar 'cdate) 1) 2 6)
          ampm  (if (<= (atof (substr ctime 3 2)) 12)
                   "AM"
                   "PM"
               )
          stime (strcat
                   (substr cdate 1 4)
                   "-"
                   (substr cdate 5 2)
                   "-"
                   (substr cdate 7 2)
                   " "
                   (substr ctime 3 2)
                   ":"
                   (substr ctime 5 2)
                   ":"
                   (substr ctime 7 2)
                   ":"
                   ampm
               )
 )
)

(defun-q MYSTARTUP ()
          (if (not (wcmatch (getvar 'DWGNAME) "Drawing1.dwg"))
            (progn
            (setq FILEDESC (open "C:\Opened_Files.log" "a"))
            (write-line
              (strcat (timedate)
                       " "
                       (getvar 'DWGPREFIX)
                       (getvar 'DWGNAME)
              )
              FILEDESC
            )
            (close FILEDESC)
            (setq FILEDESC nil)
            )
          )
)

(cond
    ;;  assuming the MYSTARTUP function is defined properly ...
    (   (null S::STARTUP) 
        (setq S::STARTUP MYSTARTUP)
    )
    (   (listp S::STARTUP)
        (setq S::STARTUP (append S::STARTUP MYSTARTUP))
    )
    (   (alert
            (strcat
                "Error:\n\n"
                "S::STARTUP function defined by defun, not defun-q."
            )   
        )
    )   
)


;;;;END OPEN DRAWING LOGFILE SECTION**********************

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: (challenge) Save editing time to a log file
« Reply #16 on: October 11, 2005, 04:42:29 PM »
Quote from: Dommy2Hotty
Okay, I assume that I placed your cond in the right spot ( in place of the appending part ).  When a drawing is opened I receive the error that S::STARTUP function defined by defun, not defun-q.  Does that help diagnose the problem?

Yep.

I'd search her machine for the string "s::startup" (case insensitive) and find all the locations where said statement exists. From there you need to consolidate / incorporate / distil. Notwithstanding, is her machine breaking any company standardization by having its own startup yada?
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Dommy2Hotty

  • Swamp Rat
  • Posts: 1127
Re: (challenge) Save editing time to a log file
« Reply #17 on: October 11, 2005, 04:52:22 PM »
I'd search her machine for the string "s::startup" (case insensitive) and find all the locations where said statement exists. From there you need to consolidate / incorporate / distil. Notwithstanding, is her machine breaking any company standardization by having its own startup yada?

Thank you very much.  Is there an easy (prolly not) way to go about finding all the files that it can be in?  And no company standardization problems...her and I take care of all that, so whatever she's got going on with her computer is fine.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: (challenge) Save editing time to a log file
« Reply #18 on: October 11, 2005, 05:14:53 PM »
This at DOS:

Code: [Select]
findstr /i /s /m /c:"defun s::startup" c:\cad\*.lsp >> c:\HasStartupInIt.txt
findstr /i /s /m /c:"defun s::startup" c:\cad\*.mnl >> c:\HasStartupInIt.txt

Would put a listing of all lsp and mnl files that contain the phrase "defun s::startup" into the file c:\HasStartupInIt.txt. Like:

c:\cad\Acad2002\Sample\VisualLISP\External\blackboard.lsp
c:\cad\Acad2004\Sample\VisualLISP\External\blackboard.lsp
c:\cad\Acad2004\Support\sample-profile-util.lsp
c:\cad\Acad2004\Support\sample-profile-util.lsp


This of course, assuming the directory c:\cad were legit.

If you use /n instead of /m it will list the actual line numbers, like so --

c:\cad\Acad2002\Sample\VisualLISP\External\blackboard.lsp:181: (defun s::startup ()
c:\cad\Acad2004\Sample\VisualLISP\External\blackboard.lsp:181: (defun s::startup ()
c:\cad\Acad2004\Support\sample-profile-util.lsp:59:;;; (defun s::startup ()
c:\cad\Acad2004\Support\sample-profile-util.lsp:72:;;; (defun s::startup ()
« Last Edit: October 11, 2005, 05:20:40 PM by MP »
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Dommy2Hotty

  • Swamp Rat
  • Posts: 1127
Re: (challenge) Save editing time to a log file
« Reply #19 on: October 11, 2005, 05:21:20 PM »
I see...thank you...let the search begin!

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: (challenge) Save editing time to a log file
« Reply #20 on: October 11, 2005, 05:24:44 PM »
Just be careful when using DOS redirection, i.e. this part:

>> c:\HasStartupInIt.txt

Two greater than signs (>>) appends new data to and existing data in the file c:\HasStartupInIt.txt. One greater than sign (>) will overwrite any existing data.

And there's no warning, it just obeys.

As it should.

:)

Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Dommy2Hotty

  • Swamp Rat
  • Posts: 1127
Re: (challenge) Save editing time to a log file
« Reply #21 on: October 11, 2005, 05:27:13 PM »
And there's no warning, it just obeys.

As it should.

:)



 :-D

sinc

  • Guest
Re: (challenge) Save editing time to a log file
« Reply #22 on: October 31, 2005, 11:12:00 AM »
This has worked for me with no problems.  I had a co-worker add this to her acad2004doc.lsp file and it gives her this error:
Code: [Select]
AutoCAD Express Tools Copyright © 2002-2003 Autodesk, Inc.
; error: Invalid attempt to access a compiled function definition.  You may
want to define it using defun-q: #<SUBR @05d2f9d8 S::STARTUP>

I added it to hers the same way I added it to mine:
Command: (startapp "notepad" (findfile "acad2004doc.lsp"))
But her's throws the error.  Any ideas?
I don't think you should really be adding this to the "acad2004doc.lsp".  Technically, it should be placed in the "acaddoc.lsp" file.  In general, you shouldn't need or want to edit the acad2004doc.lsp.

This probably won't fix your problem, which is more likely caused by what MP suggests.

Dommy2Hotty

  • Swamp Rat
  • Posts: 1127
Re: (challenge) Save editing time to a log file
« Reply #23 on: October 31, 2005, 11:15:42 AM »
Just an update:

The problem was caused by FYPONCAD.  It created ACAD.LSP with one line: (Load FyponCad) <~basically
So I deleted that file and all is well.

Amsterdammed

  • Guest
Re: (challenge) Save editing time to a log file
« Reply #24 on: November 01, 2005, 07:19:05 AM »
Dommy,
I had the same Problem a while ago and Juerg Menzi wrote some great solution which works with a timeout function, so only when you WORK it will count the time.

Code: [Select]
;== AcadDoc.lsp ==============================================================
; Sets Command Reactors to collect the command time.
; Sets a DocManager Reactor to release the Reactor objects at the end
; of an AutoCAD session.
; Copyright:
;   ©2005 MENZI ENGINEERING GmbH, Switzerland
; Notes:
;   - None
; - Initialize ActiveX support
(vl-load-com)
;
; - Initialize session variables
;
(setq Me:DwgNme ""   ;empty drawing name
      Me:CmdTim 0   ;command time
      Me:CmdTmp 0   ;temporary command time
      Me:CmdCnt 0   ;command count
      Me:TimOut 180   ;command timeout
)
;
; - Reactors ------------------------------------------------------------------
;
; - If not set, initialize DocManager-Reactor
(or Me:ReaDma
 (setq Me:ReaDma (VLR-DocManager-Reactor
                  nil
                 '(
                   (:VLR-documentToBeDestroyed . MeDocToBeDestroyedCallbacks)
                  )
                 )
 )
)
; - If not set, initialize DWG-Reactor
(or Me:ReaDwg
 (setq Me:ReaDwg (VLR-DWG-Reactor
                  nil
                 '(
                   (:VLR-SaveComplete . MeDwgSaveCompleteCallbacks)
                  )
                 )
 )
)
; - If not set, initialize Command-Reactor
(or Me:ReaCom
 (setq Me:ReaCom (VLR-Command-Reactor
                  nil
                 '(
                   (:VLR-commandWillStart . MeCommandWillStartCallbacks)
                   (:VLR-commandEnded . MeCommandEndedCallbacks)
                   (:VLR-commandCancelled . MeCommandCancelledCallbacks)
                  )
                 )
 )
)
;
; - Notifications -------------------------------------------------------------
;
; - MeDwgSaveComplete notifications
(defun MeDwgSaveCompleteCallbacks (Rea Arg)
 (MeDoDwgSaveCompleteStuff Arg)
 (princ)
)
; - CommandWillStart notifications
(defun MeCommandWillStartCallbacks (Rea Arg)
 (MeDoCmdWillStartStuff Arg)
 (princ)
)
; - CommandEnded notifications
(defun MeCommandEndedCallbacks (Rea Arg)
 (MeDoCmdEndedStuff Arg)
 (princ)
)
; - CommandCancelled notifications
(defun MeCommandCancelledCallbacks (Rea Arg)
 (MeDoCmdCancelledStuff Arg)
 (princ)
)
; - DocToBeDestroyed notifications
(defun MeDocToBeDestroyedCallbacks (Rea Arg)
 (MeWriteToLog)
 (MeDoCloseStuff)
 (princ)
)
;
; - Subs ----------------------------------------------------------------------
;
; - DWG save complete function
(defun MeDoDwgSaveCompleteStuff (Arg)
 (setq Me:DwgNme (cadr Arg))
 (princ)
)
; - Command will start function
(defun MeDoCmdWillStartStuff (Arg)
 (setq Me:CmdTmp (getvar "MILLISECS")
       Me:CmdCnt (1+ Me:CmdCnt)
 )
 (princ)
)
; - Command ended function
(defun MeDoCmdEndedStuff (Arg / TmpVal)
 (setq TmpVal (- (getvar "MILLISECS") Me:CmdTmp)
       Me:CmdTim (if (> TmpVal (* Me:TimOut 1000)) ;User is sleeping
                  Me:CmdTim
                  (+ TmpVal Me:CmdTim)
                 )
 )
 (princ)
)
; - Command cancelled function
(defun MeDoCmdCancelledStuff (Arg / TmpVal)
 (setq TmpVal (- (getvar "MILLISECS") Me:CmdTmp)
       Me:CmdTim (if (> TmpVal (* Me:TimOut 1000)) ;User was sleeping
                  Me:CmdTim
                  (+ TmpVal Me:CmdTim)
                 )
 )
 (princ)
)
;
; - Write to log function
(defun MeWriteToLog ()
 (alert (strcat
         "Drawing name:\t\t" Me:DwgNme
         "\nTotal command time:\t" (MeCalcTime Me:CmdTim)
         "\nTotal commands called:\t" (itoa Me:CmdCnt)
        )
 )
 (princ)
)
; - Reactor cleanup function
(defun MeDoCloseStuff ( / VarLst)
 (setq VarLst (MeGetReaVars))
 (mapcar 'VLR-remove (mapcar 'eval VarLst))
 (mapcar '(lambda (l) (set l nil)) VarLst)
 (princ)
)
; - Collect global reactor variables
(defun MeGetReaVars ( / RetVal)
 (foreach memb (atoms-family 1)
  (if (wcmatch (strcase memb) "ME:REA*")
   (setq RetVal (cons memb RetVal))
  )
 )
 (mapcar 'read RetVal)
)
; - Calculate time from msecs
(defun MeCalcTime (Val / TimHrs TimMin TimSec TmpVal)
 (setq TmpVal (fix (/ Val 1000.0))
       TimSec (rem TmpVal 60)
       TmpVal (/ (- TmpVal TimSec) 60)
       TimMin (rem TmpVal 60)
       TimHrs (/ (- TmpVal TimMin) 60)
 )
 (strcat (itoa TimHrs) "h " (itoa TimMin) "m " (itoa TimSec) "s")     
)

(princ)
; == End AcadDoc.lsp ==========================================================


I hope this helps you,

Bernd