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.
-
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. TheSetData
andGetData
methods in C++ allow you to write anything that can be expressed as GeData into aBaseContainer
. That type is not exposed in Python. When looking at theGeData
documenation in C++, we can see that there is the constructorGeData (Int32 type, const CustomDataType &data)
, i.e.,CustomDataType
can be wrapped asGeData
, i.e.,SplineData
can be written into aBaseContainer
. 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.Cheers,
Ferdinand"""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): return 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() spline.MakeCubicSpline(lPoints=4) # 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__': main()