Jump to content

Fixing my record time lisp routine???


jim_archi4

Recommended Posts

Below is a lisp routine I wrote some 10 years ago. I have been out of the lisp writing for many years now and forgotten how it works. This routine extracts the time spent in a drawing. It used to work fine and was in my S::Strartup routing from memory in my Acad.lsp file, so it loaded every time a drawing was opened and recorded the time spent. Now it’s not working I haven’t used it in years but I now need to record the time spent in each drawing so I was wondering if anyone could help?

 

(reset)

Below is in the Acad.lsp but outside of the S::Startup

 

;;;*RESET

(defun RESET ()

(setq start (getvar "date"))

(setq stime (getvar "tdindwg"))

(PRINC)

)

 

;;;*DIARY

(defun diary ()

(setq x (getvar "DWGNAME"))

(SETVAR "LUPREC" 2)

(setq etime (* (- (getvar "TDINDWG") stime) 24.0))

(today)

(divi 0)

(if (

(setq jnum "*")

(getjnum)

)

(if (/= jnam nil)

(progn

(setq dia (open "c:/WPA_CAD2009/diary.ntp" "a")

hr (itoa (fix etime))

min (itoa (fix (* (- etime (fix etime)) 100)))

)

(if (and (= hr "0") (= min "0"))

(setq min "01")

)

(setq wline (strcat "Job: " jnum " " day

"-" mo "-" yr

" File: " jnam " Time: "

hr ":" min " "

)

)

(write-line wline dia)

(close dia)

)

)

(reset)

(SETVAR "LUPREC" 0)

(princ)

)

(defun getjnum ()

(setq divt div)

(divi (- divt 1))

(setq n1 (1+ dinum))

(divi divt)

(setq n2 dinum)

(setq jnum (substr x n1 (- n2 n1))

jnam (substr x (1+ n2))

)

)

(defun divi (test)

(setq i 1

div 0

)

(repeat (- (strlen x) 1)

(if (= (substr x i 1) (chr 92))

(progn (setq div (1+ div))

(if (and (/= test 0) (= div test))

(setq dinum i)

)

)

)

(setq i (1+ i))

)

)

 

;;;*TODAY

(defun today (/ d)

(setq d (rtos (getvar "cdate") 2 6)

yr (substr d 3 2)

mo (substr d 5 2)

day (substr d 7 2)

)

(strcat day "." mo "." yr)

)

 

In another routine I had my own open diagalog using the “Mgetfile” command and in that I planted the Diary and Reset comands see below; since the use of multiple drawing sessions this has not worked properly so I just use the AutoCad open. Now I need to use the diary to record the time again so if anyone can help I would appreciate it. Im just happy to use the standard Acad Open but redefined to run my (diary) and (RESET) before hand.

 

(defun do_open ()

(print)

(princ "\nSelect file to open...")

(print)

(setq nm (car (mgetfiled "wpa_cad - File Manager"

(getvar "dwgprefix")

"dwg"

12

)

)

)

(print)

(print)

(if (/= nm (getvar "DWGNAME"))

(progn

(diary)

(RESET)

(command ".OPEN" nmm nm)

(setvar "cmdecho" cmd)

(princ)

)

)

)

Link to comment
Share on other sites

Below is a lisp routine I wrote some 10 years ago. I have been out of the lisp writing for many years now and forgotten how it works. This routine extracts the time spent in a drawing. It used to work fine and was in my S::Strartup routing from memory in my Acad.lsp file, so it loaded every time a drawing was opened and recorded the time spent. Now it’s not working I haven’t used it in years but I now need to record the time spent in each drawing so I was wondering if anyone could help?

 

 

(reset)

 

Below is in the Acad.lsp but outside of the S::Startup

 

;;;*RESET

(defun RESET ()

(setq start (getvar "date"))

(setq stime (getvar "tdindwg"))

(PRINC)

)

 

;;;*DIARY

(defun diary ()

(setq x (getvar "DWGNAME"))

(SETVAR "LUPREC" 2)

(setq etime (* (- (getvar "TDINDWG") stime) 24.0))

(today)

(divi 0)

(if (

(setq jnum "*")

(getjnum)

)

(if (/= jnam nil)

(progn

(setq dia (open "c:/WPA_CAD2009/diary.ntp" "a")

hr (itoa (fix etime))

min (itoa (fix (* (- etime (fix etime)) 100)))

)

(if (and (= hr "0") (= min "0"))

(setq min "01")

)

(setq wline (strcat "Job: " jnum " " day

"-" mo "-" yr

" File: " jnam " Time: "

hr ":" min " "

)

)

(write-line wline dia)

(close dia)

)

)

(reset)

(SETVAR "LUPREC" 0)

(princ)

)

(defun getjnum ()

(setq divt div)

(divi (- divt 1))

(setq n1 (1+ dinum))

(divi divt)

(setq n2 dinum)

(setq jnum (substr x n1 (- n2 n1))

jnam (substr x (1+ n2))

)

)

(defun divi (test)

(setq i 1

div 0

)

(repeat (- (strlen x) 1)

(if (= (substr x i 1) (chr 92))

(progn (setq div (1+ div))

(if (and (/= test 0) (= div test))

(setq dinum i)

)

)

)

(setq i (1+ i))

)

)

 

;;;*TODAY

(defun today (/ d)

(setq d (rtos (getvar "cdate") 2 6)

yr (substr d 3 2)

mo (substr d 5 2)

day (substr d 7 2)

)

(strcat day "." mo "." yr)

)

 

In another routine I had my own open diagalog using the “Mgetfile” command and in that I planted the Diary and Reset comands see below; since the use of multiple drawing sessions this has not worked properly so I just use the AutoCad open. Now I need to use the diary to record the time again so if anyone can help I would appreciate it. Im just happy to use the standard Acad Open but redefined to run my (diary) and (RESET) before hand.

 

(defun do_open ()

(print)

(princ "\nSelect file to open...")

(print)

(setq nm (car (mgetfiled "wpa_cad - File Manager"

(getvar "dwgprefix")

"dwg"

12

)

)

)

(print)

(print)

(if (/= nm (getvar "DWGNAME"))

(progn

(diary)

(RESET)

(command ".OPEN" nmm nm)

(setvar "cmdecho" cmd)

(princ)

)

)

)

Link to comment
Share on other sites

I suggest you look up "Special Handling of Date/Time Variables" and "edtime"

Example:

instead of

(defun today (/ d)
 (setq d   (rtos (getvar "cdate") 2 6)
yr  (substr d 3 2)
mo  (substr d 5 2)
day (substr d 7 2)
 )
 (strcat day "." mo "." yr)
)

 

try:

 

 
(menucmd "M=$(edtime,$(getvar,date),DD.MO.YY)")

 

Question for you:

Do you want to maintain your code and would you rather re-write and learn new stuff?

Is it a pressing issue that you just need to run the code for now?

 

The way I see it, if you want to trigger the "diary" it would be better to use reactors

Edited by pBe
Link to comment
Share on other sites

Hi pBe,

 

Thanks for the code...

Well I need to maintain my code for new vewrsions of Autocad, some code is deleted as usually the next version of AutoCAD has added it, but I'm always up for learning a new way to do things.

 

The only reason I had my (diary) subroutine in just before opening a drawing was it was the last thing for that open command and it was fairly accurate.

 

Tell me about reactors??? I'm very curious

 

BTW I got my (diary) routine to work using your test4u many thanks. I needed to only change (setq x (getvar "DWGNAME"))

to (setq x (stracat (Getvar "Dwgprefix") (Getvar "Dwgname"))

)

)

now it sings like a canary, many thanks again

Link to comment
Share on other sites

Hi pBe,

 

Determined to get this to work I did some research on recators and found them very interesting. I tried some examples and they work fine...however I wrote this and it's failing missrealbly....:( I get Error: too many arguments

 

(vl-load-com)

 

;**************************************************************

 

;setup and intilise the reactor

(vlr-dwg-reactor "Record Data" '((:vlr-beginDwgOpen . recordmydata)))

 

;**************************************************************

 

(defun recordmydata ( )

 

(diary)

(princ)

 

);defun

 

I have also tried these below with similar errors too many or too few arguments

:vlr-saveComplete

:vlr-endDwgOpen

:vlr-dwgFileOpened

:vlr-endDwgOpen

 

Also I would need to think of the last drawing I open as it will not record the data until another drawing is opened so I may need to also look at having a reactor when I save or end the drawing to pick up that data, maybe a save might best as I can determine if I need to record it myself eg:. a drawing left open and not worked on would not need recording.

 

Running the (recordmydata) from the command line works fine, I think the error is in the reactor code as it doesn't seem to call my (recordmydata) subroutine. I even tried renaming (recordmydata) to just (diary) as its loded in the Acad.lsp file every time a drawing is open (ACADLSPASDOC is set to 1) but still no luck.

 

Thanks for introducing me to Reactors they're cool I can see a use in them for a few things

 

Any ways if you can help I would appreciate it very much!!!!!...

Link to comment
Share on other sites

I tried some examples and they work fine...however I wrote this and it's failing missrealbly....:( I get Error: too many arguments

 

The callback function requires two arguments

 

(defun recordmydata ( arg1 arg2 ).....

 

 

Sample for you:

(if (and Record (vlr-added-p Record))
(vlr-remove Record)
)
(setq Record
      (vlr-dwg-reactor
 "Start Recording This" '((:vlr-beginSave . AskedToRecord)

 )
      )
     )
(defun AskedToRecord (Triggered Thiscommand)
  (initget 1 "Y N")
   (setq ans (getkword "\nRecord this session [Yes/No]: "))
(if (eq ans "Y")
   (princ "\nSaving data....")
   (princ "\nData ignored....")
  )
 )

 

You will notice that the snippet i posted uses "save" reactors, wherein you can control if the file needs to be recorded or not.

On a beginDwgOpen reactor i would suggest you include a condtion if the file opened is a "vald document" like for example a standard drawing prefix i.e. "ProjectCode_*" only then will the "diary" be activated.

 

 

Also I would need to think of the last drawing I open as it will not record the data until another drawing is opened so I may need to also look at having a reactor when I save or end the drawing to pick up that data, maybe a save might best as I can determine if I need to record it myself eg:. a drawing left open and not worked on would not need recording.

 

Good point, that is why SDI is important, that way you wont leave an opened drawing hanging without activity. you will be forced to close the file and be prompted to record right then and there.

 

On the other hand, you can maintian MDI and you could add a "pause" routine wherein the time elapsed will be frozen until you hit "play" button.

 

EDIT:

Click Here to learn more about edtime/menucmd

Edited by pBe
Link to comment
Share on other sites

Hi pBe,

 

 

I wrote this after some research on Reactors, it works a treat, but I don't know how to add the 2 close/quit option's (clicking the 'X'). When I click the 'X' (close drawing) I get the option to save or not save the data, when I don't save it for example the drawing is not being worked on but just open for reference. When I want to save it, I click "yes" and the drawing is saved but the data is still now saved? Is there a close_save and close_nosave set of commands? Or what save does the close comand use? How do I distinguish between the 2 options with commands?

 

My code:

[/code]

(vl-load-com)

 

;**************************************************************

 

;setup and intilise the reactor

(vlr-command-reactor

nil '((:vlr-commandWillStart . recordmydata)))

 

;**************************************************************

 

(defun recordmydata (calling-reactor startcommandInfo /

thecommandstart)

(setq thecommandstart (nth 0 startcommandInfo))

;;;setup the condition for open or end

(cond

((= thecommandstart "OPEN") (diary))

((= thecommandstart "END") (diary))

((= thecommandstart "SAVE") (diary))

((= thecommandstart "QSAVE") (diary))

((= thecommandstart "QUIT") (diary))

 

);cond

(princ)

 

);defun

[/code]

 

What do you think? Any suggestions on how to include the close/quit??

Link to comment
Share on other sites

Lets analyze this statement Jim

 

.....When I click the 'X' (close drawing) I get the option to save or not save the data, when I don't save it for example the drawing is not being worked on but just open for reference....

 

If you need to open a file for "reference" open it as read only.

remind them that everytime a drawing is saved, it will count on editing time.

 

What you need to do is to add a conditon test on you "diary" routine dont start recording if the file is read only

 

(if
 (eq (vla-get-readonly
(vla-get-ActiveDocument (vlax-get-acad-object))
     )
     :vlax-false
 )
  (princ "\nRecord routine activated...")
  (princ "\nRecord routine De-activated...")
)

 

... When I want to save it, I click "yes" and the drawing is saved but the data is still now saved?....

 

Why would you want to save the file if its open for reference. if modification needs to be done on that drawing it will still count as "editing" time,

otherwise why save it at all?

 

((= thecommandstart "OPEN") (diary))

 

Believe me, I've been down that road before Jim. programs are only as good as the user could be.

 

BTW did you look into the link I posted above for edtime function? I strongly suggest re-writing you "diary" routine to account for every possible condtion. I could write one for you but where's the fun in that? , besides who better understand what needs to be done other than you Jim :)

 

You can heed my suggestions and start writing the code, if you hit a snag just holler

 

Cheers

Edited by pBe
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...