PDA

View Full Version : Set Keyframe in R12 with Python?


visualride
06-19-2012, 10:42 PM
I've been struggling with trying to set non-standard keyframes(they don't change with the record button) within Cinema 4D R12 on OSX. I've written code that I thought would work, but didn't.
This code does create an 'Enabled' curve and adds a key, but it does not add the correct amount (I want '1' -Enabled), and the key is strange because it isn't showing up as red, or actually keyframed, but the key is showing in the timeline. The "keyy.SetValue(crv,1)" line doesn't seem to be working.
Since this is R12 I don't have the following classes to use: FindCTrack, FillKey, or SetGeData among others. Anyone have an idea?
Note: This is a similar post to one that I posted a few weeks ago with some great feedback, but I still haven't gotten it to work yet.
import c4d, math
from c4d import gui
#Welcome to the world of Python

def main():
myDoc = c4d.documents.GetActiveDocument()
Selected = doc.GetActiveObjects(0)
fps = myDoc.GetFps()

if len(Selected)>0:
for ListOb in Selected:

visE = c4d.CTrack(ListOb, c4d.DescID(c4d.ID_BASEOBJECT_GENERATOR_FLAG))
ListOb.InsertTrackSorted(visE)

#ListOb[c4d.ID_BASEOBJECT_GENERATOR_FLAG] = 1
t = doc.GetTime().Get()
crv = visE.GetCurve()
keyy = crv.AddKey(c4d.BaseTime(t))['key']
keyy.SetValue(crv,1)

c4d.EventAdd()

else:
gui.MessageDialog('You must select an Object first!')

if __name__=='__main__':
main()

Scott Ayers
06-20-2012, 01:17 AM
I'm not sure if this is what you're trying to do or not.
But this code will turn off the visibility option on any selected object. And also set a key for it. import c4d, math
def main():
myDoc = c4d.documents.GetActiveDocument()
Selected = doc.GetActiveObjects(0)
fps = myDoc.GetFps()

if len(Selected)>0:
for ListOb in Selected:

visE = c4d.CTrack(ListOb, c4d.DescID(c4d.ID_BASEOBJECT_GENERATOR_FLAG))
ListOb.InsertTrackSorted(visE)

ListOb[c4d.ID_BASEOBJECT_GENERATOR_FLAG] = 1 #Turn off visible option
t = doc.GetTime().Get()
crv = visE.GetCurve()
keyy = crv.AddKey(c4d.BaseTime(t))['key']
keyy.SetGeData(visE.GetCurve(),0) #Sets the first key(0) to a value of 1

c4d.EventAdd()
c4d.DrawViews(c4d.DRAWFLAGS_FORCEFULLREDRAW) #Update the scene view changes

if __name__=='__main__':
main()

visualride
06-20-2012, 02:08 AM
All right! Thanks a lot Scott!
This line did it for me:
keyy.SetGeData(visE.GetCurve(),0) #Sets the first key(0) to a value of 1
I'm surprised that it did work because 'SetGeData' is not listed in the R12 documentation, but it is in R13.

CGTalk Moderation
06-20-2012, 02:08 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.