Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    MYPLUGINOBJECT to a BaseObject

    SDK Help
    0
    7
    442
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H
      Helper
      last edited by

      On 27/08/2013 at 11:23, xxxxxxxx wrote:

      User Information:
      Cinema 4D Version:   R14 
      Platform:   Windows  ;   
      Language(s) :     C++  ;

      ---------
         Hi Folks,

      how do I turn something like this:

        
      // Below = reference to my ObjectData plugin from inside   
      // another DescriptionToolData plugin. The reference is valid.   
      MYPLUGINOBJECT MyPlugin;   
      

      to a BaseObject? As In:

        
      BaseObject *obj = (BaseObject* )MyPlugin;   
      // I'm sure the above isn't right,   
      // though it does compile!   
      

      How is this done properly?

      WP.

      1 Reply Last reply Reply Quote 0
      • H
        Helper
        last edited by

        On 27/08/2013 at 11:30, xxxxxxxx wrote:

        Is MYPLUGINOBJECT a subclass of ObjectData? Then to create a new object

        BaseObject\* obj = BaseObject::Alloc(THE_PLUGINID_OF_MYPLUGINOBJECT);
        

        or to retrieve the BaseObject* linked to the ObjectData instance

        MYPLUGINOBJECT\* plugin_obj = // ...
        BaseObject\* obj = (BaseObject\* ) plugin_obj->Get();
        
        
        // assuming
        class MYPLUGINOBJECT : public ObjectData 
        

        It is important to understand that an instance of ObjectData is not the same as an
        instance of BaseObject. The BaseObject is a wrapper for ObjectData instances.

        ObjectData\* data = (ObjectData\* ) obj->GetNodeData();
        BaseObject\* obj_2 = (BaseObject\* ) data->Get();
        
        
        obj == obj_2
        obj != data
        

        -Niklas

        1 Reply Last reply Reply Quote 0
        • H
          Helper
          last edited by

          On 27/08/2013 at 12:25, xxxxxxxx wrote:

          Thanks Niklas,

          I was wishing to "retrieve the BaseObject" link, so you're second way was what I was seeking!

            
          BaseObject* obj = (BaseObject* ) plugin_obj->Get();   
          

          WP.

          1 Reply Last reply Reply Quote 0
          • H
            Helper
            last edited by

            On 28/08/2013 at 00:47, xxxxxxxx wrote:

            Just as a completion to what Niklas wrote, I recommend using static_cast instead of the C-Style cast. It has the nice property that first of all it will throw a compiling error if the cast is not valid and it can be identified in code much better because it will be color-coded.

            1 Reply Last reply Reply Quote 0
            • H
              Helper
              last edited by

              On 28/08/2013 at 07:35, xxxxxxxx wrote:

              Howdy,

              If I may ask, what is the reason for doing?:

              MYPLUGINOBJECT MyPlugin;
              

              Adios,
              Cactus Dan

              1 Reply Last reply Reply Quote 0
              • H
                Helper
                last edited by

                On 28/08/2013 at 08:17, xxxxxxxx wrote:

                Hi Dan,

                I'm using it at the class-level of a tool plugin so it can be passed around in various functions to retrieve the node data (does that make sense?).

                WP.

                EDIT: come to think of it, I may have gone in a small circle with this...

                1 Reply Last reply Reply Quote 0
                • H
                  Helper
                  last edited by

                  On 28/08/2013 at 09:30, xxxxxxxx wrote:

                  Howdy,

                  Yes, that makes perfect sense, but the way I would do it would be to only use a pointer as a member variable in the ToolData class:

                  MYPLUGINOBJECT* MyPlugin;
                  

                  Then in the function where you need to assign an address to the pointer:

                  BaseObject *op = doc->GetActiveObject(); // or the BaseObject pointer passed to the ToolData function
                  MyPlugin = static_cast<MYPLUGINOBJECT*>(op->GetNodeData());
                  if(!MyPlugin) return FALSE; // exit if the cast failed
                  

                  This way you won't need to pass it around to other functions and you can simply check to make sure it is valid as the first line of each function:

                  if(!MyPlugin) return FALSE; // exit if the pointer is NULL
                  

                  EDIT:
                  Don't forget to initialize the pointer in ToolData::InitTool() :

                  MyPlugin = NULL;
                  

                  Adios,
                  Cactus Dan

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post