Jump to content

Reactor Issue


PDuMont

Recommended Posts

Hi,

 

I am using a modiffied version of the autosave reactor posted by Lee Mac here

 

The reactor is invoked via the acaddoc.lsp file.

 

Everything is working fine with one exception.

Apparently the acaddoc file is loaded when using EXPORTDWF/EXPORTPDF commands.

 

I have added pop-up dialogs to the autosave reator and these dialogs appear every time I export to file.

It doesn't happen with publish or plot, only export, which is primarily what I use.

 

I have tried to add conditionals to the reactor to check for file extension (.dwg) and variable 'dwgtitled to no avail.

 

Does anyone know what AutoCAD is doing when exporting?

 

I can post the reactor if anyone needs.

 

Thanks.

Link to comment
Share on other sites

Yes, please post the modified code you're using.

 

Off the top of my head... Perhaps employing a Command Reactor such that CommandWillStart event filters for EXPORT* Commands, subsequently unregistering the Autosave Reactor, and following CommandCancelled, CommandEnded, or CommandFailed for same, the Autosave Reactor is again registered.

 

Cheers

Edited by BlackBox
I can haz a grammar
Link to comment
Share on other sites

Thanks BlackBox, that sounds promising.

 

Edit: the pop-up is using express tools, wont work if not installed.

Will use a more robust dialog eventually.

 

(vl-load-com)
(defun c:ason ()
 (if (not *autosave-reactor*)
   (progn
     (setq *autosave-reactor*
     (vlr-command-reactor
       "autosave"
       '(
	 (:vlr-commandWillStart . autosave)
	 (:vlr-commandended     . autosave)
	 (:vlr-commandcancelled . autosave)
	 (:vlr-commandfailed    . autosave)
	)
     ) ;_ end of vlr-command-reactor
     ) ;_ end of setq
     (princ "\n<<< AutoSave reactor Switched ON >>>")
   ) ;_ end of progn
 ) ;_ end of if
 (princ)
) ;_ end of defun


(defun c:asoff ()
 (if *autosave-reactor*
   (progn
     (vlr-Remove *autosave-reactor*)
     (setq *autosave-reactor* nil)
     (princ "\n<<< AutoSave reactor Switched OFF >>> ")
   ) ;_ end of progn
 ) ;_ end of if
 (princ)
) ;_ end of defun


(setq *autosave-acdoc* (vla-get-activedocument (vlax-get-acad-object))
     *autosave-count* 0
) ;_ end of setq


