Message 1 of 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have this piece of legacy code I'm trying to understand. When I want to insert something into a paperspace Layout I usually use Database.CurrentSpaceId or some other means of finding the Layout object. Then I open the Layout.BlockTableRecord and append the Entity.
But this code is using BlockTableRecord.Paperspace. I'm familiar with BlockTableRecord.Model, but how does the former work if there are multiple paperspace Layouts?
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
using (Transaction transaction = db.TransactionManager.StartOpenCloseTransaction())
using(BlockTable bt = transaction.GetObject(db.BlockTableId, OpenMode.ForRead, false, true) as BlockTable)
{
try
{
if (!(db.CurrentSpaceId == bt[BlockTableRecord.PaperSpace]))
{
doc.Editor.WriteMessage("\n You must be in paperspace to insert the Loop Schedule.");
transaction.Abort();
return;
}
Point3d insertPoint = GetInsertPoint();
Table tb = MakeTableObj(insertPoint);
using (BlockTableRecord btr =
transaction.GetObject(bt[BlockTableRecord.PaperSpace], OpenMode.ForWrite, false, true) as
BlockTableRecord)
{
btr.AppendEntity(tb);
transaction.AddNewlyCreatedDBObject(tb, true);
}
transaction.Commit();
}
catch (Exception ex)
{
transaction.Abort();
doc.Editor.WriteMessage($"Error in {nameof(MethodName)}: {ex.Message}");
}
}
Solved! Go to Solution.