Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware 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

    Send message to tooldata

    Cinema 4D SDK
    r20 python
    2
    4
    959
    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.
    • P
      pim
      last edited by

      How can I send data from a command plugin dialog to a tooldata plugin?
      I tried following in the command plugin

                  self.mode = id
                  #c4d.SpecialEventAdd(PLUGIN_ID2, p1=id, p2=id)  
                  
                  msg = c4d.BaseContainer()
                  msg[1] = id
                  self.CoreMessage(c4d.EVMSG_TOOLCHANGED, msg)
      

      But nothing is received in the tooldata plugin.

          def Message(self, node, type, data):
              if type==c4d.EVMSG_TOOLCHANGED:
                  print "EVMSG_TOOLCHANGED"
                  if data['id'][0].id==PLUGIN_ID2:
                      print "Pushed button with the ID", PLUGIN_ID2
                      return True
                  
          def CoreMessage(self, id, msg):
              if id == PLUGIN_ID2:
                 print "Message received."
                 ....
      
      1 Reply Last reply Reply Quote 0
      • C4DSC
        C4DS
        last edited by

        If I remember correctly we did discuss the other way (from CommandData to ToolData) quite a while ago (see https://developers.maxon.net/forum/topic/10044/13513_using-objectmessage). But I guess using this same technique could still be applicable to your current request.

        Most important is to understand that a CoreMessage is not captured by a ToolData. This type of message can only be captured by a MessageData plugin, where you then could "translate" it into a message that actually is sent to the ToolData.

        What I have been successful in using is, performing following from the "transmitter":

        BasePlugin* tool = FindPlugin(TOOL_PLUGIN_ID, PLUGINTYPE::TOOL);
        if (tool)
        	tool->Message(TOOL_MSG_PREPAREDATA);
        
        

        Where TOOL_PLUGIN_ID is the plugin ID of the ToolData, and TOOL_MSG_PREPAREDATA is a custom defined message, using a unique plugin ID.

        And then using following in the "receiver" ToolData:

        Bool MyToolData::Message(BaseDocument *doc, BaseContainer &data, Int32 type, void *t_data)
        {
        	if (type == TOOL_MSG_PREPAREDATA)
        	{
        		PrepareData();
        	}
        
        	return DescriptionToolData::Message(doc, data, type, t_data);
        }
        
        
        1 Reply Last reply Reply Quote 4
        • C4DSC
          C4DS
          last edited by

          Furthermore, I am not sure you can simply sent out a EVMSG_TOOLCHANGED.
          Why would you do so?
          Best is to actually perform a change of tool (by doing a doc->SetAction(...)), which will automatically sent out this message. But of course the message being a CoreMessage it can only be captured by a MessageData plugin. Again, you could provide this detection and "translate" that captured EVMSG_TOOLCHANGED into a "tool->Message(custom_msg_id_toolchanged)", which you would then listen to in your ToolData::Message()

          1 Reply Last reply Reply Quote 0
          • P
            pim
            last edited by

            @C4DS said in Send message to tooldata:

            PrepareData

            Your first answer works great! Thank you.

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