.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Need to override the close in the autocad drawing

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
Anonymous
813 Views, 3 Replies

Need to override the close in the autocad drawing

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

3 REPLIES 3
Message 2 of 4
norman.yuan
in reply to: Anonymous

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

Drive CAD With Code

EESignature

Message 3 of 4
Anonymous
in reply to: 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

Message 4 of 4
tunithin
in reply to: norman.yuan

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost