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

    Create User Data with Data Type Spline

    Cinema 4D SDK
    python 2023
    2
    4
    844
    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

      I want to add user data with type Spline.
      However DTYPE _SPLINE is not recognized?
      AttributeError: module 'c4d' has no attribute 'DTYPE_SPLINE'

      What am I doing wrong?

      import c4d
      
      def main():
          # Get the active document
          doc = c4d.documents.GetActiveDocument()
          
          # Add user data for the spline
          userdata_id = c4d.DescID(c4d.DescLevel("MySpline", c4d.DTYPE_SPLINE, 0))
          userdata = op.AddUserData(userdata_id, "MySpline", c4d.CUSTOMGUI_SPLINE)
          
          # Set the spline data for the user data
          userdata_data = userdata.GetData()
          userdata_data.SetData(c4d.DESC_NAME, "MySpline")
          userdata_data.SetData(c4d.DESC_DEFAULT, c4d.SplineData())
          userdata_data.SetData(c4d.DESC_ANIMATE, c4d.DESC_ANIMATE_ON)
          userdata_data.SetData(c4d.DESC_UNIT, c4d.DESC_UNIT_REAL)
          userdata_data.SetData(c4d.DESC_CUSTOMGUI, c4d.CUSTOMGUI_SPLINE)
          userdata_data.SetData(c4d.DESC_SCALEH, 100)
          userdata_data.SetData(c4d.DESC_CUSTOMGUI, spline_data)
          
          
          # Update the document
          c4d.EventAdd()
      
          
      if __name__ == '__main__':
          main()
      
      ferdinandF 1 Reply Last reply Reply Quote 0
      • ferdinandF
        ferdinand @pim
        last edited by ferdinand

        Hello @pim,

        Thank you for reaching out to us. As announced here, Maxon is currently conducting a company meeting. Please understand that our capability to answer questions is therefore limited at the moment.

        To be frank here, your code looks a bit ChatGPT-ish, it at least invents things, contains syntax which simply does not exist. Please disclose the usage of ChatGPT.

        Something like DTYPE_SPLINE simply does not exist, because the GUI and datatype are custom as you point out yourself in your other thread. As the c4d.SplineData page will tell you, the plugin/data type ID symbol for the class is CUSTOMDATATYPE_SPLINE. Your AddUserData call does also make little sense, there is no function with such signature in our API. Also the userdata.GetData() call is equally nonsensical.

        Find below an example for adding a SplineData user parameter.

        Cheers,
        Ferdinand

        Result: cfca5d3a-95df-4029-8e58-707fe98a2e98-image.png

        Code:

        """Adds a SplineData user data parameter to the selected object.
        
        Must be run as a Script Manager script with at least one object selected. This script is using
        Python 3.10 syntax, i.e., can only be run 2023.2 or higher. Remove the line `op: c4d.BaseObject |
        None` to make the script run in older versions.
        """
        
        import c4d
        
        doc: c4d.documents.BaseDocument # The active document.
        op: c4d.BaseObject | None # The selected object, can be #None.
        
        def main():
            """Runs the example.
            """
            if not op:
                raise RuntimeError("Please select an object.")
        
            # Create a description container for the data type CUSTOMDATATYPE_SPLINE.
            bc: c4d.BaseContainer = c4d.GetCustomDataTypeDefault(c4d.CUSTOMDATATYPE_SPLINE)
            bc[c4d.DESC_NAME] = "MySpline" # Set the name of the parameter.
            bc[c4d.DESC_SHORT_NAME] = "MySpline" # Set the name of the parameter.
            # Disable the horizontal grid lines in the SplineCustomGui. This is just one of the many special
            # description settings this GUI does come with. As always, you will find them documented under
            # the custom GUI.
            bc[c4d.SPLINECONTROL_GRID_H] = False
        
            # Add a new user data parameter for the container.
            paramId: c4d.DescID = op.AddUserData(bc)
        
            # Create a new spline using the cubic interpolation preset with five points and write the spline
            # to our new parameter. Then push an update event to Cinema 4D.
            spline: c4d.SplineData = c4d.SplineData()
            spline.MakeCubicSpline(5)
            op[paramId] = spline
            
            c4d.EventAdd()
        
            # Some of your code. I really do not want to be rude here, and when you have written this 
            # yourself, my apologies, but this looks very much like ChatGPT gibberish to me.
        
            # Meaningless, default values are booleans for groups.
            # userdata_data.SetData(c4d.DESC_DEFAULT, c4d.SplineData())
        
            # Redundant, the default value is on.
            # userdata_data.SetData(c4d.DESC_ANIMATE, c4d.DESC_ANIMATE_ON)
        
            # Meaningless, splines have no unit.
            # userdata_data.SetData(c4d.DESC_UNIT, c4d.DESC_UNIT_REAL)
        
            # Meaningless, splines only have this UI.
            # userdata_data.SetData(c4d.DESC_CUSTOMGUI, c4d.CUSTOMGUI_SPLINE)
            
            # More gibberish.
            # userdata_data.SetData(c4d.DESC_SCALEH, 100)
            # userdata_data.SetData(c4d.DESC_CUSTOMGUI, spline_data)
        
        if __name__ == '__main__':
            main()
        

        MAXON SDK Specialist
        developers.maxon.net

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

          Thanks, clear now.
          I will stop using ChatGPT.

          Regards,
          Pim

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

            Hey @pim,

            It is great to hear that your problem is solved. And to be clear: You can use ChatGPT and Co. to write your code; I would simply ask you to disclose it if you post code (partially) generated by a bot.

            We understand and agree that chat bots can be a useful tool especially for beginners. But they also have a tendency to write code that is just made up gibberish. When we know that the code has been written by a bot, we can say "that is just noise/garbage". If we do not, we have to point out all problems individually, not only to not offend the author by calling his or her code "garbage", but to also to help the user to understand his or her mistakes.

            Cheers,
            Ferdinand

            MAXON SDK Specialist
            developers.maxon.net

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