Author Topic: How to get the type of an entity by its ObjectId?  (Read 2764 times)

0 Members and 1 Guest are viewing this topic.

csharpbird

  • Newt
  • Posts: 64
How to get the type of an entity by its ObjectId?
« on: October 23, 2009, 09:43:19 AM »
How to get the type of an entity by its ObjectId?

fixo

  • Guest
Re: How to get the type of an entity by its ObjectId?
« Reply #1 on: October 23, 2009, 11:04:32 AM »
How to get the type of an entity by its ObjectId?
Code: [Select]
ent.GetRXClass().DxfName
~'J'~

sinc

  • Guest
Re: How to get the type of an entity by its ObjectId?
« Reply #2 on: October 23, 2009, 04:17:14 PM »
That's not a good method.  Autodesk has stopped using DXF codes, and they are bad to use for anything anymore, except maybe basic Lisp customization of the core product.

It's something like this (typed blindly into the webpage, without benefit of Intellisense):

Code: [Select]
Type T;
using (Transaction tr = HostApplicationServices.TransactionManager.StartTransaction())
{
    DBObject obj = tr.GetObject(objectid, OpenMode.ForRead);
    T = obj.GetType();
    tr.Commit();
}

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8728
  • AKA Daniel
Re: How to get the type of an entity by its ObjectId?
« Reply #3 on: October 24, 2009, 07:48:13 AM »
Sinc,

I think the whole idea behind ObjectId::ObjectClass is to avoid the overhead of  transactions to test types

i.e
Code: [Select]
AcAp.Document activeDocument = AcAp.Application.DocumentManager.MdiActiveDocument;
AcEd.Editor editor = activeDocument.Editor;
ObjectId id = editor.GetEntity("get").ObjectId;
editor.WriteMessage("\n{0}", id.ObjectClass.Name);
editor.WriteMessage("\n{0}", id.ObjectClass.IsDerivedFrom(RXObject.GetClass(typeof(Curve)))

sinc

  • Guest
Re: How to get the type of an entity by its ObjectId?
« Reply #4 on: October 24, 2009, 11:01:14 AM »
Ah OK...  I hadn't found that method yet.  It actually gets the RXClass from the ObjectId without getting the object at all, not even internally in some hidden fashion?  If so, there's actually one thing I might be able to use that for, now that I think about it...  (Usually I need to get the object itself, too, because I'm working with the object, but I believe I have one case where I only need to know the types without getting the objects.)

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8728
  • AKA Daniel
Re: How to get the type of an entity by its ObjectId?
« Reply #5 on: October 24, 2009, 11:29:16 AM »
..It actually gets the RXClass from the ObjectId without getting the object at all, not even internally in some hidden fashion? ..

I assume the wrapper is opening the DBObject kForRead just long enough to get the RxClass. 

..Usually I need to get the object itself, too, because I'm working with the object ..

Same here :-)