<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Help needed accessing custom object pointer with c# in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/help-needed-accessing-custom-object-pointer-with-c/m-p/2003783#M77699</link>
    <description>Thanks for the quick response, below is my code to select the custom object and retrieve the pointer...&lt;BR /&gt;
     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...  &lt;BR /&gt;
&lt;BR /&gt;
//&lt;BR /&gt;
[CommandMethod("aaexSelect")]&lt;BR /&gt;
    public void aaexSelect()&lt;BR /&gt;
    {&lt;BR /&gt;
        //get the database&lt;BR /&gt;
        Autodesk.AutoCAD.DatabaseServices.Database db =&lt;BR /&gt;
        Autodesk.AutoCAD.DatabaseServices.HostApplicationServices.WorkingDatabase;&lt;BR /&gt;
//begin transaction&lt;BR /&gt;
        Autodesk.AutoCAD.DatabaseServices.Transaction tr = db.TransactionManager.StartTransaction();&lt;BR /&gt;
&lt;BR /&gt;
        try&lt;BR /&gt;
        {&lt;BR /&gt;
            //prompt for entity&lt;BR /&gt;
            Autodesk.AutoCAD.EditorInput.PromptEntityOptions prompEntOpt =&lt;BR /&gt;
            new Autodesk.AutoCAD.EditorInput.PromptEntityOptions("\r\nChoose an entity: ");&lt;BR /&gt;
&lt;BR /&gt;
            //get entity&lt;BR /&gt;
            Autodesk.AutoCAD.EditorInput.Editor editor =&lt;BR /&gt;
            Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;&lt;BR /&gt;
&lt;BR /&gt;
            Autodesk.AutoCAD.EditorInput.PromptEntityResult prompEntRes = editor.GetEntity(prompEntOpt);&lt;BR /&gt;
&lt;BR /&gt;
            //open dbobj for read&lt;BR /&gt;
            Autodesk.AutoCAD.DatabaseServices.DBObject dbobj =&lt;BR /&gt;
            tr.GetObject(prompEntRes.ObjectId, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead, true, true);&lt;BR /&gt;
&lt;BR /&gt;
            //get rxclass from dbobj&lt;BR /&gt;
            RXClass rxCls = dbobj.GetRXClass();&lt;BR /&gt;
         &lt;BR /&gt;
            IntPtr ipCustomObj = new IntPtr();&lt;BR /&gt;
         &lt;BR /&gt;
            //drill down to my custom object class and get the unmanaged object.&lt;BR /&gt;
            do&lt;BR /&gt;
            {&lt;BR /&gt;
                switch (rxCls.Name)&lt;BR /&gt;
                {&lt;BR /&gt;
                    case "MyCustomObjectClass":&lt;BR /&gt;
                        ipCustomObj = rxCls.UnmanagedObject;&lt;BR /&gt;
                        break;&lt;BR /&gt;
                }&lt;BR /&gt;
&lt;BR /&gt;
                rxCls = rxCls.MyParent;&lt;BR /&gt;
            }&lt;BR /&gt;
&lt;BR /&gt;
            while (rxCls.MyParent != null);&lt;BR /&gt;
&lt;BR /&gt;
           //if the IntPtr is 0 then post message and exit,&lt;BR /&gt;
           //else, pass pointer to c++ class to read unmanged object.&lt;BR /&gt;
            if (ipCustomObj == IntPtr.Zero)&lt;BR /&gt;
            {&lt;BR /&gt;
               editor.WriteMessage("\r\nThe selected entity is not valid.");&lt;BR /&gt;
                return;&lt;BR /&gt;
            }&lt;BR /&gt;
            else &lt;BR /&gt;
            {&lt;BR /&gt;
                editor.WriteMessage("\r\nThe custom object pointer is: " + String.Format("{0:X4}",ipCustomObj.ToInt32() ));    &lt;BR /&gt;
            }&lt;BR /&gt;
&lt;BR /&gt;
            //send ipCustomObj to C++ wrapper class, cast to underlying class...&lt;BR /&gt;
            //...&lt;BR /&gt;
&lt;BR /&gt;
   &lt;BR /&gt;
        }&lt;BR /&gt;
        catch (System.Exception ex)&lt;BR /&gt;
        {&lt;BR /&gt;
            System.Diagnostics.Debug.WriteLine(ex.ToString());&lt;BR /&gt;
        }&lt;BR /&gt;
&lt;BR /&gt;
        finally&lt;BR /&gt;
        {&lt;BR /&gt;
            tr.Dispose();&lt;BR /&gt;
        }&lt;BR /&gt;
    }&lt;BR /&gt;
