Hi,
Is it possible to override the close in an autocad drawing.
My requirement is such that when the user clicks on close button, I need a different message box to appear, where I can save, discard or cancel the operation.
-Ted
Solved! Go to Solution.
Solved by norman.yuan. Go to Solution.
Whether user clicks "Close" in the menu/toolbar/ribbon, or enter "Close" at command line, or even click "x" at top-right corner of the document window, AutoCAD execute "Close" command.
So, you can handle DocumentCollection.DocumentLockModeChanged event to veto "Close" command, the event handler would look like:
static void DocumentManager_DocumentLockModeChanged(object sender, DocumentLockModeChangedEventArgs e) { Document dwg = CadApp.DocumentManager.MdiActiveDocument; Editor ed = dwg.Editor; ed.WriteMessage("\nGlobal command: {0}", e.GlobalCommandName); if (e.GlobalCommandName.ToUpper()=="CLOSE") { ed.WriteMessage("\n\"Close\" command is vetoed!"); e.Veto(); } }
Since you need to do something after veto the regular command and then eventaully allow the document being closed, you will also need to handle DocumentLockModeChangeVetoed event to start your own closing process.
Actually, in the DocumentLockModeChanged event handler, you may also have to veto "Quit" command, because if user click AutoCAD window's "x", the "Close" command may not be issued by AutoCAD.
The situation is quite tricky, and if not dealt with very carefully, user might be confused/frustrated when being forced to deal with AutoCAD in irregular way.
Norman Yuan
Hi,
Thanks for the reply..
This was exactly what I was implementing currently.. Just wanted to cross check if there could be a better one
Thanks!
Ted
Hi @norman.yuan ,
Could you please kindly help me to override "Quit" command.
I'm just trying to place a alert message while the user is trying to close the drawing using "x" window button.
I'm quite new to lisp writing.
I have written the below code using Vlide.
(defun c:c()
(Alert " Self Quality Check points :
• Check the Revision Date, Description & Details are correct
• Check the Layers are correct
• Check Insulation & Tracing updated base on the reference Iso
• Check the P&ID number matching or not
***Please Ensure the above points before closing this Drawing***")
(command "close")
)
Thanks in advance