Lisp Routine to Close Drawing

Lisp Routine to Close Drawing

ebsoares
Collaborator Collaborator
5,350 Views
4 Replies
Message 1 of 5

Lisp Routine to Close Drawing

ebsoares
Collaborator
Collaborator

Hi, everyone.

Trying to create a simple routine that will run a set of actions before closing the drawing. If I do it all from the command line and get to the point of closing the drawing we can just type "close" and AutoCAD will nicely display a dialog box asking if we want to save the drawing. 

However, I tried the simple routine (command "CLOSE") and, instead of that dialog box, it displays the question in the command line instead. Moreover, the answer is backwards: for the dialog box "yes" means "save the drawing", for the command line version "yes" means "do NOT save the drawing".

I searched around but couldn't find the solution...

Does anyone know how to create a lisp routine that uses the normal "close" command and displays the normal "close" dialog box?

Thanks

0 Likes
Accepted solutions (1)
5,351 Views
4 Replies
Replies (4)
Message 2 of 5

Kent1Cooper
Consultant
Consultant

@ebsoares wrote:

.... a simple routine that will run a set of actions before closing the drawing. .... we can just type "close" and AutoCAD will nicely display a dialog box asking if we want to save the drawing. 

However, I tried ... (command "CLOSE") and, instead of that dialog box, it displays the question in the command line instead. ....


 

Since you're prefacing the Closing with "a set of actions," presumably the answer to the question will always  be that you want to save the changes.  You can have it not ask that question, avoiding the issue, by just saving first:

 

(command "_.qsave" "_.close")

Kent Cooper, AIA
Message 3 of 5

ebsoares
Collaborator
Collaborator

Hi, Kent - thanks for the reply!

 

Your comment makes sense, generally. But what I'm trying to do is to simply use this routine every time I close a drawing - whether the drawing needs to be saved or not. So having that dialog box would help.

 

Here are the details (if it helps): the company I work for runs some routines automatically every time we open AutoCAD drawings - changing many variables in the process. Since a few of those changes are undesirable to the work I perform, I customized my own acad.lsp file to revert those variables to the way I need them. However, company policy dictates that file variables be the way they set them up, so I need to re-revert them back to the way they were after I finish my work. Here, saving the file when closing is the way to go. The kicker is those times when you just open a file to review something quickly but don't intend to change anything.

 

I'd like to get used to calling a lisp routine every time I need to close a drawing and decide on the fly whether it needs to be saved or not.

 

Is that possible?

0 Likes
Message 4 of 5

CodeDing
Advisor
Advisor
Accepted solution

@ebsoares,

 

As one option, you could use VisualLISP to send the command...

(defun c:TEST ( / )
(vl-load-com)
(vla-SendCommand (vla-get-ActiveDocument (vlax-get-acad-object)) "_.CLOSE ")
;;;Note the extra space " " between the E in CLOSE and the last quotation, to commit the command.
);defun

...this will still prompt as if you had typed it into the command line.

 

EDIT:

I had also tried using the (initdia) function to no avail. It does not prompt the Save dialog box.

 

Best,

~DD

Message 5 of 5

ebsoares
Collaborator
Collaborator

Thank you, @CodeDing! That's what I was looking for!

 

0 Likes