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
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    How to add Button User Data with a Button GUI in python script?

    Cinema 4D SDK
    s24 python
    2
    3
    806
    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.
    • eZioPanE
      eZioPan
      last edited by

      Hi,

      How can I add a button to an object with python?

      I'm trying to add a button to a Null Object, but only get a button userdata without button itself. Here is the code:

      import c4d
      
      def main():
          null_object = c4d.BaseObject(c4d.Onull)
      
          ud_btn_bc = c4d.GetCustomDatatypeDefault(c4d.DTYPE_BUTTON)
          ud_btn_bc.SetString(c4d.DESC_NAME, "Click")
          ud_btn_bc.SetString(c4d.DESC_SHORT_NAME, "click")
          null_object.AddUserData(ud_btn_bc)
      
          doc.InsertObject(null_object)
       
          c4d.EventAdd()
      
      if __name__ == "__main__":
          main()
      
      

      It seems that creating a button user data from GUI is different from Python. But I don't know how to do it correctly in Python.

      Thanks!

      1 Reply Last reply Reply Quote 0
      • ManuelM
        Manuel
        last edited by

        hi,

        the function 'GetCustomDatatypeDefault' do not always return a BaseContainer with DESC_CUSTOMGUI defined. In the case of the 'Button' datatype, the returned BaseContainer is empty. You must define the custom GUI you want to use.

        In your case using ' ud_btn_bc.SetInt32(c4d.DESC_CUSTOMGUI, c4d.CUSTOMGUI_BUTTON)' will work.

        Cheers,
        Manuel

        MAXON SDK Specialist

        MAXON Registered Developer

        1 Reply Last reply Reply Quote 0
        • eZioPanE
          eZioPan
          last edited by

          It works like a charm!

          Thanks a lot!

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