Curves Data vs Spline Data?

Hi,

I’m trying to create a spline through python with this code . It works as expected.
However, the way the code is set-up is a bit confusing.

Currently, the flow goes like this:

1) Create Curve Data through bpy.data.curves.new
2) Modify Parameters
3) Create Spline Data through bpy.data.curves.spline.new
4) Modify Points 
5) Create Object using Curve Data
6) Insert Object in the Scene

Q1: In line #3, Where did the bpy.data.curves.spline.new come from?
I check the documentation for the curves. It has no whatsoever subclass for Spline. It only has SurfaceCurve, TextCurve.

So I was wondering how did the bpy.data.curves.spline.new be valid?
Couldn’t it just be bpy.data.spline.new if spline is a separate type?

Q2: In line #5, it creates objects using the curve data, which was weird since up to #3 curveData as a variable was no longer being used. Shouldn’t the spline data a more appropriate way to create the object?

Sorry for the dry questions. Just really confused on how the API was set-up.

Thank you for looking at my problem.

I’ll try to at least partially answer the questions, and i’ll excuse myself if i’m not entirely correct, but here goes:

Q1:
bpy.data.curves.spline.new is not a valid statement, the class bpy.types. Curve ( ID ) is essentially a container for a collection of splines. So the flow on the code you linked is slightly different to what you describe:

  1. Create a curve container - bpy.data.curves.new
  2. Modify container parameters
  3. Create a spline object in the collection - bpy.types. CurveSplines.new
  4. Insert point data in the spline

I’m not sure if you have misunderstood of how objects in python work since

polyline = curveData.splines.new('NURBS')

isn’t combined with the earlier statement to form a statement bpy.data.curves.spline.new. It refers to calling the function new defined for the object in the splines variable contained in the curveData object created by calling bpy.data.curves.new

Q2:
Since the spline data is contained in the curve object, the ‘object’ object is created with both the curve data and the spline data. This is perhaps slightly confusing but it makes sence when you consider that a curve object, when edited and interacted with, may contain multiple separate curves. Therefor the data of such an object must be a collection, and the spline created in #3 is automatically added to the collection when created. Hence the spline data is also passed to the construction of the ‘object’ object not only the curve data :slight_smile:

Final Note:
The code you linked is also not compliant with 2.80, but since you refered to the 2.80 api i did the same since the non-compliant code only refer to how objects are linked with the scene.

1 Like

Q1:

isn’t combined with the earlier statement to form a statement bpy.data.curves.spline.new

You are right completely right. I misunderstand this one. Thanks for the clarification

Q2

Therefor the data of such an object must be a collection, and the spline created in #3 is automatically added to the collection when created.

Oh okay. I initially thought spline data is a separate thing. I was expecting something like this

3) Create Spline Data through bpy.data.curves.spline.new
4) Modify Points 
4.5) Add Spline Data to Curve Data
5) Create Object using Curve Data

Clearly I was wrong. I forgot what specific feature is in some methods, but basically I think its like list.sort(). You don’t need to create another sorted list. The original list will be sorted.

RE:Final note

Yea, sure I appreciate. I’m using 2.8 at the moment :slight_smile: I think, I changed the link line to this scene.collection.objects.link(object) for it to work.

Thanks again. Have a great day ahead!