Created
February 4, 2024 08:17
-
-
Save Evilsine/181156262078428996d4d71b9f149d60 to your computer and use it in GitHub Desktop.
C4D script that deletes unnecessary keyframe tracks(tracks with no value change) on select objects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import c4d | |
doc: c4d.documents.BaseDocument # The currently active document. | |
op: c4d.BaseObject | None # The primary selected object in `doc`. Can be `None`. | |
def allEqual(iterator): | |
iterator = iter(iterator) | |
try: | |
first = next(iterator) | |
except StopIteration: | |
return True | |
return all(first == x for x in iterator) | |
def main() -> None: | |
doc.StartUndo() | |
sel = doc.GetActiveObjects(0) | |
for obj in sel: | |
tracks = obj.GetCTracks() | |
for track in tracks: | |
curve = track.GetCurve() | |
keyCount = curve.GetKeyCount() | |
keys = [] | |
for key in range(keyCount): | |
keys.append(curve.GetKey(key).GetValue()) | |
if allEqual(keys) == True: | |
doc.AddUndo(c4d.UNDOTYPE_DELETE, track) | |
track.Remove() | |
doc.EndUndo() | |
c4d.EventAdd() | |
if __name__ == '__main__': | |
main() |
not working :( , any tips?
which version of c4d are you on? and does it output any error in the python console when you run the script?
I use c4d 2023, in the python console it does not run :(
I tested the script in 2023.2.2 and it's working fine for me. just to make sure you're using the script correctly, can you download the script as a .py file, put it into your user script folder and run it under the user script section in the extensions menu?
perfect, I have version 2023.1.3 and I will try with 2023.2.2.
thank you very much!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I tested the script in 2023.2.2 and it's working fine for me. just to make sure you're using the script correctly, can you download the script as a .py file, put it into your user script folder and run it under the user script section in the extensions menu?