How to write GeDynamicArrayCallback



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 30/05/2012 at 13:25, xxxxxxxx wrote:

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

    ---------
    Can anyone show me an example of how to write a GeDynamicArrayCallback?
    I'd like to use the DoToAll() function on a dynamic array. But I don't know how to write the CallBack it's asking for.

        int arrsize = 3;                          //Size of the array to make  
      GeDynamicArray<LONG>myarray(arrsize);     //Create the new array  
      myarray[0] = 100;                         //Assign some data to an element  
      myarray[1] = 200;                         //Assign some data to an element  
      myarray[2] = 300;                         //Assign some data to an element  
      
      myarray.DoToAll();      //<---How do I write this function?
    

    Thanks,
    ScottA



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 30/05/2012 at 22:39, xxxxxxxx wrote:

    You need to define a method with the same characteristics as the GeDynamicArrayCallback typedef and point to it in the argument of DoToAll() (just put an ampersand in front of the method name).  It looks like void* data is the GeDynamicArray that you want to operate on (myarray) and is passed from DoToAll() to your GeDynamicArrayCallback() method in the third argument.

    I've never tried it so see if that works.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 31/05/2012 at 07:59, xxxxxxxx wrote:

    I've been trying to do that. But I'm having no luck.
    I've been searching the internet trying to find an example of a CallBack that looks similar to how Maxon is using it here. But haven't found one yet. 😢

    Maybe this is just because I'm new to C++.
    But to me it seems like Maxon is using every type of old, and often obscure coding methods, that ever existed in C++.
    On one hand it's frustrating as hell trying to figure out all these obscure ways of doing things.
    On the other hand. It will help me become a much better C++ coder if I eventually get the answers.
    The C4D C++ SDK would probably be a good final exam for C++ students. 😉

    -ScottA



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 31/05/2012 at 08:22, xxxxxxxx wrote:

    Understandable.  :)  Maxon has only recently started to update their API to be more inline with modern C++ standards and their API has many vague features with no examples or detailed explanations.

    Have you tried declaring the callback method like:

    GeDynamicaArrayCallback mygdacbmethod(VLONG index, [Type](../lib_browser/enum_Type1457.html)* value, void* data)  
    {  
    ...  
    }
    

    Not sure if the method requires a return type. By default, if none is specified then C++ defaults to int as the return type which looks to be the case.

    Declare your method globally in the same .cpp file where you call DoToAll() and, most importantly, above it in the source.  C++ has two ways to recognize methods - by definition in a header or by order in the source file.  So, adding the method before it is called (in a linear fashion from top to bottom of source file) makes it known to the compiler.  Strange, but that is the way C/C++ (and some other languages) work.

    If none of this helps, I really hope that Maxon developer support can provide some answers.  Maybe I will have a chance to test this myself and respond with my results.

    Keep pounding at it and best of luck!



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 31/05/2012 at 09:08, xxxxxxxx wrote:

    Here's the plugin with all the guts removed from it to show how I'm trying to implement the callback

    #includes  
    ...  
      
      
    class myDialog : public GeDialog  
    {  
     private:  
         myDialog* dlg;  
      
     public:  
         myDialog(void);  
         ~myDialog(void);  
         virtual Bool CreateLayout(void);  
         virtual Bool InitValues(void);  
         virtual Bool Command(LONG id,const BaseContainer &msg);  
      
    };  
      
    myDialog::myDialog(void)  
    {      
    }  
      
    myDialog::~myDialog(void)  
    {      
      GeFree(dlg);  
    }  
      
    Bool CreateLayout(void);  
    {...}  
      
    Bool InitValues(void);  
    {...}  
      
      
    // **This is the callback that I can't figure out how to write**  
    Bool myArrayCallback(LONG index, Type &DoToAll, void *data) //<--This is wrong  
    {  
      LONG ai = index;         //The array's index <--This is probably wrong too     
      
      return TRUE;  
    }  
      
      
    Bool myDialog::Command(LONG id,const BaseContainer &msg)  
    {  
      
      int arrsize = 3;                          //Size of the array to make  
      GeDynamicArray<LONG>myarray(arrsize);     //Create the new array  
      myarray[0] = 100;                         //Assign some data to an element  
      myarray[1] = 200;                         //Assign some data to an element  
      myarray[2] = 300;                         //Assign some data to an element  
      
      myarray.DoToAll(  ?  ) //<--The function that I have no idea how to write  
      
      
    }  
      
      
      
    Bool RegistermyResDialog(void)  
    {  
      String Help = "C++ Dialog";  
      return RegisterCommandPlugin(IDS_RESDIALOG, "C++ Dialog", 0, AutoBitmap("icon.tif"),Help, gNew myResDialog);  
    }  
    

    I think I'm using the proper framework.
    But I'm obviously not writing the callback properly.

    -ScottA



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 31/05/2012 at 10:13, xxxxxxxx wrote:

    #includes  
    ...  
      
      
    class myDialog : public GeDialog  
    {  
      private:  
          myDialog* dlg;  
      
      public:  
          myDialog(void);  
          ~myDialog(void);  
          virtual Bool CreateLayout(void);  
          virtual Bool InitValues(void);  
          virtual Bool Command(LONG id,const BaseContainer &msg);  
      
    };  
      
    myDialog::myDialog(void)  
    {      
    }  
      
    myDialog::~myDialog(void)  
    {      
      GeFree(dlg);  
    }  
      
    Bool CreateLayout(void);  
    {...}  
      
    Bool InitValues(void);  
    {...}  
      
      
    //This is the callback that I can't figure out how to write  
    GeDynamicArrayCallback myArrayCallback(VLONG index, Type &DoToAll, void *data) //<--This is wrong  
    {  
       // You're doing to 'all' so the index parameter will be the index of the current element, I would suppose!  
       GeDynamicArray* gda = static_cast<GeDynamicArray*>(data);  
      // Do your thing to the array member (?)  
      data[index] = blah, blah  
      return TRUE;  
    }  
      
      
    Bool myDialog::Command(LONG id,const BaseContainer &msg)  
    {  
      
      int arrsize = 3;                          //Size of the array to make  
      GeDynamicArray<LONG>myarray(arrsize);     //Create the new array  
      myarray[0] = 100;                         //Assign some data to an element  
      myarray[1] = 200;                         //Assign some data to an element  
      myarray[2] = 300;                         //Assign some data to an element  
      
      myarray.DoToAll(&myArrayCallback, myarray) //<--The function that I have no idea how to write  
      
      
    }  
      
      
      
    Bool RegistermyResDialog(void)  
    {  
      String Help = "C++ Dialog";  
      return RegisterCommandPlugin(IDS_RESDIALOG, "C++ Dialog", 0, AutoBitmap("icon.tif"),Help, gNew myResDialog);  
    }
    

    Now, my problem is what to do inside of the callback method.  It may be passed the current index being operated on (for DoToAll(), it should be every element available in the array in sequence), but I'm not sure.  You will need to figure out how to cast the void* data to the correct type and then index it using VLONG index and do the operation I would think.  Maybe try to follow the default procedures for GeDynamicArray in accessing the members casting it to GeDynamicArray.  At least that might get you moving forward.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 31/05/2012 at 10:54, xxxxxxxx wrote:

    Thanks Robert.
    Getting lots of errors in the CallBack function with that. So I tried it this way:

    typedef ge_dynamicarray;  
    ge_dynamicarray myArrayCallback(VLONG index, Type &DoToAll, void *data) //<--Type undefined error  
    {  
       ge_dynamicarray* gda = static_cast<ge_dynamicarray*>(data);  
        
      data[index] = blah, blah;  //<---Error: data must be an expression to a complete object   
      return TRUE;  
    }
    

    This got rid of some of the errors. But not all of them.

    Don't waste any more time on this Robert.
    If you knew the answer that's one thing. But I'm taking up too much of your time with this.
    And you're making me feel bad.

    @MAXON - It appears that this could be documented better. Please consider this when updating the docs.

    Thanks,
    -ScottA



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 01/06/2012 at 00:14, xxxxxxxx wrote:

    Originally posted by xxxxxxxx

    @MAXON - It appears that this could be documented better. Please consider this when updating the docs.

    Yes, it's not well documented.

    GeDynamicArrayCallback is declared as:

    typedef void	GeDynamicArrayCallback(VLONG index, TYPE *value, void *data);
    

    It's a void function taking (VLONG index, TYPE *value, void *data) as parameters.
    Also don't forget it operates on a template class (GeDynamicArray<LONG>).

    So here's how to get GeDynamicArray::DoToAll() working:

    template<class TYPE> void myArrayCallback(VLONG index, TYPE *value, void *data)
    {
        // value is the current value at index in the dynamic array
      
        *value *= 2;
    }
      
    GeDynamicArray<LONG> myarray(3);
    myarray[0] = 100;
    myarray[1] = 200;
    myarray[2] = 300;
      
    myarray.DoToAll(&myArrayCallback, NULL);
    


  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 01/06/2012 at 07:51, xxxxxxxx wrote:

    Great!
    Thanks Yannick. 🍺

    -ScottA


Log in to reply