dmcknight
2009-05-07, 02:57 PM
I've had success using the DocumentCreated event to do whatever I need once the drawing is open. My problem is that there are function I would like to run just before closing the document.
So here is what I know (think), the events that pass DocumentBeginCloseEventArgs e seem to have only one function (bad terminology, sry I'm old school) associated, and thets e.veto(); . So I get the feeling that during the close events we are too late to run functions and the command must be veto'ed. With that, I tried the event CloseAborted assuming that e.veto() would fire the Close Aborted event, and thats where I need to put my pre-close functions. Well, its not happening like I expected so the question is this:
What event do I need to perfom some functions on a document just before closing, and if I'm right and the way to go is veto(), then use ??? event to perform the functions before calling close/save?
One more thing, is there info somewhere that describes the function or timing of events within Autocad?
Following is the code I use with the DocumentCreated, and the code I was attempting to use for the close.
public class start : IExtensionApplication
{
DocumentCollection dm = acadapp.DocumentManager;
public void Initialize()
{
dm.DocumentCreated += new DocumentCollectionEventHandler dm_DocumentCreated);
dm.MdiActiveDocument.BeginDocumentClose +=new DocumentBeginCloseEventHandler(MdiActiveDocument_BeginDocumentClose);
}
public void Terminate()
{
dm.DocumentCreated -= new DocumentCollectionEventHandler(dm_DocumentCreated);
dm.MdiActiveDocument.BeginDocumentClose -=new DocumentBeginCloseEventHandler(MdiActiveDocument_BeginDocumentClose);
}
private void dm_DocumentCreated(object sender, DocumentCollectionEventArgs e)
{
clsviewport.clsviewport.lv(); //locks all viewports.
}
void MdiActiveDocument_BeginDocumentClose(object sender, DocumentBeginCloseEventArgs e)
{
e.Veto(); //Vetos the close command.
}
}
So here is what I know (think), the events that pass DocumentBeginCloseEventArgs e seem to have only one function (bad terminology, sry I'm old school) associated, and thets e.veto(); . So I get the feeling that during the close events we are too late to run functions and the command must be veto'ed. With that, I tried the event CloseAborted assuming that e.veto() would fire the Close Aborted event, and thats where I need to put my pre-close functions. Well, its not happening like I expected so the question is this:
What event do I need to perfom some functions on a document just before closing, and if I'm right and the way to go is veto(), then use ??? event to perform the functions before calling close/save?
One more thing, is there info somewhere that describes the function or timing of events within Autocad?
Following is the code I use with the DocumentCreated, and the code I was attempting to use for the close.
public class start : IExtensionApplication
{
DocumentCollection dm = acadapp.DocumentManager;
public void Initialize()
{
dm.DocumentCreated += new DocumentCollectionEventHandler dm_DocumentCreated);
dm.MdiActiveDocument.BeginDocumentClose +=new DocumentBeginCloseEventHandler(MdiActiveDocument_BeginDocumentClose);
}
public void Terminate()
{
dm.DocumentCreated -= new DocumentCollectionEventHandler(dm_DocumentCreated);
dm.MdiActiveDocument.BeginDocumentClose -=new DocumentBeginCloseEventHandler(MdiActiveDocument_BeginDocumentClose);
}
private void dm_DocumentCreated(object sender, DocumentCollectionEventArgs e)
{
clsviewport.clsviewport.lv(); //locks all viewports.
}
void MdiActiveDocument_BeginDocumentClose(object sender, DocumentBeginCloseEventArgs e)
{
e.Veto(); //Vetos the close command.
}
}