This last year I started learning how to script with Python and tried to improve my skills every day. While I'm no expert at all, I'm starting to understand the whole secret behind Python, and finally managed to develop some tools that help me on my daily work. This first one, which I want to share with this community that helped me so much since I started in this industry is just a little script which checks the selected object's tracks, and their keyframes and deletes them if the track has only one keyframe, or if the whole track has multiple keyframes, but all with the same value. I don't really know if there is already something out there taht does the same, or maybe if MAXON has already implemented a function like this into Cinema 4d, anyway, I'll be happy if it is useful to anyone starting with C4DPy, because there is so little information about Python scripting out there.
The script is written as easy as I could, and trying to keep it simple and easy to understand. I added a lot of comments to understand the code. It also prints a lot of stuff to the console, so you can read what's happening once executed.
Just download the file and unzip into your lybrary-> scripts folder
You can also download it from my website: www.ivanpais.es
I would be super happy if anybody finds errors, bugs, or or any kind of possible improvement.
Here is the code for you to learn, change, destroy, or whatever you like!
#Sript created by Iván Pais
#Please check out my website www.ivanpais.es
#Feel free to contact me through firstname.lastname@example.org
#I would be super happy if you take me into account for freelance work and collaborations
from c4d import gui
def checkEqual(lst): #Checks if the values inside a list are equal
return lst[1:] == lst[:-1]
print (lst[1:] == lst[:-1])
actobjs = doc.GetSelection() #Get seletion list
for obj in actobjs: #Loop for every object
tracks = obj.GetCTracks() #Gets object's tracks
counter = 0
for t in tracks: #Loop for every track
if "Visible" in str(t): #Checks if it's a visibility track, and avoids the loop'
if "Sound" in str(t): #Checks if it's a sound track, and avoids the loop'
tcurve = t.GetCurve() #Get Curve of this track
print "Curve for track %s is %s, " %(counter,tcurve)
kcount = t.GetCurve().GetKeyCount()#Get key count of this track
print "This track has %s keys" % (kcount)
keylist = #Creates a list with all keys
for x in range(int(kcount)):
print "Keys of this track are %s" % keylist
valuelist = #Creates a list with the values stored in keyslist
for x in keylist:
valuelist.append(x.GetValue())#Gets the keys in keylist and appends it's value to valuelist'
if checkEqual(valuelist) == True: #Passes valuelist to checkEqual function to check if all values are the same
t.Remove() #Removes that track if true
c4d.EventAdd(c4d.EVENT_FORCEREDRAW) #Foreces redraw to apply changes