TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: HasanCAD on May 30, 2012, 05:01:15 AM

Title: How to run a lisp when close file ?
Post by: HasanCAD on May 30, 2012, 05:01:15 AM
Hi all

I started this lisp but need some help

Usage of lisp:
To create the file history
Search for a text start with "Save Date *"
if yes find the last one and insert new text under the last one
if no alert the user to pick a point to insert new text

Questions:
Q1: How to run this lisp when close the file?
Q2: In if condition How to search for a text start with "Save Date *" and if there more than one select the last to insert the new text under it ?

The code
Code: [Select]
(defun c:FileHistory (/)
      ;Get time and date
      ;Afralisp
  (setq d (rtos (getvar "CDATE") 2 6)
yr (substr d 1 4) ;extract the year
        mo (substr d 5 2) ;extract the month
        dy (substr d 7 2) ;extract the day
hr (substr d 10 2);extract the hour
        m  (substr d 12 2);extract the minute
Sdate (strcat "Save Date: "(strcat dy "/" mo "/" yr))
Stime (strcat " Time: "(strcat hr ":" m ))
SUser (strcat " User: "(getvar "loginname"))
SStr (strcat Sdate Stime SUser)
)
 
  (if ()
    (progn
      (setq Tpt )
      (maketext SStr Tpt 4000)
      )
    (Progn
      (alert (strcat "Pick a point to Insert file history"))
      (setq Tpt (getpoint))
      (maketext SStr Tpt 4000)
   )))
(defun maketext (str pt ht )
  (entmakex (list (cons 0 "TEXT") ;***
  (cons 1 str) ;* (the string itself)
  (cons 6 "BYLAYER") ; Linetype name
  (cons 7 (getvar "TEXTSTYLE")) ;* Text style name, defaults to STANDARD, current
  (cons 8 (getvar "CLAYER")) ; layer
  (cons 10 pt) ;* First alignment point (in OCS)
  (cons 11 pt) ;* Second alignment point (in OCS)
  (cons 39 0.0) ; Thickness (optional; default = 0)
  (cons 40 ht) ;* Text height
  (cons 41 0.8) ; Relative X scale factor, Width Factor, defaults to 1.0
  (cons 51 0.0) ; Oblique angle
  (cons 62 256) ; color
  (cons 71 0) ; Text generation flags
  (cons 72 0) ; Horizontal text justification type
  (cons 73 1) ; Vertical text justification type
  (cons 210 (list 0.0 0.0 1.0))
    )  ))
