Reputation: 2402
I want to display entities on a drawing area as a preview for the user, then if the user accepts the program, add the the entities to the database or make some modification.
I'm used to use transaction and commit the transaction the entities appear if i can make the entities appear before commit the transaction
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTable bt = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
BlockTableRecord btr = tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
int i = poly2TxtSetting.currentFormat.IndexFormat.startWith;
List<ObjectId> ListTextId = new List<ObjectId>();
List<ObjectId> ListPointId = new List<ObjectId>();
foreach (var po in Points)
{
i += poly2TxtSetting.currentFormat.IndexFormat.step;
DBText dtext = new DBText();
dtext.TextString = i.tostring();
dtext.Position = po;
dtext.SetDatabaseDefaults();
DBPoint point = new DBPoint(po);
btr.AppendEntity(dtext);
tr.AddNewlyCreatedDBObject(dtext, true);
btr.AppendEntity(point);
tr.AddNewlyCreatedDBObject(point, true);
}
tr.Commit();
}
Upvotes: 1
Views: 2838
Reputation: 186
If you want to display your model in AutoCAD model space, you have two options.
1) Insert it into database. 2) Add it into Transient Manager.
I think you need is 2nd option.
Search for Transient Graphics.
Check below Code that will help you.
Solid3d solid=new Solid(0);
solid.CreateSphere(10);
TransientManager.CurrentTransientManager.AddTransient(solid, TransientDrawingMode.Main, 128, new IntegerCollection());
This will display sphere on origin with radius=10;
Upvotes: 2
Reputation: 701
You can wait for the graphics flush:
tr.TransactionManager.QueueForGraphicsFlush();
then prompt for input so the user has time to see the update:
PromptKeywordOptions pko = new PromptKeywordOptions("\nKeep Changes?");
pko.AllowNone = true;
pko.Keywords.Add("Y");
pko.Keywords.Add("N");
pko.Keywords.Default = "Y";
PromptResult pkr = ed.GetKeywords(pko);
if (pkr.StringResult == "Y") {
tr.Commit();
} else {
tr.Abort();
}
This link provides an example application using this technique.
Upvotes: 1