Create User Data with Data Type Spline
-
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()
-
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 isCUSTOMDATATYPE_SPLINE
. YourAddUserData
call does also make little sense, there is no function with such signature in our API. Also theuserdata.GetData()
call is equally nonsensical.Find below an example for adding a
SplineData
user parameter.Cheers,
FerdinandResult:
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()
-
Thanks, clear now.
I will stop using ChatGPT.Regards,
Pim -
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