Howto get Space / Layout of object(id)

Howto get Space / Layout of object(id)

faceter
Participant Participant
1,207 Views
3 Replies
Message 1 of 4

Howto get Space / Layout of object(id)

faceter
Participant
Participant

Hello,

 

how can I get the Layout of an existing Entity (e.g. AttributeReference entity) ?

 

I have the AttributeReference object and can get it's ObjectID.

Is there a property or function to get the Layout of the object?

 

Thanks a lot for your help

 

nil

0 Likes
Accepted solutions (2)
1,208 Views
3 Replies
Replies (3)
Message 2 of 4

_gile
Consultant
Consultant
Accepted solution

Hi,

 

You can use the BlockId property of the entity to get ObjectId of the BlockTableRecord instance which owns the entity. It can be either a layout or a block definition.

If you need the Layout instance, you can check if its IsLayout property equals true and, then, get the Layout object with the BlockTableRecord.LayoutId property.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 4

faceter
Participant
Participant
Accepted solution

Thanks a lot

works fine.

 

nil

0 Likes
Message 4 of 4

BKSpurgeon
Collaborator
Collaborator
using (Transaction tr = db.TransactionManager.StartTransaction())
{
    Entity entity = tr.GetObject(id, OpenMode.ForRead) as Entity;                    
    BlockTableRecord btr = tr.GetObject(entity.BlockId, OpenMode.ForRead) as BlockTableRecord;

    if (btr.IsLayout)
    {

    }
    else
    {

    }

           

    tr.Commit();
}

 

some code demonstrating the above for a quick cut and paste.

 

All credit to Gilles for the answer.

 

 

0 Likes