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.
// CodeHimBelongaKdub
// [kdub 2009-09-08 12:37]
[CommandMethod("DOIT10")]
public static void Test_QueueForGraphicsFlush()
{
// Get the current document and database
Document doc = AcadApp.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
// Create a reference to the
// Autodesk.AutoCAD.DatabaseServices Transaction Manager
AcDb.TransactionManager trMan = db.TransactionManager;
// Start a transaction
using (Transaction tr = trMan.StartTransaction())
{
// Open the Block table for read
BlockTable bt;
bt = tr.GetObject(db.BlockTableId,
OpenMode.ForRead) as BlockTable;
// Open the Block table record Model space for write
BlockTableRecord btr;
btr = tr.GetObject(bt[BlockTableRecord.ModelSpace],
OpenMode.ForWrite) as BlockTableRecord;
// Create a line that starts at 50,50 and ends at 100,75
Line acLine1
= new Line
(new Point3d
(50,
50,
0),
new Point3d
(100,
75,
0));
acLine1.SetDatabaseDefaults();
// Add the new object to the block table record and the transaction
btr.AppendEntity(acLine1);
tr.AddNewlyCreatedDBObject(acLine1, true);
// This line does the trick ...
// Shows the graphics inside the transaction.
// could use tr.TransactionManager.QueueForGraphicsFlush()
//
trMan.QueueForGraphicsFlush();
// Getpoint
PromptPointResult pPtRes;
PromptPointOptions pPtOpts
= new PromptPointOptions
("");
// Prompt for point
pPtOpts.Message = "\nEnter the start point of a New line: ";
pPtRes = doc.Editor.GetPoint(pPtOpts);
Point3d ptStart = pPtRes.Value;
//>>
// stuff happens here ....
//<<
// Save the new objects to the database
tr.Commit();
}
}
enjoy,
Kerry