Author Topic: Need To Disable Undo Recording  (Read 160 times)

0 Members and 1 Guest are viewing this topic.

CrockettScience

  • Mosquito
  • Posts: 3
Need To Disable Undo Recording
« on: March 13, 2019, 08:32:17 PM »
Our .NET plugin for AutoCAD 2018 has certain event handlers that call Editor.CommandAsync() on certain other hidden commands that we made. The system works fine except that if the user hits undo after such an event fires, the called commands are captured in the undo stack.

Our events handlers already have subscriptions to certain undo events, so I'd like to just disable recording outside commands for these calls.

Database.DisableUndoRecording(true) must just be broke or something. Literally nothing happens there. I've tried CommandFlags.NoUndoMarker, but it makes no difference. That may be because we're opening a transaction and modifying the database in these calls.

Anyone have any suggestions or insights?

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 6905
  • AKA Daniel
Re: Need To Disable Undo Recording
« Reply #1 on: March 13, 2019, 10:01:38 PM »
Hi,

Welcome to the swamp  :evil:

try using OpenCloseTransaction

CrockettScience

  • Mosquito
  • Posts: 3
Re: Need To Disable Undo Recording
« Reply #2 on: March 14, 2019, 01:24:06 PM »
I tried that too. No change.

That's worked for some other people elsewhere, but doesn't seem to change anything in my specific instance. Is there something underneath the surface of that kind of transaction that might break it? What exactly is the significance of Undo's and Transactions?

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 6905
  • AKA Daniel
Re: Need To Disable Undo Recording
« Reply #3 on: March 15, 2019, 05:53:39 AM »
this works in bricscad . You donít have to use a transaction, you just have to ensure dbobjects are disposed, easily done with a using statement

Code - C#: [Select]
  1.        [CommandMethod("doit", CommandFlags.NoUndoMarker)]
  2.        public void CreateTableFormul()
  3.        {
  4.            Document doc = Application.DocumentManager.MdiActiveDocument;
  5.            Database db = doc.Database;
  6.            Editor ed = doc.Editor;
  7.  
  8.           ObjectId ModelSpaceId = SymbolUtilityServices.GetBlockModelSpaceId(db);
  9.           using  (BlockTableRecord btr = ModelSpaceId.Open(OpenMode.ForRead) as BlockTableRecord)
  10.           {
  11.               db.DisableUndoRecording(true);
  12.               foreach(var id in btr)
  13.               {
  14.                   using(Entity ent = id.Open(OpenMode.ForWrite) as Entity)
  15.                   {
  16.                       ent.Layer = "0";
  17.                   }
  18.               }
  19.               db.DisableUndoRecording(false);
  20.           }
  21.        }
  22.  
  23.  


edit kdub: code type changed.
« Last Edit: March 15, 2019, 06:18:21 AM by kdub »

CrockettScience

  • Mosquito
  • Posts: 3
Re: Need To Disable Undo Recording
« Reply #4 on: March 18, 2019, 04:58:51 PM »
That's a good idea, let me try that. Whether or not that fixes it, that's useful to implement now because of the ease in flexibility, my only concern is with Transaction.AddNewlyCreatedDBObject(), which we have a couple cases of creating simple blocks. Is there a way to add objects to the database without a transaction as well, or is it necessary to use a transaction then?

Edit: Scratch that, it appears that AddNewlyCreatedDBObject() just adds db objects that were newly created To the Transaction, not the database.

Will get back on whether this fixes undo recording issue.
« Last Edit: March 18, 2019, 05:06:39 PM by CrockettScience »

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 6905
  • AKA Daniel
Re: Need To Disable Undo Recording
« Reply #5 on: March 18, 2019, 09:15:57 PM »
...Scratch that, it appears that AddNewlyCreatedDBObject() just adds db objects that were newly created To the Transaction, not the database.

Right AddNewlyCreatedDBObject() should have been named RegisterForDisposal()  :laugh: