How to send data from python to my c++ plugin?



  • On 17/07/2018 at 06:48, xxxxxxxx wrote:

    Hi everyone.

    Not sure if this is the right branch of forum, but I think that problem is in my python code..

    I'm trying to learn C4D CPP API and I've stucked. I can't figure out how to read the data that i sent from python node to my c++ TagData plugin with Message().

    My plugin code(part of it) :

    MyTestPlugin.cpp   
    class MyTestPlugin:TagData{  
    ...  
    ...  
    Bool MyTestPlugin::Message(GeListNode *node, Int32 type, void *data)  
    {  
      if (type == 322)  
      {  
          GePrint("___Event Fired___");  
          if (!data)  
              return false;  
          GePrint(String::IntToString( (Int32)data ));  
          GePrint(String::IntToString( *(Int32* )data ));  
      }  
      return true;  
    }  
    ...  
    ...  
    

    And my python code(XPresso node) looks like:

    import c4d
      
    def main() :  
      _myCustomTag.Message(322, 112233)  
      
    

    The output:
    ___Event Fired___
    415747088
    15

    If I'm not mistaken the problem is that python sends message with < Int32> data inside and cpp waits for < Int32*>. But I just can't figure out what to do.(((
    Please help.



  • On 18/07/2018 at 06:42, xxxxxxxx wrote:

    Hi dmitry82,

    Actually, the problem is that you are sending a python object to a C++.
    So the best way to do it is to use a BaseContainer to send your data, and use MSG_BASECONTAINER.

    So your C++ code will looks like

    if (type == MSG_BASECONTAINER)
    {
    	GePrint("___Event Fired___");
    	if (!data)
    		return false;
    	BaseContainer* bc = (BaseContainer* )data;
    	if (bc == nullptr)
    		return false;
      
    	Int32 value = bc->GetInt32(0, 10);
    }
    

    and your python code

    bc = c4d.BaseContainer()
    bc[0] = 100
    _myCustomTag.Message(c4d.MSG_BASECONTAINER, bc)
    

    Please note Message function is executed immediately when you call it, that means you get the same limitation as you get in a threaded context (Xpresso Node), which is to not change the scene structure within this call, for more information please read the C++ Manual about threading.

    If you have any question, please let me know,
    Cheers,
    Maxime



  • On 04/08/2018 at 03:54, xxxxxxxx wrote:

    Sorry for late reply.
    Thanks for your answer - it helped me a lot.

    Actually, it's strange that you have to use BaseContainer wrap for every piece of primitive data. I think sometimes it must be seriously hurting perfomance.
    Anyway, thanks again, Maxime. Best wishes.


Log in to reply