Author Topic: How to run a lisp when close file ?  (Read 16813 times)

0 Members and 1 Guest are viewing this topic.

kruuger

  • Swamp Rat
  • Posts: 637
Re: How to run a lisp when close file ?
« Reply #15 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

Coder

  • Swamp Rat
  • Posts: 827
Re: How to run a lisp when close file ?
« Reply #16 on: May 31, 2012, 04:41:26 AM »
Why not include command CLOSE at the bottom of the routine and exclude using reactors .... :pissed:

kruuger

  • Swamp Rat
  • Posts: 637
Re: How to run a lisp when close file ?
« Reply #17 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

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: How to run a lisp when close file ?
« Reply #18 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.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

kruuger

  • Swamp Rat
  • Posts: 637
Re: How to run a lisp when close file ?
« Reply #19 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

Coder

  • Swamp Rat
  • Posts: 827
Re: How to run a lisp when close file ?
« Reply #20 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 .

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: How to run a lisp when close file ?
« Reply #21 on: May 31, 2012, 07:18:48 AM »
...
this is what you want HasanCAD ?
kruuger
YES this is what I want

pBe

  • Bull Frog
  • Posts: 402
Re: How to run a lisp when close file ?
« Reply #22 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?

BlackBox

  • King Gator
  • Posts: 3770
Re: How to run a lisp when close file ?
« Reply #23 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:
« Last Edit: June 29, 2012, 04:36:49 PM by RenderMan »
"How we think determines what we do, and what we do determines what we get."

kruuger

  • Swamp Rat
  • Posts: 637
Re: How to run a lisp when close file ?
« Reply #24 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.

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: How to run a lisp when close file ?
« Reply #25 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

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: How to run a lisp when close file ?
« Reply #26 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"

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: How to run a lisp when close file ?
« Reply #27 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

kruuger

  • Swamp Rat
  • Posts: 637
Re: How to run a lisp when close file ?
« Reply #28 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

BlackBox

  • King Gator
  • Posts: 3770
Re: How to run a lisp when close file ?
« Reply #29 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.
"How we think determines what we do, and what we do determines what we get."