Prompt Message When Closing a Drawing

Prompt Message When Closing a Drawing

Anonymous
Not applicable
5,927 Views
24 Replies
Message 1 of 25

Prompt Message When Closing a Drawing

Anonymous
Not applicable

Is there a way to nix the "close" command and redefine it to include a message?

I'd like to get our guys in the habit of always making sure they are putting revision dates on their drawings. So I'd like have the message "Have you updated Revision Dates for this drawing?" with a YES/NO input from the user come up when they close a drawing. After that, it would bring up the normal save/close screen.

How could I accomplish this?

0 Likes
Accepted solutions (1)
5,928 Views
24 Replies
Replies (24)
Message 2 of 25

ronjonp
Mentor
Mentor

What about automating adding these dates? That would kill two birds with one code. Post a sample drawing.

0 Likes
Message 3 of 25

Kent1Cooper
Consultant
Consultant

Do some Searching.  This [or something very similar] has come up before.  There's probably a solution involving UNDEFINE-ing the CLOSE and EXIT and QUIT commands, and making new definitions of them that would ask that question of the User first -- probably not a difficult thing to build if you don't find anything suitable.

 

[I seem to recall that the upper-right-corner-X way of Closing didn't always actually use  the CLOSE command, so there was the problem of invoking such a thing when that was picked.  But checking now in Acad2016 that I have here, the individual-drawing X does  call up CLOSE, and the overall-program X does call up QUIT, so custom command definitions ought to work.]

Kent Cooper, AIA
0 Likes
Message 4 of 25

Kent1Cooper
Consultant
Consultant

@ronjonp wrote:

What about automating adding these dates? That would kill two birds with one code. ....


 

The OP may disagree, but I don't like that idea.  If I just open a drawing to refer to something, or Copy something from it to Paste into another drawing, but don't actually do anything that changes it, or even if I do something but then decide to Undo it all, I wouldn't want it to register as a revision.

Kent Cooper, AIA
0 Likes
Message 5 of 25

ronjonp
Mentor
Mentor

Sure .. that's why I asked for a sample drawing. There are usually some conditions to follow and IMO taking the user out of the equation yields more consistent results .. but that's just me. 8-)

0 Likes
Message 6 of 25

Kent1Cooper
Consultant
Consultant
Accepted solution

@Kent1Cooper wrote:

.... custom command definitions ought to work.]


 

In simplest terms:

 

(command "_.undefine" "CLOSE")
(defun C:CLOSE (/ yesno)
  (initget 1 "Yes No"); no Enter allowed -- must answer the question
  (setq yesno (getkword "\nHave you updated Revision Dates for this drawing? [Yes/No]: "))
  (if (= yesno "Yes")
    (command "_.close")
    (quit); that is, quit this routine -- not the same as QUIT command
  ); if
); defun

 

BUT that assumes you always  want them to update the revision date [or to lie about it], regardless of what they may have done or not done in the drawing, because it won't invoke the native CLOSE command unless they answer "Yes."  Should there be some kind of "No, but there's no reason to" option, for the situations I mentioned in my Reply to @ronjonp's automating suggestion?

 

It could also be built to have either Yes or No offered as a default  answer, requiring only Enter/space to accept it.

 

If that [or a more flexible version if needed] works, do the same with EXIT and QUIT.  But in all cases, there's the work-around possibility for those who don't want to be bothered, and who are knowledgeable enough, that they can just type in .CLOSE [with the decimal/period prefix], and get the native command directly, bypassing the re-definition.

 

EDIT:  Fixed the code [I left out an important part before...], so if you copied it before this EDIT appeared, try again.

Kent Cooper, AIA
0 Likes
Message 7 of 25

Anonymous
Not applicable

Kent, that is pretty much what I'm looking for. However, after I select yes it asks: "Really want to discard the changes to this drawing? <N>:" How would I be able to get rid of that? If there's no way to get rid of it the code does the trick. And I really like that it's a forced answer.

0 Likes
Message 8 of 25

Anonymous
Not applicable

It tends to lock up at the "Really want to discard all changes to drawing?" 

0 Likes
Message 9 of 25

ronjonp
Mentor
Mentor

Be aware that when your users get tired of your prompt they can easily bypass with .close. Might consider using a reactor instead.

0 Likes
Message 10 of 25

ronjonp
Mentor
Mentor

And if you stick to this method, maybe this will do. IMO there should be another check to see if this date question is even relevant to the current drawing.

