Author Topic: Get Object by ObjectID String  (Read 1562 times)

0 Members and 1 Guest are viewing this topic.

nobody

  • Swamp Rat
  • Posts: 861
  • .net stuff
Get Object by ObjectID String
« on: August 26, 2015, 04:04:49 AM »
I need a way to reselect an object but all I have is the string of the object ID... (eg 85760...)

Basically I stored the objectID in a datatable as a string and need to use it later in the routine. 

Is the only way to do this iterating through every object in the drawing and checking it's id?

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: Get Object by ObjectID String
« Reply #1 on: August 26, 2015, 04:12:17 AM »
Are you sure you need an ObjectId instead of a handle?
Quote from: Autodesk
Handles are persistent between AutoCAD sessions, so they are the best way of accessing objects if you need to export drawing information to an external file which might later need to be used to update the drawing. The ObjectId of an object in a database exists only while the database is loaded into memory. Once the database is closed, the Object Ids assigned to an object no longer exist and maybe different the next time the database is opened.
« Last Edit: August 26, 2015, 04:21:57 AM by Andrey Bushman »

nobody

  • Swamp Rat
  • Posts: 861
  • .net stuff
Re: Get Object by ObjectID String
« Reply #2 on: August 26, 2015, 04:16:55 AM »
About 2 seconds ahead of me. Thanks! I did switch to handle based on this:

http://through-the-interface.typepad.com/through_the_interface/2007/02/getting_access_.html

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: Get Object by ObjectID String
« Reply #3 on: August 26, 2015, 04:18:40 AM »
For a handle:
Code - C#: [Select]
  1. Handle h = new Handle(i); // The i variable is Int64 value of the handle
  2. ObjectId id = ObjectId.Null;
  3. Boolean parseResult = db.TryGetObjectId(h, out id); // db is Database
  4. if (parseResult) {
  5.   // Here you can use id...
  6. }