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

    CUSTOMGUI_CYCLE: SetContainer: TypeError: an integer is required (got type set)

    Cinema 4D SDK
    python r25
    2
    3
    593
    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.
    • R
      RenoBozo
      last edited by RenoBozo

      Hi, everyone,

      I can't get to make .SetContainer work.

      I'm doing this through a python tag, file attached.

      I looked everywhere, and I've seen the code on a few websites, I don't understand why it's not working.
      Is there a change I've missed?
      custom-gui.c4d
      My goal is to make the element selected so that I can use this component to make a sort of quick selector between objects.

      import c4d
      from c4d import gui
      from c4d import documents
      
      def MkUD(Object):
          children = Object.GetChildren()
          count = len(children)
          bc = c4d.GetCustomDataTypeDefault(c4d.DTYPE_LONG)
          bc.SetString(c4d.DESC_NAME, 'Objects')
          bc.SetInt32(c4d.DESC_CUSTOMGUI, c4d.CUSTOMGUI_CYCLE)
          cycle = c4d.BaseContainer()
          cycle.SetString(0, 'si')
          cycle.SetString(1, 'sai')
          print (cycle)
          bc.SetContainer(c4d.DESC_CYCLE, cycle) # I can see the UD when I comment this line
          Object.SetUserDataContainer([c4d.ID_USERDATA, 1], bc) # but nothing inside...
      
      def main():
          obj = doc.SearchObject("Null")
          MkUD(obj)
          c4d.EventAdd()
      

      I get:

      <c4d.BaseContainer object at 0x000001DF3FF609C0>
      Traceback (most recent call last):
        File "Python", line 20, in main
        File "Python", line 15, in MkUD
      TypeError: an integer is required (got type set)
      >>> 
      

      I'm on R25
      Thanks for your help, so frustrating.

      1 Reply Last reply Reply Quote 0
      • ferdinandF
        ferdinand
        last edited by

        Hello @renobozo,

        thank you for reaching out to us and welcome to the Plugin Café. We cannot reproduce your problem here on our machines. Your error indicates that c4d.DESC_CYCLE is not an integer on your machine as it should be, but a set. Could you print out the value of c4d.DESC_CYCLE? You might have accidently overwritten the value, but should have been fiexed by a restart.

        Cheers,
        Ferdinand

        The result:
        9db9d4e6-6da1-4bfe-822e-f51e37df6779-image.png
        The script:

        """Simple example that does create cycle user data parameters in the selected
        object.
        
        The cycle values are populated with the names of the children of the selected 
        object. To be run as a script manger script. Requires an object to be selected
        which should have some children.
        """
        
        import c4d
        
        def CreateUserData(node: c4d.BaseList2D):
            """Creates a user data parameter in #node.
            """
            param = c4d.GetCustomDataTypeDefault(c4d.DTYPE_LONG)
            param.SetString(c4d.DESC_NAME, 'Objects')
            param.SetInt32(c4d.DESC_CUSTOMGUI, c4d.CUSTOMGUI_CYCLE)
            cycle = c4d.BaseContainer()
            # I assume you wanted to populate the cycle with the children.
            for i, child in enumerate(node.GetChildren()):
                cycle.SetString(i, child.GetName())
            param.SetContainer(c4d.DESC_CYCLE, cycle)
        
            # You have to pass either a collection type or DescId for the parameter id here.
            if not node.SetUserDataContainer((c4d.ID_USERDATA, 1), param):
                raise RuntimeError("Could not set user data parameter.")
            did = c4d.DescID(c4d.DescLevel(c4d.ID_USERDATA), c4d.DescLevel(2))
            if not node.SetUserDataContainer(did, param):
                raise RuntimeError("Could not set user data parameter.")
        
        def main():
            """Entry point.
            """
            if op is None:
                raise RuntimeError("Please select an object.")
            CreateUserData(op)
            c4d.EventAdd()
        
        if __name__ == '__main__':
            main()
        

        MAXON SDK Specialist
        developers.maxon.net

        1 Reply Last reply Reply Quote 0
        • ferdinandF
          ferdinand
          last edited by ferdinand

          Hello @RenoBozo,

          without any further questions or postings, we will consider this thread as solved by Friday the 4th, February 2022.

          Thank you for your understanding,
          Ferdinand

          MAXON SDK Specialist
          developers.maxon.net

          1 Reply Last reply Reply Quote 0
          • ferdinandF ferdinand referenced this topic on
          • First post
            Last post