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.
Solved! Go to Solution.
Solved by FRFR1426. Go to Solution.
Document.BeginDocumentClose
You can call DocumentBeginCloseEventArgs.Veto() to stop AutoCAD from shutting down the document.
You can also use Document.CloseWillStart or DocumentCollection.DocumentToBeDestroyed.
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();
}
}
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...
Can't find what you're looking for? Ask the community or share your knowledge.