TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: ROBBO on January 30, 2015, 11:18:57 AM

Title: Up DWGPROPS revsion on save / exit of drawing automatically
Post by: ROBBO on January 30, 2015, 11:18:57 AM
Any help, as always appreciated. I am trying to add a routine to my start-up that would automatically update the dwgprops revision from the rev letter in the layout tab. I have tried, but struggling to get it to work.

This is what I have thus far:

Code - Auto/Visual Lisp: [Select]
  1. (defun sstrtcmdRev (calling-reactor sstrtcmdRevinfo / Rev)
  2.   (if (wcmatch (car sstrtcmdRevinfo) "*SAVE*")
  3.     (progn
  4. (defun updpRev (/ acsum Rev)
  5. (setq Rev (getvar "CTAB"))
  6. (setq acsum
  7.     (vla-get-summaryinfo
  8.         )
  9.       )
  10.     )
  11.   )
  12. )
  13.   (vla-get-revisionnumber acsum)
  14. (vla-put-revisionnumber acsum Rev)
  15. )

I have a similar lisp that works when the command is entered and works fine, but would like this to update automatically.

Many thanks in advance, Robbo.
Title: Re: Up DWGPROPS revsion on save / exit of drawing automatically
Post by: CincyJeff on January 30, 2015, 12:01:28 PM
I would think you could use a reactor to fire before the end command runs or you can redefine the end command to perform your function before closing.
Title: Re: Up DWGPROPS revsion on save / exit of drawing automatically
Post by: ChrisCarlson on January 30, 2015, 12:27:45 PM
Where is the command that currently works? If you want it to run every time a drawing is opened, add the command to the end of your routine, and have the routine set to autoload

so something like this

Code: [Select]
(defun c:LevelUpLikeMario (/)
(princ)
)
(LevelUpLikeMario)
Title: Re: Up DWGPROPS revsion on save / exit of drawing automatically
Post by: ROBBO on February 02, 2015, 02:23:08 AM
Where is the command that currently works? If you want it to run every time a drawing is opened, add the command to the end of your routine, and have the routine set to autoload

so something like this

Code: [Select]
(defun c:LevelUpLikeMario (/)
(princ)
)
(LevelUpLikeMario)

This is the routine/command to run on drawing start-up, but would prefer to have the command run when drawing is saved or on exit;

Code - Auto/Visual Lisp: [Select]
  1. (defun c:updpRev (/ acsum Rev)
  2. (setq Rev (getvar "CTAB"))
  3. (setq acsum
  4.     (vla-get-summaryinfo
  5.     )
  6. )
  7. (vla-get-revisionnumber acsum)
  8. (vla-put-revisionnumber acsum Rev)
  9. )
  10. (c:updpRev)
Title: Re: Up DWGPROPS revsion on save / exit of drawing automatically
Post by: roy_043 on February 02, 2015, 07:54:54 AM
If I look at the code in the first post I notice some issues:
1.
When the command name matches "*SAVE*" you define a function without executing it.
2.
Lines 14 and 15 are outside the function updpRev.
3.
Line 14 is not necessary.

Using a :vlr-commandwillstart reactor you should be able to react to the SAVE and QSAVE commands. But I would not attempt to react to the QUIT command.

Code: [Select]
(if *myCommandReactor*
  (vlr-remove *myCommandReactor*)
)
(setq *myCommandReactor*
  (vlr-command-reactor nil '((:vlr-commandwillstart . sstrtcmdRev)))
)

(defun sstrtcmdRev (rea lst)
  (if (wcmatch (car lst) "*SAVE*") (updpRev))
)

(defun updpRev (/ acsum Rev)
  (setq Rev (getvar "CTAB"))
  (setq acsum
     (vla-get-summaryinfo
         (vla-get-activedocument (vlax-get-acad-object))
     )
  )
  (vla-put-revisionnumber acsum Rev)
)
Title: Re: Up DWGPROPS revsion on save / exit of drawing automatically
Post by: ROBBO on February 02, 2015, 08:06:17 AM
If I look at the code in the first post I notice some issues:
1.
When the command name matches "*SAVE*" you define a function without executing it.
2.
Lines 14 and 15 are outside the function updpRev.
3.
Line 14 is not necessary.

Using a :vlr-commandwillstart reactor you should be able to react to the SAVE and QSAVE commands. But I would not attempt to react to the QUIT command.

Code: [Select]
(if *myCommandReactor*
  (vlr-remove *myCommandReactor*)
)
(setq *myCommandReactor*
  (vlr-command-reactor nil '((:vlr-commandwillstart . sstrtcmdRev)))
)

(defun sstrtcmdRev (rea lst)
  (if (wcmatch (car lst) "*SAVE*") (updpRev))
)

(defun updpRev (/ acsum Rev)
  (setq Rev (getvar "CTAB"))
  (setq acsum
     (vla-get-summaryinfo
         (vla-get-activedocument (vlax-get-acad-object))
     )
  )
  (vla-put-revisionnumber acsum Rev)
)

Thank you roy_043