Author Topic: How to update entity if all I have is ObjectID #?  (Read 4821 times)

0 Members and 1 Guest are viewing this topic.

Viktor

  • Guest
How to update entity if all I have is ObjectID #?
« on: September 24, 2009, 11:39:14 PM »
Is it possible to recreate an objectID? I have an attribute reference that I want to update, instead of searching for the block everytime and then finding the right attribute, when I read the attribute I get the objectID.OldIdPtr and store it while the user is doing other things. Then when the user wants to udpate the attribute, I want to be able to recreate the objectID and then just tr.getobject(objID,.... and update the attribute that way.

Am I way off on this? I thought of storing the entire objectID object, but the problem is that if the user wants to save and close, then I store all information in a xml file, and I can't store the entire objectID object in xml, I can only store the "id".

Any help would be appreciated.

I did try this:

Dim id As New IntPtr(Convert.ToInt32(ObjIDStr))
Dim ObjID As New ObjectId(id)

But that sets the OldId, and all the rest of the properties say something about corrupt memory...

Thanks,
Viktor.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8696
  • AKA Daniel
Re: How to update entity if all I have is ObjectID #?
« Reply #1 on: September 25, 2009, 12:05:24 AM »
Try storing the handle instead of the ID

ObjectId.Handle

Glenn R

  • Guest
Re: How to update entity if all I have is ObjectID #?
« Reply #2 on: September 25, 2009, 04:14:40 AM »
I would also store the FingerPrintGuid for the database as well. Between the handle, as Dan suggested and the guid, you should be good to go.

sinc

  • Guest
Re: How to update entity if all I have is ObjectID #?
« Reply #3 on: September 25, 2009, 08:06:54 AM »
There is also another option.  Instead of writing this information to an external XML file, you can also write it to the Named Object Dictionary.  Just use the ObjectId, and write it to the NOD using type DxfCode.SoftPointerId.  This way, Autocad will automatically give you the correct ObjectId when you start up again.

The benefit to this method is that it doesn't create a separate, external file, and all the information stays inside the drawing.  This avoids the problem of the DWG and XML files getting separated, or of the user "breaking" things by editing the XML file in a text editor.  Although, of course, sometimes you may have some other specific reason to prefer using an external XML file.

Viktor

  • Guest
Re: How to update entity if all I have is ObjectID #?
« Reply #4 on: September 28, 2009, 01:54:20 PM »
There is also another option.  Instead of writing this information to an external XML file, you can also write it to the Named Object Dictionary.  Just use the ObjectId, and write it to the NOD using type DxfCode.SoftPointerId.  This way, Autocad will automatically give you the correct ObjectId when you start up again.

The benefit to this method is that it doesn't create a separate, external file, and all the information stays inside the drawing.  This avoids the problem of the DWG and XML files getting separated, or of the user "breaking" things by editing the XML file in a text editor.  Although, of course, sometimes you may have some other specific reason to prefer using an external XML file.

Yea, in my case, the xml file stores a bunch of other audit information that would get sent to the drafter that is doing work on the files. So XML is imminent. The point is that the file gets checked by one individual using this program, he can add comments to the problems found, then send the xml file back and the drafter can load the xml file back into the program, see the comments, fix the problems, add his/her own comments, etc.

Now, to answer the posts before this one:

I will give it a shot and post back.

Viktor

  • Guest
Re: How to update entity if all I have is ObjectID #?
« Reply #5 on: September 28, 2009, 04:36:08 PM »
Try storing the handle instead of the ID

ObjectId.Handle

Well, how do I set the handle? its a read-only property. I can get the value, but I can't set the value either. Are you talking about using the handle to itterate all the object id's until the handle is found?

Viktor

  • Guest
Re: How to update entity if all I have is ObjectID #?
« Reply #6 on: September 28, 2009, 04:38:04 PM »
I would also store the FingerPrintGuid for the database as well. Between the handle, as Dan suggested and the guid, you should be good to go.

FingetPrintGuid is on the database level though isn't it? How will this help getting the object by objectID?

sinc

  • Guest
Re: How to update entity if all I have is ObjectID #?
« Reply #7 on: September 28, 2009, 05:41:49 PM »
The handle cannot be changed.  That's the whole point of the handle - it is assigned when the entity is first created, and it never changes.

I'm not really sure what you're doing, but it's starting to sound like you're going to an awful lot of trouble...  Are you sure it's all necessary?  A lot of times, when things get as convoluted as this is beginning to sound, there's a much simpler route...

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8696
  • AKA Daniel
Re: How to update entity if all I have is ObjectID #?
« Reply #8 on: September 28, 2009, 07:12:25 PM »
Try storing the handle instead of the ID

ObjectId.Handle

Well, how do I set the handle? its a read-only property. I can get the value, but I can't set the value either. Are you talking about using the handle to itterate all the object id's until the handle is found?

Use Database::GetObjectId() to get the ObjectId from the handle

Viktor

  • Guest
Re: How to update entity if all I have is ObjectID #?
« Reply #9 on: September 28, 2009, 07:19:23 PM »
Try storing the handle instead of the ID

ObjectId.Handle

Well, how do I set the handle? its a read-only property. I can get the value, but I can't set the value either. Are you talking about using the handle to itterate all the object id's until the handle is found?

Use Database::GetObjectId() to get the ObjectId from the handle

And that is the answer! Sorry, I misunderstood on how you meant I use the handle. This is also the answer I got from ADN:

Quote
To store a reference to an object between AutoCAD sessions, you should store the Handle. (Handle + DWG path is a unique identifier). You can then retrieve the (session-specific) ObjectId using the Database.GetObjectId method.


The Handle.Value property returns a long that you can store and then use in the Handle constructor to recreate the Handle in your next session.


Viktor

  • Guest
Re: How to update entity if all I have is ObjectID #?
« Reply #10 on: September 28, 2009, 07:26:20 PM »
The handle cannot be changed.  That's the whole point of the handle - it is assigned when the entity is first created, and it never changes.

I'm not really sure what you're doing, but it's starting to sound like you're going to an awful lot of trouble...  Are you sure it's all necessary?  A lot of times, when things get as convoluted as this is beginning to sound, there's a much simpler route...

Sinc, i sure hope it isn't too complicated, I can just write it off on my poor ability to communicate the issue or idea. Overall, this is a rather simple application, something that Autodesk needs to include in AutoCad. Basically, its a "Rule based Auditor". So I have a table in our standards database that cad manager can add all kinds of rules to. Things like, a block with a certain name can only be at such an insertion and on such a layer, etc. Then an auditor checks the drawing for rule violations. We need this sort of thing because over 70% of our work is done by outside consultants, which are not always eager to follow our standards. This way, we can catch the violations easily, add comments, and send it back to them for review.

Currently, we use Design Review to do the marking up of the drawings and sending them back, but it is a very laborous task to check this many files for standards integrity.

Being able to retrieve an object without reitterating the drawing is a big plus because now a change can be done with no noticable delay.

Hope that makes sense.

Viktor.

Viktor

  • Guest
Re: How to update entity if all I have is ObjectID #?
« Reply #11 on: September 28, 2009, 07:27:36 PM »
The handle cannot be changed. 
I was under the impression that the objectid does not change as well, but I guess that is not the case. Its a learning experience.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8696
  • AKA Daniel
Re: How to update entity if all I have is ObjectID #?
« Reply #12 on: September 28, 2009, 07:34:54 PM »
Great! glad you found the answer  :-)

Right, Just think of an ObjectId as a memory address to an object. Each time you open the drawing, objects are assigned a new memory address (ObjectId)

Glenn R

  • Guest
Re: How to update entity if all I have is ObjectID #?
« Reply #13 on: September 29, 2009, 03:58:41 AM »
An ObjectID is a 'calculated' property, meaning it's computed off the handle (which is unique in a dwg, but not across drawings), the document/drawing and the session id of the current AutoCAD session I believe. So what this means is that the ObjectId is not guaranteed to be the same, whereas a handle is.

As far as the FingerprintGuid idea goes, if you were externally storing the handle, you would need a way to check what drawing the handle originated from.

Glenn R

  • Guest
Re: How to update entity if all I have is ObjectID #?
« Reply #14 on: September 29, 2009, 07:31:01 AM »
ObjectId's are guaranteed to be unique across all drawings open in the current session btw.