(command "_.undefine" "_.close")
(defun c:close nil
  (cond	((= 1 (getvar 'writestat))
	 (initget 1 "Yes No")
	 (if (= (getkword "\nHave you updated Revision Dates for this drawing? [Yes/No]: ") "Yes")
	   (vl-cmdf "_.qsave" "_.close" "_Yes")
	   (print (strcat "Update the dates " (getenv "username") " or I'll release the kraken!"))
	 )
	)
	((vl-cmdf "_.close" "_n"))
  )
  (princ)
)
(vl-load-com)
0 Likes
Message 11 of 25

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

.... after I select yes it asks: "Really want to discard the changes to this drawing? <N>:" How would I be able to get rid of that? If there's no way to get rid of it the code does the trick. ....


 

That's because of this from Message 1:  "...with a YES/NO input from the user come up when they close a drawing. After that, it would bring up the normal save/close screen."  I assumed that since it's about the CLOSE command, the end of that should really say "it would bring up the normal close command," and I also assumed that it should do so only if the answer about updating the revision date was "Yes" [because if it was "No," you'd want them to do that before Closing].  In the case of a "Yes" answer, it's still possible that a User might have updated the revision date earlier on, and  might have done some other things since, which would trigger that prompt, and I would think you'd want that to be asked, not to get rid of it.  If you really do want it bypassed, do I assume correctly that you would want the answer about discarding changes to be "No," so that what's been done would be saved?  If so, you can change the one line to add the answer:

 

(command "_.close" "_no")

 

which seems to also eliminate the hanging up problem in your other Message.  [I can't otherwise explain that -- it also hangs up at that prompt for me when I run just (command "_.close") manually, but not when I include the "_no" answer.]

 

[I find it quite curious, but noteworthy, that if there have been changes since the last saving operation, the dialog-box  CLOSE command prompt is whether you want to Save  changes, but the command-line prompt is whether to discard  them.]

Kent Cooper, AIA
0 Likes
Message 12 of 25

scot-65
Advisor
Advisor
A method to consider, which I had employed at a previous office
is to redefine the QSAVE command. When a user commits to changes
to a file, the "last saved date" is applied to a text object.

At that time I only considered one text object to update but the method
could be expanded to a revision date table. Manipulation of a table is
not something I have investigated yet.

Original:
One will need to register an application and add extended code to a
text object in order to find the object. The downside is one can easily
copy this object and use it elsewhere without knowledge that the
text value is subject to change (yes, this has happened to us - and it
was our employer that did this!).

If I had to do it over again:
Retain the QSAVE thought and use an attributed title block (with both
the date and loginname).

???

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

0 Likes
Message 13 of 25

john.uhden
Mentor
Mentor

You are on the right track.

Somewhere I have the whole setup I've used for years to maintain a drawing history.  It uses a reactor and checks the value of DBMOD.

John F. Uhden

0 Likes
Message 14 of 25

Anonymous
Not applicable

So, thinking about the other opinions on should this be for each drawing or not, is there a way that it could look at the drawing to see if our title block exists? If it finds the block it will use the redefined command and if not it will use the _.close command?

0 Likes
Message 15 of 25

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

.... is there a way that it could look at the drawing to see if our title block exists? If it finds the block it will use the redefined command and if not it will use the _.close command?


 

If the Title Block is not a dynamic  Block [for which the "name" of an insertion  of it isn't the Block name itself], you can find out this way:

 

(ssget "_X" '((2 . "YourTitleBlockName")))

 

If that returns other than nil, then at least one insertion [or Xref] of it exists in the current drawing.  [If there's no insertion  of it, but the definition  exists in the drawing, that code won't reveal the fact, but that can also be determined if needed.]

Kent Cooper, AIA
0 Likes
Message 16 of 25

john.uhden
Mentor
Mentor

 A commandwillstart reactor can allow you to check the drawing and do many things before the command actually takes place.  But you may prefer to use a beginsave reactor to modify the drawing before it's actually saved.

John F. Uhden

0 Likes
Message 17 of 25

sagar.adhau
Participant
Participant

Hi , Thanks all for your comment in above post it help lot for me. I have below query please help,

 

I have prepared below for my requirement. In this, when user going to close the auto cad file by clicking on X right top corner of file it will give Auto cad message  to user for check point before closing. After check point window, command prompt use to show user about message for '' do you want to save the drawing" if Yes the drawing save and close and if press '' No'' then issue i am facing is, it will again ask " Really want to discard all changes to drawing? <N>" After pressing "No" for changes in file, the file should close directly without asking again for my confirmation . I don't need this message please advice. below is my lisp,

=======================================

(command "_.undefine" "_.close")

(defun c:close nil

(setvar "cmdecho" 0)

(alert (strcat "n1.check quantity in material list per customer PO" "\n2.Ensure the component voltage "))

  (initget "Yes No")

  (setq ans (getkword "\ndo you want to save drawing [Y/N]? "))

   (if (=and "Yes")

   (progn

    (vl-cmdf "_.qsave" "_.close" "_Yes")

    )

   (command "_.close")

)

(princ)

)

===================================

Kindly Help.

Can I bring the same window (after my custom point check window) which is default setting in auto cad for drawing saving without having the message in command prompt.

Also suggest if i can add checkbox for the checkpoint i mentioned in Autocad message pop up, See attached?.

 

Thanks a lot

 

0 Likes
Message 18 of 25

Sea-Haven
Mentor
Mentor

One item that was barely mentioned was NO and what would actually happen, yes its checked, so for me I would do something like (load "update revision") forcing the user to do just that in that lisp, this cancels the Close etc, how that is handled is up to your company std.

 

2 options Doslib has a yesno dcl and same with my Multi radio buttons.lsp so user has a dcl rather than a Initget. 

 

(if (not AH:Butts)(load "Multi Radio buttons.lsp"))
(if (= but nil)(setq but 1))
(setq ans (ah:butts but "h"  '("Yes or No" "Yes" "No"))) ; ans holds the button picked value

 

0 Likes
Message 19 of 25

sagar.adhau
Participant
Participant
Hi, I have very basic knowledge of Lisp. Please mentioned where to add above code you have mentioned.
0 Likes
Message 20 of 25

Sea-Haven
Mentor
Mentor

1 undefine

2 have you met the questions

3 yes close dwg or dont close 

 

Your code has 2-3 problems 

(if (=and "Yes") ans is correct variable name

 

The yes no should be for the (alert (strcat "n1.check quantity in material list per customer PO" "\n2.Ensure the component voltage ")) not the close.

 

After if = yes do close remove second close so dwg will not close as you have said NO.

 

I will try to find time to write a dcl with the message re paragraph and the yes no.

 

0 Likes