Hi,
I need to set a keyframe through a python tag. This means if I change something a frame and a value in the code, it updates in the affected object.
I watched this tutorial. It also uses a python tag but unfortunately, once you set the keyframe, you have to modify it on the timeline rather than within the code.
Here is my code so far, assuming a simple primitive cube in the scene:
import c4d
def set_keyframe(obj, objParameter, frameList, valueList):
old_tracks = obj.FindCTrack(objParameter)
# Remove existing track and create a new one. This ensures that the only track available in the object is within the code
if old_tracks:
old_tracks.Remove()
new_track = c4d.CTrack(objParameter)
obj.InsertTrackSorted(new_track)
curve = atrck.GetCurve()
# This is the part that I don't know what I'm doing.
for (frame,value) in zip(frameList,valueList):
curve.AddKey (c4d.BaseTime(frame, 24))
atrck.FillKey(doc, obj, value )
set_keyframe(
obj = doc.SearchObject("Cube"),
objParameter = c4d.ID_BASEOBJECT_REL_POSITION,c4d.VECTOR_Y, # Assuming the selected object is
frameList = [0,30,45],
valueList = [100,-250,20]
)
Is there a way around this?
Thank you for looking at the problem.