So, here is my problem. I have an event handler that intercepts saving of documents. In other words I have a:
Application.DocumentManager.DocumentLockModeChanged += documentLockModeChanged;
and
private void documentLockModeChanged(object sender, AutoCAD.DocumentLockModeChangedEventArgs e) {
doSomeStuff();
}
Now, in my "doSomeStuff" I am working with an in-house (yeah, I know) document management system - DMS, so basically what I do is get and set some properties in the drawing and in the meta information about said drawing in the DMS Then I save the drawing to the DMS and I want to close it. So, somewhere I have a
Application.DocumentManager.MdiActiveDocument.CloseAndDiscard();
Sadly, this doesn't work. I get a command-in-progress error. If this was a command, I could apparently set CommandMode.Session and all would be fine, but since this is inside an event handler, that has no effect. Does anyone have a good idea?
BTW, this is in Autocad 2013.
I create a command that closes and discards the drawing... basically:
[CommandMethod("CurrDocCloseAndDiscard", CommandFlags.Session)]
public static void CurrDocCloseAndDiscard() {
DocumentManager.MdiActiveDocumentCloseAndDiscard();
}
then in my event handler I do:
...SendStringToExecute("CurrDocCloseAndDiscard\r")...
Seems to work. Don't know if it is a bad thing to do...
I do not think you need to do something like this. You can close your current document very easily without using the event handler. As you are put your code in document lock handler , this is why you are getting that some command on progress. but you can easily save and close your document by following code. you do not need to sendstringto execute.
[CommandMethod("CD", CommandFlags.Session)] Static public void CloseDocument() { Document doc = Application.DocumentManager.MdiActiveDocument; doc.CloseAndSave(doc.Name); }
You can also go through the below link where you may get some idea about closing document in details
http://through-the-interface.typepad.com/through_the_interface/2007/03/closing_all_ope.html
Please also see developers document. Those material are very helpful to resolve general issue.
Out of curiousity if you are wanting to deal saving of drawings why are you using DocumentCollection.DocumentLockModeChanged Event and not Database.BeginSave Event
Can't find what you're looking for? Ask the community or share your knowledge.