.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Property ObjectId vs Id

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
richard2012
2118 Views, 2 Replies

Property ObjectId vs Id

It is probably trivial question but what is different between property DBObject.ObjectId and DBObject.Id

Thanks,

Richard

2 REPLIES 2
Message 2 of 3
khoa.ho
in reply to: richard2012

Both DBObject.ObjectId and DBObject.Id return to the same struct ObjectId, and have the same value.

 

The difference is how they get called unmanaged code behind .NET framework. If we decompile acdbmgd.dll, we will see the difference:

 

Decompiled code of DBObject.ObjectId:

// Autodesk.AutoCAD.DatabaseServices.DBObject class
public unsafe ObjectId ObjectId
{
	get
	{
		AcDbObjectId acDbObjectId;
		AcDbObjectId* ptr = <Module>.AcDbObject.objectId(this.GetImpObj(), &acDbObjectId);
		ObjectId result;
		result.m_id = *(long*)ptr;
		return result;
	}
}

// <Module> class
[SuppressUnmanagedCodeSecurity]
[DllImport("", CallingConvention = CallingConvention.Cdecl, SetLastError = true)]
[MethodImpl(MethodImplOptions.Unmanaged)]
public unsafe static extern AcDbObjectId* objectId(AcDbObject*, AcDbObjectId*);

 

Decompiled code of DBObject.Id:

// Autodesk.AutoCAD.DatabaseServices.DBObject class
public unsafe override ObjectId Id
{
	get
	{
		AcDbObject* impObj = this.GetImpObj();
		AcDbObjectId acDbObjectId;
		AcDbObjectId* ptr = calli(AcDbObjectId* modreq(System.Runtime.CompilerServices.IsUdtReturn) modopt(System.Runtime.CompilerServices.CallConvCdecl)(System.IntPtr,AcDbObjectId*), impObj, ref acDbObjectId, *(*(long*)impObj + 80L));
		ObjectId result;
		result.m_id = *(long*)ptr;
		return result;
	}
}

 

A managed code DBObject.ObjectId will call another unmanaged/unsafe code AcDbObject.objectId(). AcDbObject is a class of ObjectARX, which has method objectId() to return the pointer of memory address of the database-resident object.

 

A managed code DBObject.Id will call another unmanaged/unsafe code calli() which is I don't know, and is also not found on ObjectARX SDK. I guess it may be legacy code, even it returns same value of DBObject.ObjectId.

 

ObjectId is not value that AutoCAD saves to DWG file, it saves handles instead. A handle is a long number to identify an entity, so handle is unique inside one drawing. But AutoCAD is a MDI application. That means it can work with multiple drawing files at the same time. Then a handle is not unique among multiple opened drawings. To solve that, AutoCAD uses memory address to identify an entity, which is ObjectId. So every time we open a DWG file, an ObjectId of any entity will change, except the handle of this entity is still remained from reading file.

 

The benefit of ObjectId is to work for multiple drawings at the same time, as each entity has its own unique memory address. For that reason, we can copy any entity from one drawing to another with Ctrl-C and Ctrl-V inside AutoCAD.

 

Anyway, DBObject.ObjectId is official to identify an entity inside an AutoCAD host which may handle many opened drawings at the same time.

 

I still don't know if it is a need to use DBObject.Id, or it is redundant. As DBObject.ObjectId is good enough to represent an entity.

 

-Khoa

Message 3 of 3
richard2012
in reply to: khoa.ho

Thanks for really comprehensive explanation.
Just one think I am little surprise is that majority of examples I have read use DBObject.Id, but as you said both return the same struct ObjectId.
Richard

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost