Author Topic: TransactionManager.QueueForGraphicsFlush  (Read 1134 times)

0 Members and 1 Guest are viewing this topic.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 10819
  • class keyThumper<T>:ILazy<T>
TransactionManager.QueueForGraphicsFlush
« on: September 08, 2009, 12:16:15 am »
spent some of the boss's time sorting this problem, so thought I'd quickly share it.

Inside a transaction newly added objects don't display until the transaction is committed and the transaction disposed.

So, if we automagically  draw a line and then prompt for a point ( inside the same transaction ) the line won't be on the screen.

This is also the case using nested transactions ...


BUT, TransactionManager.QueueForGraphicsFlush() appears to resolve the problem.

It can be called on either the Transaction Manager :-
trMan.QueueForGraphicsFlush();

or on the transaction :-
tr.TransactionManager.QueueForGraphicsFlush()


Here's a sample. Just comment out the line trMan.QueueForGraphicsFlush(); to see the original behaviour.


Code - C#: [Select]
  1.  
  2. //  CodeHimBelongaKdub
  3. //  [kdub 2009-09-08 12:37]
  4.  
  5.  
  6. [CommandMethod("DOIT10")]
  7. public static void Test_QueueForGraphicsFlush()
  8. {
  9.    // Get the current document and database
  10.    Document doc = AcadApp.DocumentManager.MdiActiveDocument;
  11.    Database db = doc.Database;
  12.  
  13.    // Create a reference to the
  14.    // Autodesk.AutoCAD.DatabaseServices Transaction Manager
  15.    AcDb.TransactionManager trMan = db.TransactionManager;
  16.  
  17.    // Start a transaction
  18.    using (Transaction tr = trMan.StartTransaction())
  19.    {
  20.        // Open the Block table for read
  21.        BlockTable bt;
  22.        bt = tr.GetObject(db.BlockTableId,
  23.                           OpenMode.ForRead) as BlockTable;
  24.  
  25.        // Open the Block table record Model space for write
  26.        BlockTableRecord btr;
  27.        btr = tr.GetObject(bt[BlockTableRecord.ModelSpace],
  28.                            OpenMode.ForWrite) as BlockTableRecord;
  29.  
  30.        // Create a line that starts at 50,50 and ends at 100,75
  31.        Line acLine1 = new Line(new Point3d(50, 50, 0),
  32.                                new Point3d(100, 75, 0));
  33.  
  34.        acLine1.SetDatabaseDefaults();
  35.  
  36.        // Add the new object to the block table record and the transaction
  37.        btr.AppendEntity(acLine1);
  38.        tr.AddNewlyCreatedDBObject(acLine1, true);
  39.  
  40.        // This line does the trick ...
  41.        // Shows the graphics inside the transaction.
  42.        // could use tr.TransactionManager.QueueForGraphicsFlush()
  43.        //
  44.        trMan.QueueForGraphicsFlush();
  45.  
  46.        // Getpoint
  47.        PromptPointResult pPtRes;
  48.        PromptPointOptions pPtOpts = new PromptPointOptions("");
  49.  
  50.        // Prompt for point
  51.        pPtOpts.Message = "\nEnter the start point of a New line: ";
  52.        pPtRes = doc.Editor.GetPoint(pPtOpts);
  53.        Point3d ptStart = pPtRes.Value;
  54.        //>>
  55.        // stuff happens here ....
  56.        //<<
  57.        // Save the new objects to the database
  58.        tr.Commit();
  59.  
  60.    }
  61. }
  62.  


enjoy,
Kerry


« Last Edit: August 03, 2012, 05:33:24 am by Kerry »
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate<--

Glenn R

  • Water Moccasin
  • Posts: 1932
  • What idiot child of married cousins wrote this?!
Re: TransactionManager.QueueForGraphicsFlush
« Reply #1 on: September 08, 2009, 05:35:47 am »
Nice one Kerry.
Me

Draftek

  • Swamp Rat
  • Posts: 1498
Re: TransactionManager.QueueForGraphicsFlush
« Reply #2 on: September 08, 2009, 08:12:42 am »
I have found this AcDbObject method useful as well in similar situations:

Acad::ErrorStatus closeAndPage(Adesk::Boolean onlyWhenClean = true);
Soli Deo Gloria

Chumplybum

  • Newt
  • Posts: 85
Re: TransactionManager.QueueForGraphicsFlush
« Reply #3 on: September 08, 2009, 06:20:04 pm »
you can also use entity.draw... this is taken from the acad_mgd help:
Quote
You can use AcTransactionManager::queueForGraphicsFlush() and AcTransactionManager::flushGraphics() to draw entities on demand even if they are associated with the transactions and some transactions are active, which would mean the modification on the entities is not committed to the database. AcTransactionManager::queueForGraphicsFlush() queues up all the eligible entities associated with all the transactions for graphics update and AcTransactionManager::flushGraphics() draws them. You can also use AcDbEntity::draw() to draw an individual entity. This helps you see a particular entity on the screen without waiting until the end of the outermost transaction when all the modifications to all the entities are drawn. Use AcTransactionManager::enableGraphicsFlush() to enable or disable the drawing of entities. When a command ends, you relinquish control of graphics generation and it is automatically enabled.

sinc

  • Gator
  • Posts: 3124
  • I think I cad...
Re: TransactionManager.QueueForGraphicsFlush
« Reply #4 on: September 08, 2009, 08:57:27 pm »
In a related vein, does anyone know how to flush output to the command line?
-- Sinc
Civil-3D 2012
http://www.ejsurveying.com
http://www.quuxsoft.com
Unleash Civil-3D with the Sincpac-C3D!