Solved Store SplineData inside a Container

Is is possible to store a SplineData object inside a Container?
Or must I store all the data points as vector data inside a subcontainer?

Ok, fixed it, using InsData.

Ok, fixed it, using InsData.

Hey @rui_mac,

thank you for reaching out to us. It is great to hear that you solved your problem yourself. I would however recommend to use BaseContainer.SetData.

As a brief explanation, because the Python docs are not too clear on what can be written with SetData, and not all users/readers might be familiar with the C++ API. The SetData and GetData methods in C++ allow you to write anything that can be expressed as GeData into a BaseContainer. That type is not exposed in Python. When looking at the GeData documenation in C++, we can see that there is the constructor GeData (Int32 type, const CustomDataType &data), i.e., CustomDataType can be wrapped as GeData, i.e., SplineData can be written into a BaseContainer. Because this also comes up from time to time, you should be aware that the data is being copied. See example at the end of my posting for details.


"""Demonstrates how to write SplineData into a BaseContainer.

import c4d

def UnpackData(bc: c4d.BaseContainer, cid: int) -> None:
    data: any = bc.GetData(cid)
    if not isinstance(data, c4d.SplineData):

    print("\nThe first two knots of the spline in the container:")
    for i, knot in enumerate(data.GetKnots()[:2]):
        print (i, knot)

def main() -> None:
    # Create a spline data instance and use MakeCubicSpline() to generate some data in it.
    spline: c4d.SplineData = c4d.SplineData()

    # Iterate over the knots.
    print("The first two knots of the original spline:")
    for i, knot in enumerate(spline.GetKnots()[:2]):
        print (i, knot)

    # Store the SplineData in a BaseContainer. The data will be copied, so any modification made
    # to #spline after inserting it, will not be reflected.
    print ("\nWriting spline into container.")
    bc: c4d.BaseContainer = c4d.BaseContainer()
    bc.SetData(1000, spline)

    # Modify the first knot of the spline.
    spline.SetKnot(0, c4d.Vector(1), c4d.FLAG_KNOT_T_BREAK)

    print("\nThe first two knots of the modified spline:")
    for i, knot in enumerate(spline.GetKnots()[:2]):
        print (i, knot)

    UnpackData(bc, 1000)

if __name__ == '__main__':

MAXON SDK Specialist