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

Help needed accessing custom object pointer with c#

3 REPLIES 3
Reply
Message 1 of 4
Anonymous
928 Views, 3 Replies

Help needed accessing custom object pointer with c#

Hello all-
I have a question about accessing a custom object from C#. I have been opening the custom objects for read, and using dbobj.GetRXClass() to retrieve the RxClass, and then using 'UnmanagedObject()' to get a pointer to what I think is the 'real' instance of the underlying c++ object. I have not seen much documentation on this, but when I use the pointer in my unmanaged dll, the object retrieved does not seem to be correct. Can anyone provide an example that accomplishes this correctly?

Best Regards,
Anthony
3 REPLIES 3
Message 2 of 4
Anonymous
in reply to: Anonymous

Can you show the code?

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

wrote in message news:5638189@discussion.autodesk.com...
Hello all-
I have a question about accessing a custom object from C#. I have been opening the custom objects for read, and using dbobj.GetRXClass() to retrieve the RxClass, and then using 'UnmanagedObject()' to get a pointer to what I think is the 'real' instance of the underlying c++ object. I have not seen much documentation on this, but when I use the pointer in my unmanaged dll, the object retrieved does not seem to be correct. Can anyone provide an example that accomplishes this correctly?

Best Regards,
Anthony
Message 3 of 4
Anonymous
in reply to: Anonymous

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
Message 4 of 4
Anonymous
in reply to: Anonymous

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

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