PDA

View Full Version : Setting keyframes with C.O.F.F.E.E. script


visualride
05-10-2012, 10:57 PM
Is it possible to set visibility keyframes with a script with C.O.F.F.E.E.? If so, how?

littledevil
05-11-2012, 08:55 AM
yes, it is. use the search function.

visualride
05-14-2012, 06:34 PM
This is in the C.O.F.F.E.E. SDK help file:
Note: Currently it is not possible to allocate tracks, curves or keys in C.O.F.F.E.E.

So, yes, I did use the search and this is what I came up with and needed confirmation that it was impossible to create a keyframe in with a C.O.F.F.E.E. script in C4D.

Any suggestions?

Horganovski
05-15-2012, 07:28 AM
You could have a COFFEE script change the visibility settings and then record a keyframe on the object, but it would just be using the regular record keyframe command so you'd need to add a keyframe selection for that attribute so that it would get recorded along with the regular transform attributes. Not ideal obviously.

Python can definitely do it though, I'm only getting started with keys/timeline stuff in C4D with it though so can't post an example yet. If I get time to figure it out I'll post the results as it's something that would be useful for me too.

Cheers,
Brian

Horganovski
05-15-2012, 08:08 AM
Hmmm, I hacked some Python together that will create visibility tracks for the selected objects. But when I set a key on that track (on frame zero in this example) the key is yellow. The problem might be related to the fact that Visibility keys don't show up in the FCurves, ie it's impossible to read their value from the timeline like it is for other attributes (which is pretty weird). I assumed there would be boolean values but there are 3 states (default, on, off) which I thought would mean 0,1,2 but setting those values for the key does not fix it.

So, stumped for the moment, but I'll ask around and see if I can get some more info.


import c4d
from c4d import gui

dVis = c4d.DescID(c4d.ID_BASEOBJECT_VISIBILITY_RENDER) #assign the DescID to a var for convenience


objList=doc.GetActiveObjects(True)# get the selected objects
lstSize = len(objList)# count how many objects are selected
# loop through each selected object
c=0
while (c<lstSize):
tVis = objList[c].FindCTrack(dVis) #find the track
if not tVis: #if track isn't found, create it
tVis = c4d.CTrack(objList[c],dVis)
objList[c].InsertTrackSorted(tVis)
key = c4d.CKey()
curve = tVis.GetCurve()
keyDict = curve.AddKey(c4d.BaseTime(0))
#objList[c][c4d.ID_BASEOBJECT_VISIBILITY_RENDER]=2 # just a test - trying to brute-force it ;)
keyDict["key"].SetValue(curve,2)

c=c+1

c4d.EventAdd()

RickBarrett
05-15-2012, 05:20 PM
You need to use SetGeData instead of SetValue in this case, because you're setting a LONG rather than a float.

Here's a Cineversity wiki article describing how to create tracks & keys using Python:
http://www.cineversity.com/wiki/Python%3A_DescIDs_and_Animation/

Horganovski
05-15-2012, 06:53 PM
Thanks Rick!

With a lot of Ricks help on another forum I was able to cobble this together. This will add a Visible in Render key to the selected objects on whatever frame the playhead is on. You can change the 'visState' variable to set whether that's an On or Off key. NB a value of 0 is On and 1 is Off, so don't think of it as a regular boolean value (because there's a 3rd possible value '2' which means 'Default')


import c4d
from c4d import gui

visState =0 # this is the variable that determines whether the visibility will be on or off. NB - 0 for on, 1 for off
curTime=doc.GetTime()# get the current time of the playhead so we can add a key on the current frame
dVis = c4d.DescID(c4d.ID_BASEOBJECT_VISIBILITY_RENDER) #assign the DescID to a var for convenience

objList=doc.GetActiveObjects(True)# get the selected objects
lstSize = len(objList)# count how many objects are selected
# loop through each selected object
c=0
while (c<lstSize):
tVis = objList[c].FindCTrack(dVis) #find the track
if not tVis:#if track isn't found, create it
tVis = c4d.CTrack(objList[c],dVis)
objList[c].InsertTrackSorted(tVis)
curve = tVis.GetCurve()
keyDict = curve.AddKey(curTime)
tVis.FillKey(doc, objList[c], keyDict["key"])
keyDict["key"].SetGeData(curve,visState)
c4d.EventAdd()
c=c+1

c4d.EventAdd()
c4d.CallCommand(12147)#redraw the scene

visualride
05-15-2012, 09:25 PM
Hey, thanks guys! Exactly what I need. I'm just getting started with Python also, and this should to be a good primer.

Horganovski
05-15-2012, 09:50 PM
Glad it helps, I've been tinkering with Python for about two weeks or so now I guess and there are still huge holes in my knowledge but I'm gradually building more complex scripts I can build off. I'm making a habit of leaving lots of comments in all of the scripts so they are easier to dissect when someone else reads them (or I re-read them a couple of weeks later ; ) )

Cheers,
Brian

visualride
05-16-2012, 05:43 PM
This is good code. My coding experience comes from writing AutoLisp code to automate AutoCAD tasks. In that editor, you can step through the code and see the output from selected lines or loops. Do you have any recommendation for a more advanced editor for C4D to get more realtime feedback as you step through code? I'm sure that there is a line of code that I could insert to output, somehow, the current values of variables.

Horganovski
05-16-2012, 07:06 PM
I generally use the free Notepad ++ editor when I'm working with Python in Cinema or MEL in Maya, I find it pretty good and it supports both of those languages well.

Regarding seeing the values of variables, I just add 'print' commands to the script while developing it and leave the script console open while working so I can see the results or any errors etc due to typos.

Cheers,
Brian

CGTalk Moderation
05-16-2012, 07:06 PM
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.