.NET

Reply
New Member
richard2012
Posts: 2
Registered: ‎10-29-2012
Message 1 of 3 (435 Views)
Accepted Solution

Property ObjectId vs Id

435 Views, 2 Replies
10-29-2012 06:59 PM

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

Thanks,

Richard

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

Mentor
khoa.ho
Posts: 220
Registered: ‎09-15-2011
Message 2 of 3 (386 Views)

Re: Property ObjectId vs Id

11-03-2012 04:44 PM 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

New Member
richard2012
Posts: 2
Registered: ‎10-29-2012
Message 3 of 3 (347 Views)

Re: Property ObjectId vs Id

11-06-2012 02:12 AM 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
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.