Need help getting an old script to work in C4D
-
Hey all, I found this post from 11+ years ago by a user named
"bandini" that has a bit of code to bake animations. I am trying to update the code so that it works with the current version of C4D. Any help would be appreciated! Thanks!https://forums.cgsociety.org/t/holy-grail-bake-mograph-objects-to-keyframes/1296975/10
This is what I've converted so far but I am receiving an error on line 11 that says:
in <module>
while current_frame <= user_end_time:
NameError: name 'StopAllThreads' is not definedHere is the "updated" script that is giving me the error
user_start_time = 0 user_end_time = 90 fps = doc.GetFps() bake_start_time = doc.GetTime() # needed to initialize a BaseTime object doc.SetTime(bake_start_time) # set the time slider to the user's start time current_frame = doc.GetTime().GetFrame(fps) while current_frame <= user_end_time: StopAllThreads() CallCommand(12410) # record user_start_time += 1 doc.SetFrame(user_start_time) # Set the current frame of the time slider redraw = DrawViews(DA_STATICBREAK) EventAdd(EVENT_ANIMATE) if redraw: current_frame = doc.GetTime().GetFrame(fps)
-
Maybe add
c4d
? Likec4d.StopAllThreads()
? -
When I try that, I get an error that says "NameError: name 'c4d' is not defined"
-
because your have to add
import c4d
at the start of every c4d script. -
Thank you, by adding the "import c4d" at the beginning of the script and "c4d." in front of the lines below, that solved the issues with the
StopAllThreads()
CallCommand(12410) # recordHowever, now line 16 says:
line 16, in <module>
c4d.SetFrame(user_start_time) # Set the current frame of the time slider
AttributeError: module 'c4d' has no attribute 'SetFrame' -
Here are the scripts (original and modified), as well as the c4d file if that is helpful
https://www.dropbox.com/sh/vwnkj9x08b9dg0k/AACWhSoQV4rYo3ECMkNIZ2Kda?dl=0
-
Hi @bstone
Thanks for providing the modified script.
API changed throughout the release. One of those probably is theSetFrame
(i.e no longer exist).Here's what I have.
import c4d user_start_time = 0 user_end_time = 90 fps = doc.GetFps() bake_start_time = doc.GetTime() # needed to initialize a BaseTime object doc.SetTime(bake_start_time) # set the time slider to the user's start time current_frame = doc.GetTime().GetFrame(fps) while current_frame <= user_end_time: c4d.StopAllThreads() c4d.CallCommand(12410) # record user_start_time += 1 #doc.SetFrame(user_start_time) # Set the current frame of the time slider pTime = c4d.BaseTime(user_start_time,fps) doc.SetTime(pTime) redraw = c4d.DrawViews(c4d.DA_STATICBREAK) c4d.EventAdd(c4d.EVENT_ANIMATE) if redraw: current_frame = doc.GetTime().GetFrame(fps)
-