I have created a Python Generator that looks at the hierarchy of it's children and generates a spline through them all. This part all works fin.
However, when I create a Spline Wrap object and set the Python Generator as it's spline, nothing happens. Is there a way I can get a Spline Wrap object to use a spline created by a Python Generator?
No. If I remember correctly from a previous discussion, a Python Generator does not bear a certain flag that is needed to signify a spline. (You can try to find that conversation with the Search function if you want to know what the flag was called...)
I tried searching for that post, but I couldn't find it.
I'm trying a slightly different approach now by using a python tag on a spline object. It's almost working but I'm having update issues.
hmm, now I can't find that thread either. Maybe it was on a different forum. Or maybe I'm totally wrong, in which case I hope a Maxon person will be able to clarify.
Anyway, you could try to write a generator plugin, where OBJECT_GENERATOR and OBJECT_ISSPLINE are set. I believe the latter flag was the crucial one.
The issue is that a Python Generator cannot / does not implement GetContour(), which is supposed to be used to create splines, not GetVirtualObjects().
@PluginStudent ah, thanks. Strange that I was thinking of a flag.
Anyway, it still doesn't work
Actually your answer was correct. For an ObjectData plugin you need to set the flags OBJECT_GENERATOR and OBJECT_ISSPLINE upon registration, to tell Cinema that is should poll GetContour and not GetVirtualObjects for building the cache of the object.
As pointed out, this a shortcoming of the Python Generator Object, which is basically treated like a GetVirtualObjects method. However, if implementing a whole plugin seems out of the question, you could use a Python Scripting Tag, ignore are all warnings and fiddle with the cache of the Python Generator Object, extract whatever spline data is in there and link it to your wrap deformer. Below you will find a simple example for how you would do that.
The Python Scripting Tag:
""" Put this into a Python Scripting Tag.
The Python Scripting Tag needs to be attached to the Spline Wrap Deformer,
which is meant to be driven by a Python Generator Object. The script
requires the tag to have a BaseLink as its first user data element, linking
to the Python Generator Object.
This is not by any means an intended use of the Cinema API. The major
problem is that messing with the cache of the generator by
linking it back into the document is a big No-No. Although I think you
are here on the safe side, it might cause Cinema 4D to crash or worse -
silently corrupt the document. THIS IS A HACK - you have been warend.
Also might casue little kittens to be very sad.
# The Python scripting tag needs a BaseLink element linking to the
# Python generator object as its first user data element.
source = op[c4d.ID_USERDATA, 1]
deformer = op.GetObject()
# Sort out some invalid inputs
if not isinstance(source, c4d.BaseObject):
if not isinstance(deformer, c4d.C4DAtom):
if not deformer.CheckType(c4d.Owrap):
# Get the cache of the Python generator node, prefering the deformed
# cache over the static cache.
cache = source.GetDeformCache() or source.GetCache()
# Set the cache as the MGSPLINEWRAPDEFORMER_SPLINE attribute of the
# wrap deformer, given that there is a cache.
deformer[c4d.MGSPLINEWRAPDEFORMER_SPLINE] = cache
The Python Generator object I did use:
Thanks @moGRR for reaching out us.
With regard to your question, as pointed out by @zipit, it's not possible to have a Python Generator to generate object which can be recognized as real spline by generators/deformers expecting a spline as input due to the Python Generator flags used in its registration.
Beside the option mentioned by @zipit I also invite to have a look at this post where it's presented a generator outputting spline and accepting splines as input.