Tony, If the custom object is the one that you are
selecting, then the UnmanagedObject property of
that DBObject is a pointer to the native custom
object instance.
The UnmanagedObject property of an RXClass is
a pointer to the wrapped native AcRxClass, not the
native custom object instance.
If you're trying to pass the pointer to an instance
of your custom object (which you select in the
editor), then its just a matter of passing the
UnmanagedObject property of the selected DBObject
to your native code, that's all.
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com
wrote in message news:5640372@discussion.autodesk.com...
Thanks for the quick response, below is my code to select the custom object and retrieve the pointer...
The custom objects are actually from my company's existing software, and I have accurate header files for all the arx and dbx objects. When I use the pointer retrieved by the the function below, I actually do not see any valid data aligning with my c++ class. If I cast the pointer to an unmanged AcRxClass it matches this structure just fine. That is why I am thinking that there is some extra step I am missing here to get or convert to the custom class...
//
[CommandMethod("aaexSelect")]
public void aaexSelect()
{
//get the database
Autodesk.AutoCAD.DatabaseServices.Database db =
Autodesk.AutoCAD.DatabaseServices.HostApplicationServices.WorkingDatabase;
//begin transaction
Autodesk.AutoCAD.DatabaseServices.Transaction tr = db.TransactionManager.StartTransaction();
try
{
//prompt for entity
Autodesk.AutoCAD.EditorInput.PromptEntityOptions prompEntOpt =
new Autodesk.AutoCAD.EditorInput.PromptEntityOptions("\r\nChoose an entity: ");
//get entity
Autodesk.AutoCAD.EditorInput.Editor editor =
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
Autodesk.AutoCAD.EditorInput.PromptEntityResult prompEntRes = editor.GetEntity(prompEntOpt);
//open dbobj for read
Autodesk.AutoCAD.DatabaseServices.DBObject dbobj =
tr.GetObject(prompEntRes.ObjectId, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead, true, true);
//get rxclass from dbobj
RXClass rxCls = dbobj.GetRXClass();
IntPtr ipCustomObj = new IntPtr();
//drill down to my custom object class and get the unmanaged object.
do
{
switch (rxCls.Name)
{
case "MyCustomObjectClass":
ipCustomObj = rxCls.UnmanagedObject;
break;
}
rxCls = rxCls.MyParent;
}
while (rxCls.MyParent != null);
//if the IntPtr is 0 then post message and exit,
//else, pass pointer to c++ class to read unmanged object.
if (ipCustomObj == IntPtr.Zero)
{
editor.WriteMessage("\r\nThe selected entity is not valid.");
return;
}
else
{
editor.WriteMessage("\r\nThe custom object pointer is: " + String.Format("{0:X4}",ipCustomObj.ToInt32() ));
}
//send ipCustomObj to C++ wrapper class, cast to underlying class...
//...
}
catch (System.Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.ToString());
}
finally
{
tr.Dispose();
}
}
//
Best Regards,
Anthony