.NET

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

Using CloseAndDiscard in a DocumentLockModeChanged event handler

160 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
Posts: 2
Registered: ‎10-01-2013
Message 2 of 4 (148 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: 221
Registered: ‎11-09-2012
Message 3 of 4 (115 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
Posts: 319
Registered: ‎05-12-2009
Message 4 of 4 (96 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

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Welcome to the new Autodesk Community!
If this is your first visit, click here to get started and make the most of the Community. Let us know what you think of the new experience in the Community Feedback Forum.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community