PDA

View Full Version : BeginDocumentClose



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.
}


}

dmcknight
2009-05-29, 06:58 PM
Events, from the standpoint of Documents, seem to be something either, not alot of people are using, or there is too little info out there about it/them.

So let me pose this question, or request:

Does anyone use or have code that uses the document closing event(s). I know if I had a little info, I could at least start out in the right direction.

T.Willey
2009-05-29, 08:47 PM
I haven't use that event, so this may not be right, but sounds good to me.

Couldn't you just veto the close, then run the code you want plus remover the event, and then just close the document yourself? I would check to make sure it was saved just before closing, if you are doing something to the database that you wanted to save, but if not, then I see no reason why this wouldn't work.