Author Topic: Document "xxx.dwg" has a command in progress.  (Read 14141 times)

0 Members and 1 Guest are viewing this topic.

Draftek

  • Guest
Re: Document "xxx.dwg" has a command in progress.
« Reply #15 on: January 23, 2007, 10:56:53 AM »
I've had the same problem with different types of apps.

When we ran a command from a toolPalette.
When the command was static and running in MDI
when a variable to hold something related to the database was static.

Me thinks some memory alocation related to the current document is not being disposed.

If you get that unlock document thingy to work, I sure would like to see it.

Thanks.

Bobby C. Jones

  • Swamp Rat
  • Posts: 516
  • Cry havoc and let loose the dogs of war.
Re: Document "xxx.dwg" has a command in progress.
« Reply #16 on: January 23, 2007, 11:14:21 AM »
I guess this question is now "How do you UnLock a Locked document?"

In 2007 you dispose of the lock, like your code shows.  In '06 it was slightly different, but I don't recall the process off the top of my head.
Bobby C. Jones

mohnston

  • Bull Frog
  • Posts: 305
  • CAD Programmer
Re: Document "xxx.dwg" has a command in progress.
« Reply #17 on: January 23, 2007, 11:30:21 AM »
I have also tried this at the beginning:
Code: [Select]
Document ThisDrawing = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
DocumentLock dLock = ThisDrawing.LockDocument();
And this at the end:
Code: [Select]
dLock.Dispose();

That method worked fine once I moved the Dispose closer to the Lock.
I ended up Disposing the lock immediately after making the changes I wanted to the database.
It's amazing what you can do when you don't know what you can't do.
CAD Programming Solutions

Chuck Gabriel

  • Guest
Re: Document "xxx.dwg" has a command in progress.
« Reply #18 on: January 23, 2007, 12:27:09 PM »
Alexander, the solution you point to is the one I referred to in my original post. I tried running the posts through Googles translator but only understood about half.

I do lock the document at the beginning of the function.
Code: [Select]
Document ThisDrawing = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
ThisDrawing.LockDocument();
Then at the end of the function.
Code: [Select]
ThisDrawing.LockDocument(DocumentLockMode.NotLocked, string.Empty, string.Empty, false);

I have also tried this at the beginning:
Code: [Select]
Document ThisDrawing = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
DocumentLock dLock = ThisDrawing.LockDocument();
And this at the end:
Code: [Select]
dLock.Dispose();

I guess this question is now "How do you UnLock a Locked document?"

In unmanaged ObjectARX, it would unlock when your dLock variable went out of scope.  I'm not sure if the managed version uses the same paradigm, though.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Document "xxx.dwg" has a command in progress.
« Reply #19 on: January 23, 2007, 04:37:30 PM »
LockDocument is covered in the Labs

.. Lab 6 I think.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Document "xxx.dwg" has a command in progress.
« Reply #20 on: January 23, 2007, 04:39:12 PM »
Yep.
Quote
... Notice we keep a copy of the ‘DocumentLock’ object.  In order to unlock the document, we simply dispose DocumentLock object returned on the original lock request.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Document "xxx.dwg" has a command in progress.
« Reply #21 on: January 23, 2007, 05:35:47 PM »
.........
In unmanaged ObjectARX, it would unlock when your dLock variable went out of scope.  I'm not sure if the managed version uses the same paradigm, though.

This could be tested by stepping through the code in the debugger with a 'locals' window open.
If .Dispose IS needed, it may be an idea to include it in a try/finally block or wrap it in a using block for the DocumentLock.


... interesting topic. I look forward to hearing the results.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

mohnston

  • Bull Frog
  • Posts: 305
  • CAD Programmer
Re: Document "xxx.dwg" has a command in progress.
« Reply #22 on: January 23, 2007, 05:56:23 PM »
What I posted in #17 solved my problem. Thanks to all.

Some of the frustration (and strangely enough the fun) with programming is that some things don't make sense.
For example, why have a LockDocument but not an UnLockDocument? "Dispose" certainly isn't intuitive even in the context of C# programming.
And why is it you create a DocumentLock object by calling LockDocument? Shouldn't it be ThisDrawing.DocumentLock()?

And if we are stuck with LockDocument why not make it a property? LockDocument(bool LockIt).
Then we can just call it:
ThisDrawing.LockDocument(true);
// do my stuff here
ThisDrawing.LockDocument(false);

 :realmad: :ugly: :| :cry: :x

Ok, I feel better now.
It's amazing what you can do when you don't know what you can't do.
CAD Programming Solutions

Glenn R

  • Guest
Re: Document "xxx.dwg" has a command in progress.
« Reply #23 on: January 23, 2007, 06:01:29 PM »
This is typically how I do it in C#:
Code: [Select]
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
using (DocumentLock docLocker = doc.LockDocument())
{
    // Do your mojo here
}// using ends and 'docLocker' goes out of scope and is automagically 'disposed' of

Cheers,
Glenn.

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: Document "xxx.dwg" has a command in progress.
« Reply #24 on: January 23, 2007, 06:04:47 PM »
'Dispose' is an OOP paradigm that saves some typing such as 'UnlockDoc' for example, in Dispose (the destructor of your class) is where you put your clean up code.
Dispose should be called when the class goes out of scope but I have noticed that in .net you still have to call it occasionally. It's probably something to do with garbage collection, sometimes objects can hang around until the gc'r cleans them up which when mixing managed/unmanaged (i.e. wrappers) may be leaving objects 'open' which is causing the trouble, only a guess though.
"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Document "xxx.dwg" has a command in progress.
« Reply #25 on: January 23, 2007, 06:13:57 PM »
And why is it you create a DocumentLock object by calling LockDocument? Shouldn't it be ThisDrawing.DocumentLock()?

......
Ok, I feel better now.

Probably something to do with grammar ... a noun / Verb thing. Types are nouns, methods are verbs .. just a W.A.G.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.