//&lt;BR /&gt;
&lt;BR /&gt;
Best Regards,&lt;BR /&gt;
Anthony</description>
    <pubDate>Wed, 27 Jun 2007 16:54:31 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2007-06-27T16:54:31Z</dc:date>
    <item>
      <title>Help needed accessing custom object pointer with c#</title>
      <link>https://forums.autodesk.com/t5/net-forum/help-needed-accessing-custom-object-pointer-with-c/m-p/2003781#M77697</link>
      <description>Hello all-&lt;BR /&gt;
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?&lt;BR /&gt;
&lt;BR /&gt;
Best Regards,&lt;BR /&gt;
Anthony</description>
      <pubDate>Tue, 26 Jun 2007 06:55:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/help-needed-accessing-custom-object-pointer-with-c/m-p/2003781#M77697</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-06-26T06:55:55Z</dc:date>
    </item>
    <item>
      <title>Re: Help needed accessing custom object pointer with c#</title>
      <link>https://forums.autodesk.com/t5/net-forum/help-needed-accessing-custom-object-pointer-with-c/m-p/2003782#M77698</link>
      <description>Can you show the code? &lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
http://www.caddzone.com&lt;BR /&gt;
&lt;BR /&gt;
AcadXTabs: MDI Document Tabs for AutoCAD 2008&lt;BR /&gt;
Supporting AutoCAD 2000 through 2008&lt;BR /&gt;
http://www.acadxtabs.com&lt;BR /&gt;
&lt;BR /&gt;
&lt;A.CONTE&gt; wrote in message news:5638189@discussion.autodesk.com...&lt;BR /&gt;
Hello all-&lt;BR /&gt;
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?&lt;BR /&gt;
&lt;BR /&gt;
Best Regards,&lt;BR /&gt;
Anthony&lt;/A.CONTE&gt;</description>
      <pubDate>Tue, 26 Jun 2007 22:24:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/help-needed-accessing-custom-object-pointer-with-c/m-p/2003782#M77698</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-06-26T22:24:11Z</dc:date>
    </item>
    <item>
      <title>Re: Help needed accessing custom object pointer with c#</title>
      <link>https://forums.autodesk.com/t5/net-forum/help-needed-accessing-custom-object-pointer-with-c/m-p/2003783#M77699</link>
      <description>Thanks for the quick response, below is my code to select the custom object and retrieve the pointer...&lt;BR /&gt;
     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...  &lt;BR /&gt;
