I created a simple IK rig manually in the object manager and it works fine. It's a folding door. When I move the the goal object (g) the door opens or closes.
I recreated this in a Python Generator, but when I try to move the goal via code using a slider on the interface it only moves the goal but it ignores the ik rig.
def make_folding_door(width: int, hinge_side: int, opening: int) -> c4d.BaseObject(c4d.Onull):
def make_cube(width: float = 15.0, height: float = 196.0, thickness: float = 1) -> c4d.BaseObject(c4d.Ocube):
cube = c4d.BaseObject(c4d.Ocube)
cube[c4d.PRIM_CUBE_LEN] = c4d.Vector(width, height, thickness)
return cube
g = c4d.BaseObject(c4d.Onull)
def create_blades() -> c4d.BaseObject(c4d.Onull):
root = c4d.BaseObject(c4d.Onull)
root.InsertUnder(door)
root[c4d.ID_BASEOBJECT_REL_POSITION,c4d.VECTOR_X] = 5.0
root[c4d.ID_BASEOBJECT_REL_POSITION,c4d.VECTOR_Y] = 99.5
g.InsertUnder(root)
g[c4d.ID_BASEOBJECT_REL_POSITION,c4d.VECTOR_Z] = -0.5
gc = make_cube(5.0)
gc.InsertUnder(g)
gc.SetRelPos(c4d.Vector(2.5, -0.5, 0.5))
p_1 = c4d.BaseObject(c4d.Onull)
p_1.InsertUnder(root)
p_1[c4d.ID_BASEOBJECT_REL_POSITION,c4d.VECTOR_Z] = -0.5
p_1[c4d.ID_BASEOBJECT_REL_ROTATION,c4d.VECTOR_X] = c4d.utils.DegToRad(-90.0)
ik_tag = c4d.BaseTag(c4d.Tcaik)
p_1.InsertTag(ik_tag)
c_1 = make_cube(7.0)
c_1.InsertUnder(p_1)
c_1.SetRelPos(c4d.Vector(3.5, -0.5, 0.5))
pe = c4d.BaseObject(c4d.Onull)
pe[c4d.ID_BASEOBJECT_REL_ROTATION,c4d.VECTOR_X] = c4d.utils.DegToRad(-180.0)
ce = make_cube(7.0)
ce.InsertUnder(pe)
ce.SetRelPos(c4d.Vector(3.5, -0.5, -0.5))
e = c4d.BaseObject(c4d.Osphere)
e[c4d.ID_BASEOBJECT_GENERATOR_FLAG] = False
e[c4d.PRIM_SPHERE_RAD] = 0.1
e.InsertUnder(pe)
e.SetRelPos(c4d.Vector(7.0, 0.0, -1.0))
if width <= 1:
p0 = c4d.BaseObject(c4d.Onull)
p0.InsertUnder(p_1)
p0.SetRelPos(c4d.Vector(7.0, 0.0, 1.0))
p0[c4d.ID_BASEOBJECT_REL_ROTATION,c4d.VECTOR_X] = c4d.utils.DegToRad(-180.0)
c0 = make_cube()
c0.InsertUnder(p0)
c0.SetRelPos(c4d.Vector(7.5, -0.5, -0.5))
p1 = c4d.BaseObject(c4d.Onull)
p1.InsertUnder(p0)
p1.SetRelPos(c4d.Vector(15.0, 0.0, -1.0))
p1[c4d.ID_BASEOBJECT_REL_ROTATION,c4d.VECTOR_X] = c4d.utils.DegToRad(-180.0)
c1 = make_cube()
c1.InsertUnder(p1)
c1.SetRelPos(c4d.Vector(7.5, -0.5, 0.5))
pe.InsertUnder(p1)
pe.SetRelPos(c4d.Vector(15, 0.0, 1.0))
g[c4d.ID_BASEOBJECT_REL_POSITION,c4d.VECTOR_X] = 4.0
ik_tag[c4d.ID_CA_IK_TAG_TIP] = e
ik_tag[c4d.ID_CA_IK_TAG_TARGET] = g
return p_1
elif width == 2:
return p_1
elif width == 3:
return p_1
else:
return p_1
blades = create_blades()
g.SetRelPos(c4d.Vector(frm_w * opening, 0.0, 0.0))
return door
If I make the the Python Generator editable, it recreates the hierarchy correctly with the IK tag with the 'end' and 'goal' set and the IK rig works when I move the goal.
Is there anything I'm missing?
PS: I know I could probably make the code shorter with a for loop, but first I want to make it step by step to make sure I'm doing everythig right.