V12.Net API: How to get and entity by its handle?

Hello all,

 

I've  started to play around with the .NET API in V12 (using C#) and run into following challenge:

How do I get reference to an entity if I know its handle?

Actually I look for a specific Paperspace Viewport (by its handle)

Do I have to cycle the Paperspace block (using a BlockTableRecordEnumerator) until I find an entity with the correct handle or is there a quicker way?

Huge amount to (re) discover after 10 years playing with COM!

T.I.A.

Arno van Eeuwen

 

Comments

  • On with the .NET quest...

     

     Document doc = AcAp.Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor editor = doc.Editor;  try {   long ln = Convert.ToInt64(rxConfig.Handle, 16);   Handle hn = new Handle(ln);   ObjectId id = db.GetObjectId(false, hn, 0);             using (Transaction tr = db.TransactionManager.StartTransaction())   {      Entity ent = (Entity)tr.GetObject(id, OpenMode.ForRead);
          Some more code here....    }       

    Now in my case the entity I try to acces using the above code lays on a locked layer.

    The GetObject fails....

    So: how to make sure to unlock the layer of an entity when I only know it's ID?

    TIA

     

  • Transaction::GetObject has an overload, forceOpenOnLockedLayer.... the signature should be

     

    public virtual DBObject GetObject(ObjectId id, OpenMode mode, bool openErased, bool forceOpenOnLockedLayer);

     

    give that a whirl and see what happens

    Cheers!

  • Why are you not in the pub celebrating your birthday? ;-)

    Ah, you brought you own from Belgium!

    Thanks Dan, another mistery solved. As I said, loads to discover.....

     

     

  • I'm headed to the pub now : )

This discussion has been closed.