Message 1 of 11
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Is the same Entity reference valid across nested transaction, all the time? I have code as such ( where I reuse not just the ObjectId of the line Entity, but also the entity itself).
[CommandMethod(nameof(NestedTransactions))]
public static void NestedTransactions()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
using (Transaction trOuter = db.TransactionManager.StartTransaction())
{
// Create a line
Line line = new Line(new Point3d(0, 0, 0), new Point3d(10, 0, 0));
var btr = (BlockTableRecord)trOuter.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
btr.AppendEntity(line);
trOuter.AddNewlyCreatedDBObject(line, true);
// Inner transaction 1: Change color
using (Transaction trInner1 = db.TransactionManager.StartTransaction())
{
line.ColorIndex = 1; // Red
trInner1.Commit();
}
// Inner transaction 2: Change layer
using (Transaction trInner2 = db.TransactionManager.StartTransaction())
{
line.Layer = "A-BLDG";
trInner2.Commit();
}
trOuter.Commit();
}
ed.Regen();
}
It works, but I'm not sure whether it's always safe to do this? or I have to use ObjectId and get the actual entity from the reigning Transaction ( since ObjectId is the same within the lifetime of the drawing)?
##########
Ngu Soon Hui
##########
I'm the Benevolent Dictator for Life for MiTS Software. Read more here
I also setup Civil WHIZ in order to share what I learnt about Civil 3D
Ngu Soon Hui
##########
I'm the Benevolent Dictator for Life for MiTS Software. Read more here
I also setup Civil WHIZ in order to share what I learnt about Civil 3D
Solved! Go to Solution.