(defun autosave	(obj arg)
 (if (and
(not
  (wcmatch (strcase (car params)) "*UNDO"))
(zerop
  (rem (setq *autosave-count* (1+ *autosave-count*)) 20) ;_COMMAND COUNTER
) ;_ end of zerop
   (= 1 (getvar 'dwgtitled))
     ) ;_ end of and
   (vla-save *autosave-acdoc*)
 ) ;_ end of if
 (princ)
) ;_ end of defun


(princ
 "\nType ASON to switch-on and ASOFF switch-off command reactor "
) ;_ end of princ
(princ)
(c:ason)


(setq reply (ACET-UI-MESSAGE
	"Turn AutoSave On? "
	"**ALERT**"
	(+ Acet:YESNO Acet:ICONWARNING)
      ) ;_ end of ACET-UI-MESSAGE

) ;_ end of setq

;; Yes = 6
;; No = 7
;; Cancel = 2

(if (= reply 6)
 (progn
   (c:ason)
   (ALERT "AutoSave is turned on \nType ASOFF to disable")
 ) ;_ end of progn
 ;; else
 (progn
   (c:asoff)
   (ALERT "AutoSave is turned off \nType ASON to enable")
 ) ;_ end of progn
) ;_ end of if
(princ)

Link to comment
Share on other sites

Even simpler (now that I've seen Lee's code, which already uses a Command Reactor), just add "*EXPORT*" to the WCMATCH test expression's string, within the 'autosave' Callback :thumbsup: :

 

(defun autosave (obj [color="blue"]arg[/color])
 (if
   (and
     (not (wcmatch (strcase (car [color="blue"]arg[/color])) "[color="red"]*EXPORT*[/color],*UNDO"))
     (zerop (rem (setq *autosave-count* (1+ *autosave-count*)) 20))
     (= 1 (getvar 'dwgtitled))
   )
   (vla-save *autosave-acdoc*)
 )
 (princ)
)

 

 

 

[Edit] - Also changed 'params' (not sure where that came from?) to 'arg' which is specified in the Defun itself as a function parameter.

Link to comment
Share on other sites

Give this slight adaptation of Lee's code a try:

 

(vl-load-com)

(defun c:ASON ()
 (or *autosave-reactor*
     (setq *autosave-reactor*
            (vlr-command-reactor
              "autosave"
              '(
                (:vlr-commandWillStart . autosave:CommandWillStart)
                (:vlr-commandended . autosave:CommandEnded)
                (:vlr-commandcancelled . autosave:CommandEnded)
                (:vlr-commandfailed . autosave:CommandEnded)
               )
            )
     )
 )
 (or *autosave-acdoc*
     (setq *autosave-acdoc*
            (vla-get-activedocument (vlax-get-acad-object))
     )
 )
 (setq *autosave-count* 0)
 (if (not *autosave-export*)
   (prompt "\nAutoSave reactor loaded, invoke \"ASOFF\" to stop. ")
 )
 (princ)
)

(defun c:ASOFF ()
 (if *autosave-reactor*
   (progn
     (vlr-remove *autosave-reactor*)
     (setq *autosave-reactor* nil
           *autosave-count*   nil
     )
   )
 )
 (if (not *autosave-export*)
   (prompt "\nAutoSave reactor stopped, invoke \"ASON\" to start. ")
 )
 (princ)
)

(defun autosave:CommandEnded (obj cmd)
 (if
   (and

     ;; don't save when an *export* or *undo command ends
     (not (wcmatch (strcase (car cmd)) "*EXPORT*,*UNDO"))
     (zerop (rem (setq *autosave-count* (1+ *autosave-count*)) 20))
     (= 1 (getvar 'dwgtitled))
   )
    (vla-save *autosave-acdoc*)
 )
 (setq *autosave-export* nil)
 (princ)
)

(defun autosave:CommandWillStart (obj cmd)
 ;; stop reactor on export, which will automagically start again,
 ;; when export* command re-loads acaddoc.lsp (contining this code).
 (if (setq *autosave-export* (wcmatch (strcase (car cmd)) "*EXPORT*"))
   (c:ASOFF)
 )
)

(c:ASON)

Link to comment
Share on other sites

If I've correctly understood what you are looking to achieve, try the following:

(defun c:ason nil
   (asremove)
   (vlr-command-reactor "autosave"
      '(   (:vlr-commandwillstart . autosave)
           (:vlr-commandended     . autosave)
           (:vlr-commandcancelled . autosave)
           (:vlr-commandfailed    . autosave)
       )
   )
   (setq autosave-count 0)
   (princ "\n<<< AutoSave reactor Switched ON >>>")
   (princ)
)
(defun c:asoff nil
   (asremove)
   (princ "\n<<< AutoSave reactor Switched OFF >>> ")
   (princ)
)
(defun asremove nil
   (foreach obj (cdar (vlr-reactors :vlr-command-reactor))
       (if (= "autosave" (vlr-data obj))
           (vlr-remove obj)
       )
   )
)
(defun autosave ( obj arg )
   (if (and (not (wcmatch (strcase (car arg)) "*UNDO"))
            (numberp autosave-count)
            (zerop (rem (setq autosave-count (1+ autosave-count)) 20))
            (= 1 (getvar 'dwgtitled))
       )
       (vla-save (asdoc))
   )
   (princ)
)
(defun asdoc nil
   (eval (list 'defun 'asdoc nil (vla-get-activedocument (vlax-get-acad-object))))
   (asdoc)
)
(   (lambda nil
       (vl-load-com)
       (cond
           (   (wcmatch (strcase (vl-filename-extension (getvar 'dwgname)) t) ".dwf"))
           (   (= 6 (acet-ui-message "Turn AutoSave On? " "**ALERT**" (logior Acet:YESNO Acet:ICONWARNING)))
               (c:ason)
               (ALERT "AutoSave is turned on \nType ASOFF to disable")
           )
           (   (c:asoff)
               (ALERT "AutoSave is turned off \nType ASON to enable")
           )
       )
       (princ)
   )
)

Link to comment
Share on other sites

Hi BlackBox & Lee,

 

No go... still get dialogs on export.

 

Since autocad is apparently(?) opening a new(temp of some sort) drawing in the export command

could the dialog itself just be suppressed?

Link to comment
Share on other sites

Hi BlackBox & Lee,

 

No go... still get dialogs on export.

 

Since autocad is apparently(?) opening a new(temp of some sort) drawing in the export command

could the dialog itself just be suppressed?

 

While I gladly defer to Lee, being that this stems from his code, I am confused by your comment - there are no dialog calls in the modified code I posted above.

Link to comment
Share on other sites

Sorry about that BlackBox, hastily typed.

 

I am not overly concerned about the reactor "seeing" the export command.

The dialogs in the original are there to alert the end user, and give a choice to enable/disable the reactor.

For most users this is not neccessary, but for some not knowing this reactor is running could be dangerous.

 

I hope that makes sense.

Link to comment
Share on other sites

Try the following instead:

(defun c:ason nil
   (asremove)
   (vlr-command-reactor "autosave"
      '(   (:vlr-commandwillstart . autosave)
           (:vlr-commandended     . autosave)
           (:vlr-commandcancelled . autosave)
           (:vlr-commandfailed    . autosave)
       )
   )
   (setq autosave-count 0)
   (princ "\n<<< AutoSave reactor Switched ON >>>")
   (princ)
)
(defun c:asoff nil
   (asremove)
   (princ "\n<<< AutoSave reactor Switched OFF >>> ")
   (princ)
)
(defun asremove nil
   (foreach obj (cdar (vlr-reactors :vlr-command-reactor))
       (if (= "autosave" (vlr-data obj))
           (vlr-remove obj)
       )
   )
)
(defun autosave ( obj arg )
   (if (and (not (wcmatch (strcase (car arg)) "*UNDO"))
            (numberp autosave-count)
            (zerop (rem (setq autosave-count (1+ autosave-count)) 20))
            (= 1 (getvar 'dwgtitled))
       )
       (vla-save (asdoc))
   )
   (princ)
)
(defun asdoc nil
   (eval (list 'defun 'asdoc nil (vla-get-activedocument (vlax-get-acad-object))))
   (asdoc)
)
(   (lambda nil
       (vl-load-com)
       (cond
           (   (wcmatch (strcase (getvar 'dwgprefix)) (strcat (strcase (getenv "TempDirectory")) "*")))
           (   (= 6 (acet-ui-message "Turn AutoSave On? " "**ALERT**" (logior Acet:YESNO Acet:ICONWARNING)))
               (c:ason)
               (ALERT "AutoSave is turned on \nType ASOFF to disable")
           )
           (   (c:asoff)
               (ALERT "AutoSave is turned off \nType ASON to enable")
           )
       )
       (princ)
   )
)

Link to comment
Share on other sites

Ah Lee, that got it.

 

Thank you both for you help, I truly appreciate it.

 

Lee, I am assuming this did it:

 

(wcmatch (strcase (getvar 'dwgprefix)) (strcat (strcase (getenv "TempDirectory")) "*"))

Link to comment
Share on other sites

I hope that makes sense.

 

Your clarification helps, yes - not sure how dangerous this is, given that it just saves one's work, but that is for you to decide nonetheless. :beer:

 

Cheers

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...