I'm putting together a simple lisp routine to help issue bound, purged drawings.
I have code that will do the binding & purging but need help with handling the saving.
This is my approach :
(1) ask the user to save the drawing using this line (command "_saveas" "" "~")
(2) run a subroutine that binds xrefs etc (this works ok)
(3) run the QSAVE command
Trouble is, if the user cancels or hits escape during the SAVEAS command the subroutine & QSAVE will still run, overwriting the current drawing. How do I handle this scenario? Or should my appoach be different?
Solved! Go to Solution.
Solved by Lee_Mac. Go to Solution.
Maybe compare the value of the DWGNAME System Variable before and after the call to SaveAs?
Quick example:
(defun c:test ( / cmd dwg ) (setq cmd (getvar 'CMDECHO)) (setvar 'CMDECHO 0) (setq dwg (strcase (strcat (getvar 'DWGPREFIX) (getvar 'DWGNAME)))) (command "_.saveas" "" "~") (if (eq dwg (strcase (strcat (getvar 'DWGPREFIX) (getvar 'DWGNAME)))) (princ "\nUser Cancelled Dialog.") (princ "\nDrawing was Saved.") ) (setvar 'CMDECHO cmd) (princ) )
@toolbox2 wrote:....
This is my approach :
(1) ask the user to save the drawing using this line (command "_saveas" "" "~")
(2) run a subroutine that binds xrefs etc (this works ok)
(3) run the QSAVE command
Trouble is, if the user cancels or hits escape during the SAVEAS command the subroutine & QSAVE will still run, overwriting the current drawing. How do I handle this scenario? Or should my appoach be different?
Perhaps something like this:
(if (not (vl-cmdf "_saveas" "" "~"))
(quit); then - simply stop overall routine before it gets to the following
); end if - no else argument - do nothing here if Saveas is completed
(.... on to the subroutine that binds xrefs, etc....)
....
EDIT: Never mind -- that doesn't seem to work as I expected -- the (not (vl-cmdf.... doesn't return T if you hit Escape in the Saveas command. But maybe the approach could be valid if formatted differently?
(if (vl-cmdf "_.saveas" "" "~")
(progn
(....the subroutine....
Kent1Cooper wrote:
.... But maybe the approach could be valid if formatted differently?
(if (vl-cmdf "_.saveas" "" "~")
(progn
(....the subroutine....
No, that doesn't seem to do it, either.
Pausing in the middle of the program for user input is not a good idea.
Tisk tisk...
Approach it differently by using the GETFILED function, and if successful
execute the rest of the program while quietly using the command line saveas...
You can mimic the saveas dialog box as though one would not notice.
You can also apply a prefix/suffix to the original file name and use that as the "default" file name
(strcat (VL-FILENAME-BASE (getvar 'dwgname)) "-Bind01-" (itoa (fix (getvar 'cdate))) ).
Untested, but you get the idea.
Minimum flag to set is 1.
Review the AutoLISP reference for further details.
???
Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.
I've got this up and running but I need something more robust. It's feasible that a user would want to use the same filename - in which case the xref binding code won't run.
pbejse has suggested using a reactor. Not familiar with these but am trying to fathom them out.
By the way, good stuff on your website 🙂
toolbox2 wrote:I've got this up and running but I need something more robust. It's feasible that a user would want to use the same filename - in which case the xref binding code won't run.
OK, perhaps:
(defun c:test ( / cmdecho tdupdate ) (setq cmdecho (getvar 'CMDECHO)) (setvar 'CMDECHO 0) (setq tdupdate (getvar 'TDUPDATE)) (command "_.saveas" "" "~") (if (< tdupdate (getvar 'TDUPDATE)) (princ "\nDrawing was saved.") (princ "\nUser pressed Cancel.") ) (setvar 'CMDECHO cmdecho) (princ) )
toolbox2 wrote:pbejse has suggested using a reactor. Not familiar with these but am trying to fathom them out.
Since LISP doesn't allow multiple threads, the reactor callback function would not be evaluated whilst the program you are running has focus.
toolbox2 wrote:By the way, good stuff on your website 🙂
Cheers!
@toolbox2 wrote:Thanks for the tip. Is it possible to get the full-on SAVEAS dialogue box with the shortcuts on the left etc
I do not think this is possible since the saveas dialog *might* be written in .NET
while getfiled *might* be written in DCL...
I personally would work with getfiled. It's safer than to pause for user input.
I think Lee_Mac is on the right track by testing if the file name is not the same before
and after the saveas. However, not testing, it would seem if one hit the cancel button
in the saveas dialog, an empty string would return - and it is different than before the
saveas... which means true (when using getfiled method)...
???
Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.
Decided to go with this. Thanks.
Incidentally, the xref binding code I'm using came from here:
where I believe you gave a helping hand.
toolbox2 wrote:Decided to go with this. Thanks.
Incidentally, the xref binding code I'm using came from here:
where I believe you gave a helping hand.
Good stuff toolbox2, happy to help