&lt;BR /&gt;
//&lt;BR /&gt;
[CommandMethod("aaexSelect")]&lt;BR /&gt;
    public void aaexSelect()&lt;BR /&gt;
    {&lt;BR /&gt;
        //get the database&lt;BR /&gt;
        Autodesk.AutoCAD.DatabaseServices.Database db =&lt;BR /&gt;
        Autodesk.AutoCAD.DatabaseServices.HostApplicationServices.WorkingDatabase;&lt;BR /&gt;
//begin transaction&lt;BR /&gt;
        Autodesk.AutoCAD.DatabaseServices.Transaction tr = db.TransactionManager.StartTransaction();&lt;BR /&gt;
&lt;BR /&gt;
        try&lt;BR /&gt;
        {&lt;BR /&gt;
            //prompt for entity&lt;BR /&gt;
            Autodesk.AutoCAD.EditorInput.PromptEntityOptions prompEntOpt =&lt;BR /&gt;
            new Autodesk.AutoCAD.EditorInput.PromptEntityOptions("\r\nChoose an entity: ");&lt;BR /&gt;
&lt;BR /&gt;
            //get entity&lt;BR /&gt;
            Autodesk.AutoCAD.EditorInput.Editor editor =&lt;BR /&gt;
            Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;&lt;BR /&gt;
&lt;BR /&gt;
            Autodesk.AutoCAD.EditorInput.PromptEntityResult prompEntRes = editor.GetEntity(prompEntOpt);&lt;BR /&gt;
&lt;BR /&gt;
            //open dbobj for read&lt;BR /&gt;
            Autodesk.AutoCAD.DatabaseServices.DBObject dbobj =&lt;BR /&gt;
            tr.GetObject(prompEntRes.ObjectId, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead, true, true);&lt;BR /&gt;
&lt;BR /&gt;
            //get rxclass from dbobj&lt;BR /&gt;
            RXClass rxCls = dbobj.GetRXClass();&lt;BR /&gt;
         &lt;BR /&gt;
            IntPtr ipCustomObj = new IntPtr();&lt;BR /&gt;
         &lt;BR /&gt;
            //drill down to my custom object class and get the unmanaged object.&lt;BR /&gt;
            do&lt;BR /&gt;
            {&lt;BR /&gt;
                switch (rxCls.Name)&lt;BR /&gt;
                {&lt;BR /&gt;
                    case "MyCustomObjectClass":&lt;BR /&gt;
                        ipCustomObj = rxCls.UnmanagedObject;&lt;BR /&gt;
                        break;&lt;BR /&gt;
                }&lt;BR /&gt;
&lt;BR /&gt;
                rxCls = rxCls.MyParent;&lt;BR /&gt;
            }&lt;BR /&gt;
&lt;BR /&gt;
            while (rxCls.MyParent != null);&lt;BR /&gt;
&lt;BR /&gt;
           //if the IntPtr is 0 then post message and exit,&lt;BR /&gt;
           //else, pass pointer to c++ class to read unmanged object.&lt;BR /&gt;
            if (ipCustomObj == IntPtr.Zero)&lt;BR /&gt;
            {&lt;BR /&gt;
               editor.WriteMessage("\r\nThe selected entity is not valid.");&lt;BR /&gt;
                return;&lt;BR /&gt;
            }&lt;BR /&gt;
            else &lt;BR /&gt;
            {&lt;BR /&gt;
                editor.WriteMessage("\r\nThe custom object pointer is: " + String.Format("{0:X4}",ipCustomObj.ToInt32() ));    &lt;BR /&gt;
            }&lt;BR /&gt;
&lt;BR /&gt;
            //send ipCustomObj to C++ wrapper class, cast to underlying class...&lt;BR /&gt;
            //...&lt;BR /&gt;
&lt;BR /&gt;
   &lt;BR /&gt;
        }&lt;BR /&gt;
        catch (System.Exception ex)&lt;BR /&gt;
        {&lt;BR /&gt;
            System.Diagnostics.Debug.WriteLine(ex.ToString());&lt;BR /&gt;
        }&lt;BR /&gt;
&lt;BR /&gt;
        finally&lt;BR /&gt;
        {&lt;BR /&gt;
            tr.Dispose();&lt;BR /&gt;
        }&lt;BR /&gt;
    }&lt;BR /&gt;
//&lt;BR /&gt;
&lt;BR /&gt;
Best Regards,&lt;BR /&gt;
Anthony</description>
      <pubDate>Wed, 27 Jun 2007 16:54:31 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/help-needed-accessing-custom-object-pointer-with-c/m-p/2003783#M77699</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-06-27T16:54:31Z</dc:date>
    </item>
    <item>
      <title>Re: Help needed accessing custom object pointer with c#</title>
      <link>https://forums.autodesk.com/t5/net-forum/help-needed-accessing-custom-object-pointer-with-c/m-p/2003784#M77700</link>
      <description>Tony, If the custom object is the one that you are&lt;BR /&gt;
selecting, then the UnmanagedObject property of&lt;BR /&gt;
that DBObject is a pointer to the native custom&lt;BR /&gt;
object instance.&lt;BR /&gt;
&lt;BR /&gt;
The UnmanagedObject property of an RXClass is&lt;BR /&gt;
a pointer to the wrapped native AcRxClass, not the &lt;BR /&gt;
native custom object instance.&lt;BR /&gt;
&lt;BR /&gt;
If you're trying to pass the pointer to an instance&lt;BR /&gt;
of your custom object (which you select in the&lt;BR /&gt;
editor), then its just a matter of passing the&lt;BR /&gt;
UnmanagedObject property of the selected DBObject&lt;BR /&gt;
to your native code, that's all.&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
http://www.caddzone.com&lt;BR /&gt;
&lt;BR /&gt;
AcadXTabs: MDI Document Tabs for AutoCAD 2008&lt;BR /&gt;
Supporting AutoCAD 2000 through 2008&lt;BR /&gt;
http://www.acadxtabs.com&lt;BR /&gt;
&lt;BR /&gt;
&lt;A.CONTE&gt; wrote in message news:5640372@discussion.autodesk.com...&lt;BR /&gt;
Thanks for the quick response, below is my code to select the custom object and retrieve the pointer...&lt;BR /&gt;
     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...  &lt;BR /&gt;
