Author Topic: UndoCtl group bit set, new database  (Read 6201 times)

0 Members and 1 Guest are viewing this topic.

T.Willey

  • Needs a day job
  • Posts: 5251
UndoCtl group bit set, new database
« on: December 15, 2014, 12:31:38 PM »
I am working on some code for some, so I cannot post the code and I do not want to get into too much detail publicly, sorry.  I know that can be a problem when looking for help.

The issue:  when the user edits the drawing with regular AutoCAD commands, and then wants to undo one or two of them, they all get undo'ed to the point where the drawing was first opened.

I am copying a bunch of objects from the currently opened drawing to a new database, new Database( true, false ), using WblockCloneObjects.  I am then closing the current drawing, without saving, and opening my new drawing.  Within the new drawing the UndoCtl system variable is set to 13 upon opening, meaning that a group is active ( even ending the group does not seem to work ).  This issue only occurs the first time the program is ran.  It also disappears when you close the new drawing and open it up again through AutoCAD commands.

I have tried setting DisableUndoRecording to true/false and that does nothing.  I have not seen anything else to try, and I am at my wits end.

I will try an answer any questions here, so others can learn also.

Thanks in advance.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

owenwengerd

  • Bull Frog
  • Posts: 451
Re: UndoCtl group bit set, new database
« Reply #1 on: December 15, 2014, 01:02:28 PM »
This is usually related to performing database or editor actions from a modeless or application context (such as during a windows message handler, or during a reactor callback).

T.Willey

  • Needs a day job
  • Posts: 5251
Re: UndoCtl group bit set, new database
« Reply #2 on: December 15, 2014, 01:42:09 PM »
Thanks, Owen.  I do not edit either drawing while my dialog is open.  I use a 'using' statement, and it only exists for a short period of time to gather information for use later.  I do not use a reactor, so I would not think there is any editing happening unless AutoCAD is firing on its own.

I will investigate further to make sure I understand fully your advice.

Edit:  Forgot to mention that my dialog is a modal dialog.
« Last Edit: December 15, 2014, 02:39:27 PM by T.Willey »
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: UndoCtl group bit set, new database
« Reply #3 on: December 15, 2014, 04:11:08 PM »
If you are opening the new drawing after it's creation, why not create the new drawing within the document manager and let it create it in the editor?  I have no idea if that would affect your issue but I would try it and see if it makes a difference.
Revit 2019, AMEP 2019 64bit Win 10

owenwengerd

  • Bull Frog
  • Posts: 451
Re: UndoCtl group bit set, new database
« Reply #4 on: December 15, 2014, 05:58:42 PM »
In what context are you creating your modal dialog (CommandMethod/LispFunction/etc.)? Are you using Application.ShowModalDialog()?

The basic problems is that an internal AutoCAD state is not getting properly ended, and so the internal UNDO state thinks there is an operation ongoing. Even though you are not modifying the database, it's possible that the call to WblockCloneObjects has some bearing on the problem. I would try to narrow it down by removing small pieces until the problem disappears.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: UndoCtl group bit set, new database
« Reply #5 on: December 15, 2014, 06:13:18 PM »
If you are opening the new drawing after it's creation, why not create the new drawing within the document manager and let it create it in the editor?  I have no idea if that would affect your issue but I would try it and see if it makes a difference.

This would be a last resort, as the code is all written.  If I cannot make it work, then this is an option.  Thanks.

In what context are you creating your modal dialog (CommandMethod/LispFunction/etc.)? Are you using Application.ShowModalDialog()?

The basic problems is that an internal AutoCAD state is not getting properly ended, and so the internal UNDO state thinks there is an operation ongoing. Even though you are not modifying the database, it's possible that the call to WblockCloneObjects has some bearing on the problem. I would try to narrow it down by removing small pieces until the problem disappears.

It is a CommandMethod with the Session flag set.  I launch the dialog with just ShowDialog from an instance of the custom form.  I can start removing portions of the code to see if that helps.  Thanks.

