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

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

    Scheduled Pinned Locked Moved PYTHON Development
    3 Posts 0 Posters 1.0k Views
    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 Offline
      Helper
      last edited by

      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.

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

        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

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

          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.

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