&lt;BR /&gt;
//&lt;BR /&gt;
[CommandMethod("aaexSelect")]&lt;BR /&gt;
    public void aaexSelect()&lt;BR /&gt;
    {&lt;BR /&gt;
        //get the database&lt;BR /&gt;
        Autodesk.AutoCAD.DatabaseServices.Database db =&lt;BR /&gt;
        Autodesk.AutoCAD.DatabaseServices.HostApplicationServices.WorkingDatabase;&lt;BR /&gt;
//begin transaction&lt;BR /&gt;
        Autodesk.AutoCAD.DatabaseServices.Transaction tr = db.TransactionManager.StartTransaction();&lt;BR /&gt;
&lt;BR /&gt;
        try&lt;BR /&gt;
        {&lt;BR /&gt;
            //prompt for entity&lt;BR /&gt;
            Autodesk.AutoCAD.EditorInput.PromptEntityOptions prompEntOpt =&lt;BR /&gt;
            new Autodesk.AutoCAD.EditorInput.PromptEntityOptions("\r\nChoose an entity: ");&lt;BR /&gt;
&lt;BR /&gt;
            //get entity&lt;BR /&gt;
            Autodesk.AutoCAD.EditorInput.Editor editor =&lt;BR /&gt;
            Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;&lt;BR /&gt;
&lt;BR /&gt;
            Autodesk.AutoCAD.EditorInput.PromptEntityResult prompEntRes = editor.GetEntity(prompEntOpt);&lt;BR /&gt;
&lt;BR /&gt;
            //open dbobj for read&lt;BR /&gt;
            Autodesk.AutoCAD.DatabaseServices.DBObject dbobj =&lt;BR /&gt;
            tr.GetObject(prompEntRes.ObjectId, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead, true, true);&lt;BR /&gt;
&lt;BR /&gt;
            //get rxclass from dbobj&lt;BR /&gt;
            RXClass rxCls = dbobj.GetRXClass();&lt;BR /&gt;
         &lt;BR /&gt;
            IntPtr ipCustomObj = new IntPtr();&lt;BR /&gt;
         &lt;BR /&gt;
            //drill down to my custom object class and get the unmanaged object.&lt;BR /&gt;
            do&lt;BR /&gt;
            {&lt;BR /&gt;
                switch (rxCls.Name)&lt;BR /&gt;
                {&lt;BR /&gt;
                    case "MyCustomObjectClass":&lt;BR /&gt;
                        ipCustomObj = rxCls.UnmanagedObject;&lt;BR /&gt;
                        break;&lt;BR /&gt;
                }&lt;BR /&gt;
&lt;BR /&gt;
                rxCls = rxCls.MyParent;&lt;BR /&gt;
            }&lt;BR /&gt;
&lt;BR /&gt;
            while (rxCls.MyParent != null);&lt;BR /&gt;
&lt;BR /&gt;
           //if the IntPtr is 0 then post message and exit,&lt;BR /&gt;
           //else, pass pointer to c++ class to read unmanged object.&lt;BR /&gt;
            if (ipCustomObj == IntPtr.Zero)&lt;BR /&gt;
            {&lt;BR /&gt;
               editor.WriteMessage("\r\nThe selected entity is not valid.");&lt;BR /&gt;
                return;&lt;BR /&gt;
            }&lt;BR /&gt;
            else &lt;BR /&gt;
            {&lt;BR /&gt;
                editor.WriteMessage("\r\nThe custom object pointer is: " + String.Format("{0:X4}",ipCustomObj.ToInt32() ));    &lt;BR /&gt;
            }&lt;BR /&gt;
&lt;BR /&gt;
            //send ipCustomObj to C++ wrapper class, cast to underlying class...&lt;BR /&gt;
            //...&lt;BR /&gt;
&lt;BR /&gt;
   &lt;BR /&gt;
        }&lt;BR /&gt;
        catch (System.Exception ex)&lt;BR /&gt;
        {&lt;BR /&gt;
            System.Diagnostics.Debug.WriteLine(ex.ToString());&lt;BR /&gt;
        }&lt;BR /&gt;
&lt;BR /&gt;
        finally&lt;BR /&gt;
        {&lt;BR /&gt;
            tr.Dispose();&lt;BR /&gt;
        }&lt;BR /&gt;
    }&lt;BR /&gt;
//&lt;BR /&gt;
&lt;BR /&gt;
Best Regards,&lt;BR /&gt;
Anthony&lt;/A.CONTE&gt;</description>
      <pubDate>Thu, 28 Jun 2007 00:44:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/help-needed-accessing-custom-object-pointer-with-c/m-p/2003784#M77700</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-06-28T00:44:58Z</dc:date>
    </item>
  </channel>
</rss>

