.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Inserting an object into BlockTableRecord.Paperspace

1 REPLY 1
SOLVED
Reply
Message 1 of 2
nshupeFMPE3
114 Views, 1 Reply

Inserting an object into BlockTableRecord.Paperspace

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}");
    }
}

 

Labels (3)
1 REPLY 1
Message 2 of 2
_gile
in reply to: nshupeFMPE3

Hi,

 

A quick test would have shown you that, when called from a layout tab, PaperSpace refers to the active layout; when called from the model space, PaperSpace refers to the last closed layout, or the first layout tab if none has yet been opened.

In my opinion, unless the active space is a known layout, this property isn't very reliable, in which case I prefer CurrentSpaceId.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report