SOLVED Unexpected Spline Behavior on Creating IK Spline Tag

Hi,

I'm trying to create an IK Spline Tag with an existing spline/curve object.
The problem is whenever I run the code, the spline interpolation is replaced.
You can see an illustration video of the problem here:
https://www.dropbox.com/s/50thcrfnaepme3z/c4d091_spline_interpolation_maintain.mp4?dl=0

You can check the illustration file here:
https://www.dropbox.com/s/fgkfh8jg7624z4l/c4d091_spline_interpolation_maintain.c4d?dl=0

Is there a way around this?

Thank you for looking at the problem.

Here is the code I used:

import c4d

def list_children(obj, withParent=1):
    if withParent:
        objList = [obj]
    else:
        objList = []

    for kid in obj.GetChildren():
        objList += list_children(kid)
    return objList

def torso_spline():
    spine_chain = list_children(doc.SearchObject("spine01_jnt"))

    start_ikHandle = c4d.BaseObject(c4d.Onull)
    start_ikHandle.SetMg(spine_chain[0].GetMg())
    start_ikHandle.SetName( (spine_chain[0].GetName()) + "_ikHandle" )
    doc.InsertObject(start_ikHandle)

    end_ikHandle = c4d.BaseObject(c4d.Onull)
    end_ikHandle.SetMg(spine_chain[6].GetMg())
    end_ikHandle.SetName( (spine_chain[6].GetName()) + "_ikHandle" )
    doc.InsertObject(end_ikHandle)

    spine_crv = doc.SearchObject("spine_crv")
    
    # Create IK Spline tag
    
    ikSpline_tag = spine_chain[0].MakeTag(1019862)
    doc.AddUndo(c4d.UNDOTYPE_NEW, ikSpline_tag)
       
    ikSpline_tag[c4d.ID_CA_IKSPLINE_TAG_SPLINE]    = spine_crv    # error in this. it changes the curve. 
    ikSpline_tag[c4d.ID_CA_IKSPLINE_TAG_END]       = spine_chain[6]
    ikSpline_tag[c4d.ID_CA_IKSPLINE_TAG_TYPE]      = c4d.ID_CA_IKSPLINE_TAG_TYPE_EQUAL
    
    # Add IK handles
    
    c4d.CallButton(ikSpline_tag, c4d.ID_CA_IKSPLINE_HANDLE_ADD)
    c4d.CallButton(ikSpline_tag, c4d.ID_CA_IKSPLINE_HANDLE_ADD)
    
    ikSpline_tag[10002] = start_ikHandle
    ikSpline_tag[10012] = end_ikHandle

torso_spline()
c4d.EventAdd()

Kindly ignore the query above.
I think this is more of a rigging question rather than a coding questing.
Anyhow, in the IK spline tag, if you set the align and aim axis to X rather than default Z.
And set the offset from 10cm to like 50cm.

It should work more or less as expected.

Thanks!

Hi @bentraje, since you rotate the axis (with SetMg) you also need to update the tangents according to the correct axis since tangents are in local space of points positions which are also in local space of the object.

But as you figured is more rigging than a programming issue. And if you already solve the issue congratz! 😉

Cheers,
Maxime.