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

0 Members and 1 Guest are viewing this topic.

mohnston

  • Bull Frog
  • Posts: 305
  • CAD Programmer
Document "xxx.dwg" has a command in progress.
« on: January 22, 2007, 06:07:54 PM »
I have a .NET app that shows a modeless dialog which is a customized print application.
It works fine except when I try to use the "qsave" command on the drawing after plotting or previewing it.
I get a message at the command line:
Document "xxx.dwg" has a command in progress.

Other commands such as Line, Copy, Move etc. work fine. Even the "Save" command works.

I've searched and read every post I could find on this subject including some in Russian (which may have lost something in the translation to English).

Is there some way to tell the Document that it doesn't have a command in progress?
I don't want to "SendCommand" since the only command that seems to shake the document free is "Save". I don't think it's good manners to save a drawing without the users permission. It's also kind of rude to make them save the drawing when all they did was print it.

Any help?
It's amazing what you can do when you don't know what you can't do.
CAD Programming Solutions

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Document "xxx.dwg" has a command in progress.
« Reply #1 on: January 22, 2007, 06:28:42 PM »
That sounds weird !

I have no ideas.

.. so this is redundant I 'spose , except to let you know that someone read the post and cares.

« Last Edit: January 22, 2007, 06:30:11 PM by Kerry Brown »
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.

uncoolperson

  • Guest
Re: Document "xxx.dwg" has a command in progress.
« Reply #2 on: January 22, 2007, 06:42:17 PM »
i was told to do something like this so i wouldn't have a problem like you describe... as far as what IsQuiescent is/does.... no idea other http://dictionary.reference.com/browse/Quiescent

Code: [Select]
            AutoCAD.AcadApplicationClass blah = new AutoCAD.AcadApplicationClass();
                AcadState oState = blah.GetAcadState();
                while (!oState.IsQuiescent)
                {
                }
[/s]

I read too fast.... i was having the same issue... gave up on not saving, and since i'm the only one to use my big happy batch program i just place a copy of the directory to be printed on my computer, screw with it (usually print) then get rid of it.... my network sucks so this is a better idea even for changing something in the drawing.
« Last Edit: January 22, 2007, 06:53:25 PM by uncoolperson »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Document "xxx.dwg" has a command in progress.
« Reply #3 on: January 22, 2007, 06:51:27 PM »
The  oState.IsQuiescent 'Gets true if there is no command, LISP script, or ARX command active; otherwise, it gets false.'

ie like the CMDACTIVE getvar ..

.. it has no .set option ie it's read only.
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 #4 on: January 22, 2007, 06:53:02 PM »
UCP, good to see you posting in the NET topics!  :-)
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.

uncoolperson

  • Guest
Re: Document "xxx.dwg" has a command in progress.
« Reply #5 on: January 22, 2007, 06:58:07 PM »
UCP, good to see you posting in the NET topics!  :-)

I'll make problems, you fix em..... deal?

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Document "xxx.dwg" has a command in progress.
« Reply #6 on: January 22, 2007, 07:01:35 PM »
UCP, good to see you posting in the NET topics!  :-)

I'll make problems, you fix em..... deal?

I promise  :lmao:
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 #7 on: January 22, 2007, 08:08:08 PM »
I had already tried "IsQuiescent".
I doesn't work in this situation. It isn't a matter of syncronicity. (POLICE!)
IsQuiescent never gets true.
Somehow the state of the active document is misreported.

It's amazing what you can do when you don't know what you can't do.
CAD Programming Solutions

uncoolperson

  • Guest
Re: Document "xxx.dwg" has a command in progress.
« Reply #8 on: January 22, 2007, 09:01:41 PM »
command line, as in the one in autocad... if not continue reading, else... i don't know yet.

blah being AutoCAD.AcadApplicationClass from above


have you tried
Code: [Select]
                blah.Visible = true;, to show what autocad is saying... my problem was i couldn't get it to not complain about saving the document.

Bryco

  • Water Moccasin
  • Posts: 1883
Re: Document "xxx.dwg" has a command in progress.
« Reply #9 on: January 22, 2007, 11:53:02 PM »
I've had that problem in regular cad (cad2000)
Quote
Document "xxx.dwg" has a command in progress
and never figured out what caused it. It seemed to happen in dwgs with layer and spatial indexing, or 3d but I never figured it out. I seem to remember Hit/Retry was an option.
I've also heard that acad2006 and 7 have some issues with printers. We just bought a new copier/printer and it ended up using/leaking  so much resourses the undo command , pljoin and a couple of others were taking forever. Looking at the task manager cad was using double what it normally was. It may be worth looking at your mem usage.

Big G

  • Bull Frog
  • Posts: 415
Re: Document "xxx.dwg" has a command in progress.
« Reply #10 on: January 23, 2007, 12:16:33 AM »
we use a few "add-on" packages here and i get this quite a bit too.....the only fix i have found is to type "EXIT" and when it asks you to save CANCEL it....qsave will work fine then?

as to what causes it.....no ideas!

I thought i seen the light at the end of the tunnel. But it was just someone with a torch bringing me more work.
"You have to accept that somedays youre the pigeon and  somedays youre the statue"

Glenn R

  • Guest
Re: Document "xxx.dwg" has a command in progress.
« Reply #11 on: January 23, 2007, 01:33:57 AM »
You said you have a modeless dialog...are you locking the document when you do your mojo...if so, are you UNLOCKING it afterward...???

From memory, IsQuescient is for out of process communication (ie COM controllers)......

Cheers,
Glenn.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Document "xxx.dwg" has a command in progress.
« Reply #12 on: January 23, 2007, 01:39:33 AM »
You said you have a modeless dialog...are you locking the document when you do your mojo...if so, are you UNLOCKING it afterward...???

From memory, IsQuescient is for out of process communication (ie COM controllers)......

Cheers,
Glenn.

Hi Glenn, I was going to suggest dockumentLocking, but the ability to make changes to the DB [ commands such as Line, Copy, Move etc. ] caused to to back off the idea.  .... but you may be correct anyway :-)
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.

Alexander Rivilis

  • Bull Frog
  • Posts: 214
  • Programmer from Kyiv (Ukraine)
Re: Document "xxx.dwg" has a command in progress.
« Reply #13 on: January 23, 2007, 05:41:50 AM »
The same situation: http://www.autocad.ru/cgi-bin/f1/board.cgi?t=32048VX (sorry but in Russian). UNLOCKING document before save it must help you.

mohnston

  • Bull Frog
  • Posts: 305
  • CAD Programmer
Re: Document "xxx.dwg" has a command in progress.
« Reply #14 on: January 23, 2007, 10:39:08 AM »
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?"
It's amazing what you can do when you don't know what you can't do.
CAD Programming Solutions

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: 3636
  • (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.
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

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