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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
perfect, I have version 2023.1.3 and I will try with 2023.2.2.
thank you very much!