Announcements
Due to scheduled maintenance, the Autodesk Community will be inaccessible from 10:00PM PDT on Oct 16th for approximately 1 hour. We appreciate your patience during this time.
.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Need to show popup at the time of closing document in Autocad

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

Need to show popup at the time of closing document in Autocad

Hello Team,

 

I have integrated C# code with Auto Cad tool for perform some operation. I am using AutoCad 2019

 

Now I am trying to show the popup when I will close the document opened in Auto Cad.

 

please help me to find out document close event in auto cad.

3 REPLIES 3
Message 2 of 4
FRFR1426
in reply to: Anonymous

Document.BeginDocumentClose

 

You can call DocumentBeginCloseEventArgs.Veto() to stop AutoCAD from shutting down the document.

 

You can also use Document.CloseWillStart or DocumentCollection.DocumentToBeDestroyed.

 
Maxence DELANNOY
Manager
Add-ins development for Autodesk software products
http://wiip.fr
Message 3 of 4
Anonymous
in reply to: FRFR1426

Thank you for the reply...

As per your suggestion i have added code..

I have added two command to add or remove  DocumentBeginCloseEventHandler.But I want to add this DocumentBeginCloseEventHandler()  function on the time of document load using c#..Can you help with this

 

Please check the following code that i have added...

 

[CommandMethod("AddDocEvent")]
public void AddDocEvent(){
  // Get the current document
  Document acDoc = Application.DocumentManager.MdiActiveDocument;
 
  acDoc.BeginDocumentClose += 
      new DocumentBeginCloseEventHandler(docBeginDocClose);
}
 
[CommandMethod("RemoveDocEvent")]
public void RemoveDocEvent(){
  // Get the current document
  Document acDoc = Application.DocumentManager.MdiActiveDocument;
 
  acDoc.BeginDocumentClose -=
      new DocumentBeginCloseEventHandler(docBeginDocClose);
}
 
public void docBeginDocClose(object senderObj, 
                             DocumentBeginCloseEventArgs docBegClsEvtArgs){
  // Display a message box prompting to continue closing the document
  if (System.Windows.Forms.MessageBox.Show(
                       "The document is about to be closed." +
                       "\nDo you want to continue?",
                       "Close Document",
                       System.Windows.Forms.MessageBoxButtons.YesNo) ==
                       System.Windows.Forms.DialogResult.No)
  {
      docBegClsEvtArgs.Veto();
  }
}

 

Message 4 of 4
FRFR1426
in reply to: Anonymous

You can install your handler in an handler of the DocumentCreated event. This event will be triggered each time a drawing is opened.

 

The empty drawing which is opened at AutoCAD startup (Drawing1.dwg) must be handled separately. You can use the DocumentBecameCurrent event for this one, but remove the handler from the event after installing your handler for DocumentBeginClose because DocumentBecameCurrent is called each time the document window is activated.

 

There is a list of DocumentCollection events here: https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2015/ENU/AutoCAD-NET/files/GUI...

Maxence DELANNOY
Manager
Add-ins development for Autodesk software products
http://wiip.fr

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

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report