This is just weird that it happens only on the first call of the program, and not something continuous.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Jeff H

  • Needs a day job
  • Posts: 6150
Re: UndoCtl group bit set, new database
« Reply #6 on: December 15, 2014, 06:29:25 PM »
Database( true, false ) -> with second argument as false associates database with current document and in session context I thought the outermost undo marks are when you locked and unlocked the document.




T.Willey

  • Needs a day job
  • Posts: 5251
Re: UndoCtl group bit set, new database
« Reply #7 on: December 15, 2014, 07:47:02 PM »
I tried Database( true, true) also, and got the same issue.  I will check again when I try to figure out where its going wrong.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

owenwengerd

  • Bull Frog
  • Posts: 451
Re: UndoCtl group bit set, new database
« Reply #8 on: December 15, 2014, 08:19:23 PM »
It is a CommandMethod with the Session flag set.  I launch the dialog with just ShowDialog from an instance of the custom form.

Calling ShowDialog() is a bad idea, and very possibly the reason you're having problems. In any case, you should always use Application.ShowModalDialog().

T.Willey

  • Needs a day job
  • Posts: 5251
Re: UndoCtl group bit set, new database
« Reply #9 on: December 16, 2014, 12:45:10 AM »
Owen, thanks for the tip about ShowDialog.  That is how I have always called a dialog.  I will change from now on.


The issue seems to arise from a call to trans.AddNewlyCreatedDBObject( obj, true );.  If I comment this out, then the UndoCtl variable is set to 5, and undo's proceed like they should.  If I leave it commented out though, I receive an error of eWasOpenForWrite on the call to WblockCloneObjects, but only when selecting certain objects.

The situation:  I am exploding blocks and if their contents meet certain requirements, then they are added to the current database, with the ability to be copied to the new database.  I append the objects, as an entity, to the owner BlockTableRecord, and then call trans.AddNewlyCreatedDBObject( obj, true ).

I have some testing to do tomorrow, but am calling a quits for the night.

Thank you everyone for the tips and pointers.  They are very much appreciated.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

nekitip

  • Guest
Re: UndoCtl group bit set, new database
« Reply #10 on: December 16, 2014, 05:34:37 AM »
I'm sure you have tested this, but is it possible that you have some transaction somewhere open the whole time?

T.Willey

  • Needs a day job
  • Posts: 5251
Re: UndoCtl group bit set, new database
« Reply #11 on: December 16, 2014, 10:11:26 AM »
I'm sure you have tested this, but is it possible that you have some transaction somewhere open the whole time?

It does not look like it.  I use transactions only with 'using' statements.  Thanks for the idea.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Jeff H

  • Needs a day job
  • Posts: 6150
Re: UndoCtl group bit set, new database
« Reply #12 on: December 16, 2014, 01:00:50 PM »
If a command is used to open the dialog then wouldn't anything done while that dialog is opened be nested inside its undo marks?

Think should only be for commands that do not modify database but you have NoUndoMarker CommandFlag.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: UndoCtl group bit set, new database
« Reply #13 on: December 16, 2014, 02:51:35 PM »
If a command is used to open the dialog then wouldn't anything done while that dialog is opened be nested inside its undo marks?

Think should only be for commands that do not modify database but you have NoUndoMarker CommandFlag.

I check the system variable UndoCtl while my command is active, and it returns 5 ( meaning a group is not active ), so it does not look like the variable is getting set in my current document and carrying over to the newly created one.

I also just tried setting the CommandFlags to NoUndoMarker, and that did not solve the problem, which I am kind of glad about.

I will continue to investigate this today, but right now it is lunch time.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: UndoCtl group bit set, new database
« Reply #14 on: December 16, 2014, 05:41:22 PM »
The real issue seems that the current document is busy with something.  If I do not close it, then it the UndoCtl system variable is correctly set.  If I try and close it after I open the new drawing in the editor, then I get a message saying the drawing is busy.

Now to find where the document can be hanging up.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.