Title: Re: How to run a lisp when close file ?
Post by: HasanCAD on May 30, 2012, 08:04:00 AM
This is a try
Code: [Select]
(defun c:FileHistory (/)

;Get time and date
;Afralisp
  (setq d (rtos (getvar "CDATE") 2 6))
  (setq yr (substr d 1 4)) ;extract the year
  (setq mo (substr d 5 2)) ;extract the month
  (setq dy (substr d 7 2)) ;extract the day
  (setq hr (substr d 10 2)) ;extract the hour
  (setq m (substr d 12 2)) ;extract the minute
  (setq Sdate (strcat "Save Date: " (strcat dy "/" mo "/" yr)))
  (setq Stime (strcat " Time: " (strcat hr ":" m)))
  (setq SUser (strcat " User: " (getvar "loginname")))

  (setq SStr (strcat Sdate Stime SUser))
  (setq sset (ssget "_X" '((0 . "Text") (1 . "Save Date:*"))))
  (setq ss (ssname sset 0))
  (setq dxfdata (entget ss))
  (setq old-dxf (assoc 10 dxfdata))
  (setq y1 (nth 2 old-dxf))

  (if (> (sslength sset) 0)
    (progn
      (repeat (setq inc (sslength sset))
(setq ss (ssname sset (setq inc (1- inc))))
(setq dxfdata (entget ss))
(setq old-dxf (assoc 10 dxfdata))
(setq x (nth 1 old-dxf))
(setq y (nth 2 old-dxf))
(if (> y1 y)
  (setq y2 y) ;T
  (setq y2 y1) ;not
)
      )
      (setq Tpt (list x y))
      (maketext SStr Tpt 4000)
    )
    (Progn
      (alert (strcat "Pick a point to Insert file history"))
      (setq Tpt (getpoint))
      (maketext SStr Tpt 4000)
    )
  )
)
Title: Re: How to run a lisp when close file ?
Post by: Coder on May 30, 2012, 09:31:32 AM

Code: [Select]
 
  (if (???????????)
    (progn
      (setq Tpt ??????? )
      (maketext SStr Tpt 4000)
      )
   

Some missing variables  :-D
Title: Re: How to run a lisp when close file ?
Post by: pBe on May 30, 2012, 09:32:38 AM
Code - Auto/Visual Lisp: [Select]
  1. (defun C:Mark ( / Text Cstr low lowpt strs i e data pts inspt)
  2. (vl-load-com)      
  3. (defun Text (lay pt hgt sty str rot wd)
  4.   (entmakex (list (cons 0 "TEXT")
  5.                   (cons 1 str)
  6.                   (cons 8 lay)
  7.                   (cons 7 sty)
  8.                   (cons 10  pt)
  9.                   (cons 40 hgt)
  10.                   (cons 41 wd)
  11.                   (cons 1  str))))
  12. (setq Cstr (apply 'strcat
  13.        (mapcar  '(lambda (k)  (strcat (car k)
  14.        (menucmd (strcat "m=$(edtime,$(getvar,DATE),"
  15.                 (eval (cadr k)) ")"))))
  16.              '(("Save Date: " "")
  17.                ("" "MO/DD/YYYY ")
  18.                ("Time: " "HH:MMam/pm ")
  19.                ("User: " (getvar "loginname"))))))      
  20. (if (setq low nil pts nil
  21.           strs (ssget "_X" '((0 . "TEXT")(1 . "Save Date:*"))))
  22.     (progn
  23.     (repeat (setq i (sslength strs))
  24.           (setq e (entget (ssname strs (setq i (1- i)))))
  25.           (if (or (< (cadr (setq pt (cdr (assoc 10 e)))) low)
  26.                   (null low))
  27.                 (progn
  28.                       (setq data (append
  29.                                        (mapcar
  30.                                              'cdr
  31.                                              (vl-remove-if-not
  32.                                                    '(lambda (k)
  33.                                                           (vl-position
  34.                                                                 (car k)
  35.                                                                 '(8 40 50 41 7)))
  36.                                                    e))
  37.                                        (list pt))
  38.                             low  (cadr pt))))
  39.           (setq pts (cons pt pts))
  40.           )
  41.     (setq lowpt (last data))
  42.     (setq inspt
  43.                (list (car lowpt)
  44.                      (- low
  45.                         (if (cadr pts)
  46.                               (apply
  47.                                     'min
  48.                                     (mapcar '(lambda (k l)
  49.                                                    (distance
  50.                                                          k
  51.                                                          l))
  52.                                             pts
  53.                                             (cdr pts)))
  54.                               8000))
  55.                      (last lowpt)))
  56.     (Text (car data) inspt (cadr data)(nth 4 data) Cstr (caddr data) (nth 3 data))
  57.     )
  58.           (if (setq inspt
  59.                          (getpoint
  60.                                "\nPick point to insert file history"))
  61.                 (Text (getvar 'Clayer)
  62.                       inspt
  63.                       4000
  64.                       (getvar 'Textstyle)
  65.                       Cstr
  66.                       0.0
  67.                       1.0)
  68.                 )
  69.     )
  70.       )

Questions:
Q1: How to run this lisp when close the file?

I guess the best way to do that is via reactor

Title: Re: How to run a lisp when close file ?
Post by: HasanCAD on May 30, 2012, 09:37:07 AM
Thanks pBe
this is mine
Code: [Select]
(defun c:FileHistory (/      d     yr    mo   dy hr m
      sdate  stime  suser  sstr   sset ss dxfdata
      dxf    y1     old-dxf   dxfdata x
      y      y1     y2
     )
  (and
;Get time and date
;Afralisp
    (setq d (rtos (getvar "CDATE") 2 6))
    (setq yr (substr d 1 4)) ;extract the year
    (setq mo (substr d 5 2)) ;extract the month
    (setq dy (substr d 7 2)) ;extract the day
    (setq hr (substr d 10 2)) ;extract the hour
    (setq m (substr d 12 2)) ;extract the minute
    (setq Sdate (strcat "Save Date: " (strcat dy "/" mo "/" yr)))
    (setq Stime (strcat " Time: " (strcat hr ":" m)))
    (setq SUser (strcat " User: " (getvar "loginname")))
    (setq SStr (strcat Sdate Stime SUser))
    (setq ssetL (ssget "_X" '((0 . "Text") (1 . "Save Date:*"))))
    (setq sset (if ssetl
(sslength ssetL)
(setq sset 0)
       )
    )
  )

  (if (> sset 0)
    (progn
      (setq ss (ssname ssetL 0))
      (setq dxfdata (entget ss))
      (setq dxf (assoc 10 dxfdata))
      (setq y1 (nth 2 dxf))
    )
  )
;OK

  (if (> sset 0)
    (progn
      (repeat (setq inc sset)
(setq ss (ssname ssetL (setq inc (1- inc))))
(setq dxfdata1 (entget ss))
(setq old-dxf (assoc 10 dxfdata1))
(setq x (nth 1 old-dxf))
(setq y (nth 2 old-dxf))
(if (> y1 y)
  (setq y2 y) ;T
  (setq y2 y1) ;not
)
      )
      (setq Tpt (list x (- y 6000)))
      (maketext SStr Tpt 4000)
    )
    (Progn
      (alert (strcat "Pick a point to Insert file history"))
      (setq Tpt (getpoint))
      (maketext SStr Tpt 4000)
    )
  )
) ;defun

(defun maketext (str pt ht)
  (entmakex (list (cons 0 "TEXT") ;***
  (cons 1 str) ;* (the string itself)
  (cons 6 "BYLAYER") ; Linetype name
  (cons 7 (getvar "TEXTSTYLE"))
;* Text style name, defaults to STANDARD, current
  (cons 8 (getvar "CLAYER")) ; layer
  (cons 10 pt) ;* First alignment point (in OCS)
  (cons 11 pt) ;* Second alignment point (in OCS)
  (cons 39 0.0) ; Thickness (optional; default = 0)
  (cons 40 ht) ;* Text height
  (cons 41 0.8) ; Relative X scale factor, Width Factor, defaults to 1.0
  (cons 51 0.0) ; Oblique angle
  (cons 62 256) ; color
  (cons 71 0) ; Text generation flags
  (cons 72 0) ; Horizontal text justification type
  (cons 73 1) ; Vertical text justification type
  (cons 210 (list 0.0 0.0 1.0))
    )
  )
)
Title: Re: How to run a lisp when close file ?
Post by: HasanCAD on May 30, 2012, 09:48:06 AM
Thanks pBe I'll study yours

I guess the best way to do that is via reactor
How is this?
I do not know whats reactor.
Title: Re: How to run a lisp when close file ?
Post by: irneb on May 30, 2012, 11:40:22 AM
http://docs.autodesk.com/ACD/2011/ENU/filesALG/WS73099cc142f4875516d84be10ebc87a53f-7c34.htm

and

http://docs.autodesk.com/ACD/2011/ENU/filesALR/WS1a9193826455f5ff1a32d8d10ebc6b7ccc-67b0.htm

Title: Re: How to run a lisp when close file ?
Post by: pBe on May 30, 2012, 11:44:08 AM
Also from the same website you used for reference on you code:

http://www.afralisp.net/visual-lisp/tutorials/reactors-part-1.php


Title: Re: How to run a lisp when close file ?
Post by: HasanCAD on May 30, 2012, 12:04:12 PM
Thanks irneb
Thanks pBe I'll study your lisp and I am sure that its great lisp
Title: Re: How to run a lisp when close file ?
Post by: irneb on May 30, 2012, 01:35:24 PM
Glad to help, though I fear we've led you to the dark side. If you think you've made errors before, wait till you've made an error in reactors  :lmao: ... they're DANGEROUS beyond belief!
Title: Re: How to run a lisp when close file ?
Post by: kruuger on May 30, 2012, 05:38:16 PM
Thanks pBe I'll study yours

I guess the best way to do that is via reactor
How is this?
I do not know whats reactor.
Code - Auto/Visual Lisp: [Select]
  1. (Defun AtSaveCommand (calling-reactor b)
  2.   (if
  3.     (or
  4.       (= (car b) "QSAVE")
  5.       (= (car b) "SAVEAS")
  6.       (= (car b) "SAVE")
  7.     )
  8.     (C:SLOWNIK)
  9.   )
  10. )
  11.  
  12. (Defun loadTheSaveReactor ()
  13.   (if *FileOnSave* (vlr-remove *FileOnSave*))
  14.   (setq *FileOnSave* (vlr-command-reactor nil '((:vlr-commandwillStart . AtSaveCommand))))
  15. )
  16.  
  17. (loadTheSaveReactor)
i'm using this when someone save the drawing. works very well.
easy to modify to CLOSE.
kruuger
Title: Re: How to run a lisp when close file ?
Post by: pBe on May 30, 2012, 11:44:01 PM
Glad to help, though I fear we've led you to the dark side. If you think you've made errors before, wait till you've made an error in reactors  :lmao: ... they're DANGEROUS beyond belief!

So true.. Dangerous reactor is.

@hasanCAD/kruuger

Think about this. what are the conditions as when to trigger the lisp routine? Every time the user invoke a save* command? in the event the user saves the file and continues working on the file?
after a while the user click save again, then that will be two Filehistory lines. You may need to use a counter within the lisp code to determine that it ran at least once, then it should the repalce the string rather than writing a new line.

_close reator is indeed the way to go
Title: Re: How to run a lisp when close file ?
Post by: HasanCAD on May 31, 2012, 03:04:30 AM
Glad to help, though I fear we've led you to the dark side. If you think you've made errors before, wait till you've made an error in reactors  :lmao: ... they're DANGEROUS beyond belief!

Welcome mr. Angel 
Title: Re: How to run a lisp when close file ?
Post by: HasanCAD on May 31, 2012, 03:07:42 AM
Glad to help, though I fear we've led you to the dark side. If you think you've made errors before, wait till you've made an error in reactors  :lmao: ... they're DANGEROUS beyond belief!

So true.. Dangerous reactor is.

@hasanCAD/kruuger

Think about this. what are the conditions as when to trigger the lisp routine? Every time the user invoke a save* command? in the event the user saves the file and continues working on the file?
after a while the user click save again, then that will be two Filehistory lines. You may need to use a counter within the lisp code to determine that it ran at least once, then it should the repalce the string rather than writing a new line.

_close reator is indeed the way to go

Yes That is correct.
Title: Re: How to run a lisp when close file ?
Post by: irneb on May 31, 2012, 03:22:09 AM
Another thing to "worry" about, sometimes while the file is "closing" ... it might be impossible to modify anything inside the file. That's usually why the "command will start" reactor is usually better to use. If you use a :vlr-beginClose reactor, it might fail, especially if the user clicks Cancel when asked to save changes. Also you might need to undo the save on a :vlr-commandCanceled / :vlr-commandFailed reactor.

Reactors, dangerous they are ... you find all sorts of "disturbances in the force" which you never thought would happen.

I also think it might be a better idea to have the log saved as a text file in the same folder as the DWG with the same filename. That way it might alleviate any non-modifyable issues. Perhaps save it in CSV format, then you could link to it as if it's an Excel sheet and have a auto-updating table if you really want it displayed inside the DWG. Then you might even use the :vlr-databaseToBeDestroyed since you're not going to modify the DWG database at all.
Title: Re: How to run a lisp when close file ?
Post by: kruuger on May 31, 2012, 04:26:02 AM
Glad to help, though I fear we've led you to the dark side. If you think you've made errors before, wait till you've made an error in reactors  :lmao: ... they're DANGEROUS beyond belief!

So true.. Dangerous reactor is.

@hasanCAD/kruuger

Think about this. what are the conditions as when to trigger the lisp routine? Every time the user invoke a save* command? in the event the user saves the file and continues working on the file?
after a while the user click save again, then that will be two Filehistory lines. You may need to use a counter within the lisp code to determine that it ran at least once, then it should the repalce the string rather than writing a new line.

_close reator is indeed the way to go
i'm using this reactor to save info about user who modify the file.
after few days of work i have nice history in DICTIONARY
of course i can review with separate program
this is what you want HasanCAD ?
kruuger
Title: Re: How to run a lisp when close file ?
Post by: Coder on May 31, 2012, 04:41:26 AM
Why not include command CLOSE at the bottom of the routine and exclude using reactors .... :pissed:
Title: Re: How to run a lisp when close file ?
Post by: kruuger on May 31, 2012, 04:45:43 AM
Why not include command CLOSE at the bottom of the routine and exclude using reactors .... :pissed:
and how to run program to save history on close without reactor ?
kruuger
Title: Re: How to run a lisp when close file ?
Post by: irneb on May 31, 2012, 04:54:48 AM
You could undefine the close command, then your defun would be named c:close and inside it you call "._CLOSE" to run the "undefined" command.

Or use the vla-Close on the current document rather. Also you might then have to implement some sort of "Do you want to save changes" dialog. Personally I agree with this idea more, there's less to go wrong, and you've got more control over what's happening.
Title: Re: How to run a lisp when close file ?
Post by: kruuger on May 31, 2012, 05:10:59 AM
You could undefine the close command, then your defun would be named c:close and inside it you call "._CLOSE" to run the "undefined" command.

Or use the vla-Close on the current document rather. Also you might then have to implement some sort of "Do you want to save changes" dialog. Personally I agree with this idea more, there's less to go wrong, and you've got more control over what's happening.
probably should work. i don't know how close reactor but save works very well. i;m working with this routine over 2 years with 40 people.
there was not a single problem. history are always in drawings
kruuger
Title: Re: How to run a lisp when close file ?
Post by: Coder on May 31, 2012, 06:24:47 AM

and how to run program to save history on close without reactor ?
kruuger

I mean when the user run the code , the text would be created and the command close would close the drawing .
Title: Re: How to run a lisp when close file ?
Post by: HasanCAD on May 31, 2012, 07:18:48 AM
...
this is what you want HasanCAD ?
kruuger
YES this is what I want
Title: Re: How to run a lisp when close file ?
Post by: pBe on May 31, 2012, 09:44:52 AM

after few days of work i have nice history in DICTIONARY
kruuger

Nice idea,
Will that be separate Dictionary for each drawing file on an external file? does it keep a record on the drawing itself?
Title: Re: How to run a lisp when close file ?
Post by: BlackBox on May 31, 2012, 10:11:28 AM
Thanks pBe I'll study yours

I guess the best way to do that is via reactor
How is this?
I do not know whats reactor.
Code - Auto/Visual Lisp: [Select]
  1. (Defun AtSaveCommand (calling-reactor b)
  2.   (if
  3.     (or
  4.       (= (car b) "QSAVE")
  5.       (= (car b) "SAVEAS")
  6.       (= (car b) "SAVE")
  7.     )
  8.     (C:SLOWNIK)
  9.   )
  10. )
  11.  
  12. (Defun loadTheSaveReactor ()
  13.   (if *FileOnSave* (vlr-remove *FileOnSave*))
  14.   (setq *FileOnSave* (vlr-command-reactor nil '((:vlr-commandwillStart . AtSaveCommand))))
  15. )
  16.  
  17. (loadTheSaveReactor)
i'm using this when someone save the drawing. works very well.
easy to modify to CLOSE.
kruuger

FWIW - I've always preferred the OR function when calls may be made more than once within a Defun (I've also used Cond as needed):

Code - Auto/Visual Lisp: [Select]
  1.  
  2.  
  3.  
  4. ;;;--------------------------------------------------------------------;
  5. ;;; Reactors:Start function
  6. (defun Reactors:Start  ()
  7.  
  8.   ;; Command reactors
  9.   (or *Reactors_Command*
  10.       (setq *Reactors_Command*
  11.              (vlr-command-reactor
  12.                nil
  13.                '((:vlr-commandCancelled . Callback:CommandEnded)
  14.                  (:vlr-commandEnded . Callback:CommandEnded)
  15.                  (:vlr-commandFailed . Callback:CommandEnded)
  16.                  (:vlr-commandWillStart . Callback:CommandWillStart)))))
  17.  
  18.   ;; <- Other reactors (i.e., AcDb, DocManager, Editor, Object, etc.
  19.  
  20.   (prompt "\n \n  >>  Reactors Loaded ")
  21.   (princ))
  22. ;;;--------------------------------------------------------------------;
  23. ;;; Callback:CommandEnded function
  24. (defun Callback:CommandEnded  (rea cmd / cmdName)
  25.   (cond
  26.     ((wcmatch (setq cmdName (car cmd))
  27.               "COPY,GRIP_STRETCH,MOVE,SCALE,STRETCH")                   ; Cursorsize
  28.      (progn
  29.        (setvar 'cursorsize *Reactor_CursorSize*)
  30.        (setq *Reactor_CursorSize* nil)))
  31.  
  32.     ((wcmatch (setq cmdName (car cmd)) "**SAVE*")                       ; Save
  33.      (c:SlowNik))
  34.  
  35.     ((and capslock
  36.           (wcmatch cmdName
  37.                    "BLOCK,*EDIT*,*TEXT*,*LAYERSTATE*,*LEADER*"))        ; Text edits
  38.  
  39.      ;; Restore original capslock setting
  40.      (capslock *Reactor_CapsLock*)
  41.      (setq *Reactor_CapsLock* nil))
  42.  
  43.     ;; <- Other commands
  44.  
  45.     ))
  46. ;;;--------------------------------------------------------------------;
  47. ;;; Callback:CommandWillStart function
  48. (defun Callback:CommandWillStart  (rea cmd / cmdName)
  49.   (cond ((wcmatch (setq cmdName (car cmd))
  50.                   "COPY,GRIP_STRETCH,MOVE,SCALE,STRETCH")               ; Cursorsize
  51.          (progn
  52.            (setq *Reactor_CursorSize* (getvar 'cursorsize))
  53.            (setvar 'cursorsize 100)))
  54.  
  55.         ((wcmatch cmdName "**SAVE*")                                    ; Save
  56.          (c:SlowNik))
  57.  
  58.         ((and capslock
  59.               (wcmatch cmdName
  60.                        "*BLOCK,*EDIT*,*TEXT*,*LAYERSTATE*,*LEADER*"))   ; Text edits
  61.  
  62.          ;; Store original capslock setting, and turn capslock on
  63.          (setq *Reactor_CapsLock* (capslock))
  64.          (capslock T))
  65.  
  66.         ;; <- Other commands
  67.  
  68.         ))
  69. ;;;--------------------------------------------------------------------;
  70. (Reactors:Start)
  71.  

... A few extra goodies are included, free of charge. LoL :kewl:
Title: Re: How to run a lisp when close file ?
Post by: kruuger on May 31, 2012, 06:35:18 PM

after few days of work i have nice history in DICTIONARY
kruuger

Nice idea,
Will that be separate Dictionary for each drawing file on an external file? does it keep a record on the drawing itself?
i store user info only in drawing:
Code - Auto/Visual Lisp: [Select]
  1. UserHistory [under named object dictionary]
  2. |
  3. |---Item_1 (xrecord)
  4. |---Item_2 (xrecord)
  5. |---Item_3 (xrecord)
but this can be very easy save to file

...
this is what you want HasanCAD ?
kruuger
YES this is what I want
please find attached files and make a test.
the coding is TERRIBLE. maybe it is time to rewrite this mess  :|
load all files. after save command type AUTOR to see the dwg log.
k.
Title: Re: How to run a lisp when close file ?
Post by: HasanCAD on June 03, 2012, 03:37:47 AM
...
A few extra goodies are included, free of charge. LoL :kewl:

I like every think if is free  :-D
Title: Re: How to run a lisp when close file ?
Post by: HasanCAD on June 03, 2012, 03:56:58 AM
...
the coding is TERRIBLE. maybe it is time to rewrite this mess  :|
...
YES it is

You know when I read these 2 replies
http://docs.autodesk.com/ACD/2011/ENU/filesALG/WS73099cc142f4875516d84be10ebc87a53f-7c34.htm
and
http://docs.autodesk.com/ACD/2011/ENU/filesALR/WS1a9193826455f5ff1a32d8d10ebc6b7ccc-67b0.htm
and
Also from the same website you used for reference on you code:
http://www.afralisp.net/visual-lisp/tutorials/reactors-part-1.php

My feeling was that both of us on a boat and you pushed me in the sea and said " teach yourself the swimming"
Title: Re: How to run a lisp when close file ?
Post by: HasanCAD on June 03, 2012, 04:43:45 AM
...
please find attached files and make a test.
...
That perfect

but when open, save and close the file gives me one line in history
Title: Re: How to run a lisp when close file ?
Post by: kruuger on June 03, 2012, 06:59:03 PM
...
please find attached files and make a test.
...
That perfect

but when open, save and close the file gives me one line in history
if one person is working on file, there is only one line per day. each save replace only time.
when someone else save the dwg program add them to history.
if file back to you program will "catch you" again.
is this clear ?

rewritten AUTOR.LSP to LOG.LSP (new shortcut LOG)
added option to sort columns.
dcl file is created on the fly (Save login.dcl not required)

kruuger
Title: Re: How to run a lisp when close file ?
Post by: BlackBox on June 03, 2012, 08:28:41 PM
What is to prevent the user from opening the drawing, and doing nothing for several hours and saving the drawing (effectively producing nothing). Won't their time still be logged?

Perhaps it would be prudent to incorporate a Sysvar Reactor that monitors Cmdactive, and when commands are not active, the timer is prgramatically stopped. Just a thought, as this thread somewhat reminds me an AUGI thread about CadTempo.
Title: Re: How to run a lisp when close file ?
Post by: kruuger on June 04, 2012, 01:20:53 AM
What is to prevent the user from opening the drawing, and doing nothing for several hours and saving the drawing (effectively producing nothing). Won't their time still be logged?

Perhaps it would be prudent to incorporate a Sysvar Reactor that monitors Cmdactive, and when commands are not active, the timer is prgramatically stopped. Just a thought, as this thread somewhat reminds me an AUGI thread about CadTempo.
program is not used for monitoring work. purpose is to easy track person who modify the drawing.
we can get him and point out that something was wrong in drawing.
kruuger
Title: Re: How to run a lisp when close file ?
Post by: BlackBox on June 04, 2012, 10:13:14 AM

program is not used for monitoring work. purpose is to easy track person who modify the drawing.
kruuger

I would argue that one is dependent on the other.

Without the context of knowing what modification(s) have occurred, one cannot possibly know which user(s) is(are) responsible.

Again, were a user to open a drawing, draw a line, delete the line just drawn, then save the drawing (effectively doing nothing)... That user would be logged.

Title: Re: How to run a lisp when close file ?
Post by: dgorsman on June 04, 2012, 10:23:24 AM
A long time ago, I was in the same boat.  The piping lead asked me to print off a stack of drawings.  A few days later he comes back and asks "Why was this changed?"  "This shouldn't look like this" and so on, pointing to my name on an automated datestamp on the prints.  I had to repeated point out to him that the log (datestamp on drawing in this case) was only changed when the drawing was printed and I had *never* worked on the drawings.

The moral of the story: tracking logs don't always say what you think they are saying.
Title: Re: How to run a lisp when close file ?
Post by: kruuger on June 04, 2012, 10:52:28 AM

program is not used for monitoring work. purpose is to easy track person who modify the drawing.
kruuger

I would argue that one is dependent on the other.

Without the context of knowing what modification(s) have occurred, one cannot possibly know which user(s) is(are) responsible.

Again, were a user to open a drawing, draw a line, delete the line just drawn, then save the drawing (effectively doing nothing)... That user would be logged.
A long time ago, I was in the same boat.  The piping lead asked me to print off a stack of drawings.  A few days later he comes back and asks "Why was this changed?"  "This shouldn't look like this" and so on, pointing to my name on an automated datestamp on the prints.  I had to repeated point out to him that the log (datestamp on drawing in this case) was only changed when the drawing was printed and I had *never* worked on the drawings.

The moral of the story: tracking logs don't always say what you think they are saying.
it's a better have more people on log list rather then none.
in my case log per day is good enough to find someone who made a bad mistake.
if someone is working in company where every move are tracked, then my compassion.
kruuger


Title: Re: How to run a lisp when close file ?
Post by: irneb on June 04, 2012, 12:30:17 PM
Again, were a user to open a drawing, draw a line, delete the line just drawn, then save the drawing (effectively doing nothing)... That user would be logged.
I can't remember, does the SysVar reactor catch changes in the CmdActive sysvar? If so perhaps just save a running total of how many commands the user's used during his/her editing time. E.g. if they've had the DWG open for several hours, but only 10 commands were issued, they probably only had it open as a reference to another drawing (i.e. for something like Copy-n-Paste).

Another alternative could be to count the number of objects inside the drawing at open, and then save the difference at Save. That way you can see how much extra work / erases were made.

There's no perfect answer, especially since any user could have multiple DWGs open at the same time. But it's near impossible to work on more than 1 at any one instant. Also what about those using RefEdit? They're inside one DWG, but actually modifying another.
Title: Re: How to run a lisp when close file ?
Post by: BlackBox on June 04, 2012, 12:54:51 PM
There's no perfect answer

This is the most accurate phrase yet.  :lol:

I can't remember, does the SysVar reactor catch changes in the CmdActive sysvar?


I'd have to experiment myself, now that you mention it.

Another alternative could be to count the number of objects inside the drawing at open, and then save the difference at Save. That way you can see how much extra work / erases were made.

There's no perfect answer, especially since any user could have multiple DWGs open at the same time. But it's near impossible to work on more than 1 at any one instant. Also what about those using RefEdit? They're inside one DWG, but actually modifying another.

Giving this a bit more thought, perhaps to simplify the who-dun-it concept _and_ to provide clear identification of what modifications have been made, a programmatic file copy at Save would prove useful. Then modify the dialog to present the user with the log list, and upon selection (or checkbox, etc.) the associated drawing (the one logged to that event/date/user) is programmatically referenced into the active drawing for 'review'.

While I do not keep track of who-dun-what, I do keep what I term 'void' copies of our drawings, which are made via LISP routine using a command (aptly named c:VOID ) to programmatically copy the drawing to a predetermined folder within our project's directory structure, adding the date to the file name. This can then be referenced to easily identify what changes were made, etc.

Admittedly, this can cause storage issues for those without the benefit of having massive amounts of available server space, etc.. This is just my workflow, and is certainly not perfect, nor would it apply to all. Just thought I'd share.
Title: Re: How to run a lisp when close file ?
Post by: HasanCAD on June 05, 2012, 03:00:03 AM
How to reset the LOG?
In some cased ( specially in details drawings) we copy and rename an old file to use in a new projects.
So we need to reset the file history.
Title: Re: How to run a lisp when close file ?
Post by: HasanCAD on June 05, 2012, 03:13:43 AM
The monitoring of the user activity is the response of the senior/team leader as well.
for monitoring the user activity we can use LEE's lisplog routine (http://www.lee-mac.com/lisplog.html)
Title: Re: How to run a lisp when close file ?
Post by: kruuger on June 05, 2012, 03:19:17 AM
How to reset the LOG?
In some cased ( specially in details drawings) we copy and rename an old file to use in a new projects.
So we need to reset the file history.
Code - Auto/Visual Lisp: [Select]
  1. (defun c:DLOG ()
  2.   (if (cd:DCT_GetDict (namedobjdict) "ADS_HISTORY")
  3.     (progn
  4.       (cd:DCT_RemoveDict (namedobjdict) "ADS_HISTORY")
  5.       (princ "\nLog history was deleted")
  6.     )
  7.     (princ "\nNo log history in drawing")
  8.   )
  9.   (princ)
  10. )
  11. ; =========================================================================================== ;
  12. ; Pobiera slownik / Gets a dictionary                                                         ;
  13. ;  Root [ENAME/nil] - ENAME = slownik "rodzic" / "parent" dictionary                          ;
  14. ;                     nil   = (namedobjdict) jako "rodzic" / (namedobjdict) as "parent"       ;
  15. ;  Name [STR]       - nazwa slownika / name of the dictionary                                 ;
  16. ; ------------------------------------------------------------------------------------------- ;
  17. ; (cd:DCT_GetDict (namedobjdict) "NAZWA")                                                     ;
  18. ; =========================================================================================== ;
  19. (defun cd:DCT_GetDict (Root Name)
  20.   (cdr (assoc -1 (dictsearch (if (not Root) (namedobjdict) Root) Name)))
  21. )
  22. ; =========================================================================================== ;
  23. ; Usuwa slownik / Removes the dictionary                                                      ;
  24. ;  Root [ENAME/nil] - ENAME = slownik "rodzic" / "parent" dictionary                          ;
  25. ;                     nil   = (namedobjdict) jako "rodzic" / (namedobjdict) as "parent"       ;
  26. ;  Name [STR]       - nazwa slownika / name of the dictionary                                 ;
  27. ; ------------------------------------------------------------------------------------------- ;
  28. ; (cd:DCT_RemoveDict (namedobjdict) "NAZWA")                                                  ;
  29. ; =========================================================================================== ;
  30. (defun cd:DCT_RemoveDict (Root Name)
  31.   (dictremove (if (not Root) (namedobjdict) Root) Name)
  32. )
  33. (princ "\n>> Type DLOG to invoke <<")
?
k.
Title: Re: How to run a lisp when close file ?
Post by: HasanCAD on June 07, 2012, 05:10:24 AM
Thanks Kruuger for the awesome lisp I'll study to learn from.
Title: Re: How to run a lisp when close file ?
Post by: HasanCAD on June 07, 2012, 05:19:21 AM
...
rewritten AUTOR.LSP to LOG.LSP (new shortcut LOG)
...
kruuger
How did you do the yellow circle which moved with the mouse?
Title: Re: How to run a lisp when close file ?
Post by: Coder on June 07, 2012, 07:55:38 AM
...
rewritten AUTOR.LSP to LOG.LSP (new shortcut LOG)
...
kruuger
How did you do the yellow circle which moved with the mouse?

It is an option in the video recorder , nothing is related to lisp .
Title: Re: How to run a lisp when close file ?
Post by: jbuzbee on June 07, 2012, 11:39:31 AM
This needs an OpenDCL interface: just sayen . . .  8-)