.NET

Reply
New Member
terjeber
Posts: 2
Registered: ‎10-01-2013
Message 1 of 4 (191 Views)

Using CloseAndDiscard in a DocumentLockModeChanged event handler

191 Views, 3 Replies
10-02-2013 07:03 AM

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.

New Member
terjeber
Posts: 2
Registered: ‎10-01-2013
Message 2 of 4 (179 Views)

And then I found a solution

10-02-2013 07:18 AM in reply to: terjeber

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

Mentor
mzakiralam
Posts: 231
Registered: ‎11-09-2012
Message 3 of 4 (146 Views)

Re: And then I found a solution

10-03-2013 12:57 AM in reply to: terjeber

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.

 

 

Valued Mentor
jeff
Posts: 330
Registered: ‎05-12-2009
Message 4 of 4 (127 Views)

Re: And then I found a solution

10-03-2013 08:53 AM in reply to: mzakiralam

Out of curiousity if you are wanting to deal saving of drawings why are you using DocumentCollection.DocumentLockModeChanged Event and not Database.BeginSave Event

You can also find your answers @ TheSwamp
Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.