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
    • Register
    • Login

    Controlling drag&drop using MSG_DESCRIPTION_CHECKDRAGANDDROP

    Cinema 4D SDK
    2024 python
    3
    5
    738
    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.
    • CJtheTigerC
      CJtheTiger
      last edited by CJtheTiger

      Hello coders. Me again.

      In a Python ObjectData plugin I added a LINK parameter. I want all BaseObjects except for the plugin object itself to be droppable in here. So I put this in my .res file:

      LINK OMYOBJECT_LINK { ACCEPT { Obase; } }
      

      According to the documentation of MSG_DESCRIPTION_CHECKDRAGANDDROP I should listen to this message and if I want the drop to not be acceptable I should return False. So this is in my code:

      def Message(self, node: GeListNode, type: int, data: object) -> bool:
      
          if type == c4d.MSG_DESCRIPTION_CHECKDRAGANDDROP:
              return False
      
          return True
      

      Just to try it out I always return False. And that's where my issue is: I can still drop any object in there. It is limited to BaseObjects so the ACCEPT { Obase; } seems to work but returning False seems to not prevent the user from dropping something in the link.

      What am I doing wrong?

      I tried removing ACCEPT { Obase; } from the .res file to no effect.

      As an addition: How do I control what the picker of a LINK is allowed to pick? Since it's technically not a drag&drop action it should be something other than MSG_DESCRIPTION_CHECKDRAGANDDROP right?

      1 Reply Last reply Reply Quote 0
      • S
        spedler
        last edited by

        In addition to ACCEPT the LINK gui also has a REFUSE statement. You can use that to exclude your plugin ID.

        Steve

        CJtheTigerC 1 Reply Last reply Reply Quote 1
        • CJtheTigerC
          CJtheTiger @spedler
          last edited by

          Hello @spedler,

          Thanks, this totally works.

          However this refuses to take any of my plugin objects, while in the end I only want to refuse the current plugin object; I still want to be able to drag other instances of my plugin object in there.

          So in the end I'd still like to solve this using advanced logic in the MSG_DESCRIPTION_CHECKDRAGANDDROP message.

          Best regards,
          Daniel

          1 Reply Last reply Reply Quote 0
          • M
            m_adam
            last edited by

            Hi @CJtheTiger, you were close regarding MSG_DESCRIPTION_CHECKDRAGANDDROP as written in the documentation, you need to set the value of the `resul field of the dictionary like so:

            
                def Message(self, node: c4d.GeListNode, type: int, data: object) -> bool:
            
                    if type == c4d.MSG_DESCRIPTION_CHECKDRAGANDDROP:
                        gadgetId = data["id"]
                        dragedObj = data["element"]
                        data["result"] = dragedObj != node
                        return True
                    
                    return True
            

            Cheers,
            Maxime.

            MAXON SDK Specialist

            Development Blog, MAXON Registered Developer

            CJtheTigerC 1 Reply Last reply Reply Quote 1
            • CJtheTigerC
              CJtheTiger @m_adam
              last edited by

              Hi @m_adam,

              thanks a lot, that did the trick.

              To close this topic off here's a snippet to allow other objects but not the current object to be dropped in there:

              def Message(self, node: GeListNode, type: int, data: object) -> bool:
              
                  if type == c4d.MSG_DESCRIPTION_CHECKDRAGANDDROP:
              
                      relevant_id = c4d.DescID(c4d.YOUR_PARAM) # Use the ID of the parameter of your object that you want to check.
                      current_id: c4d.DescID = data['id']
                      
                      if relevant_id.IsPartOf(current_id)[0]:        
                          dragged_element = data["element"]        
                          is_same_object = node == dragged_element        
                          data['result'] = not is_same_object        
                          return True
                      
                      return True
              

              Cheers,
              Daniel

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