keys between the previous and next key

53 views
Skip to first unread message

Darwin Giordano

unread,
May 2, 2024, 2:14:27 PMMay 2
to Python Programming for Autodesk Maya
With chatgpt I managed to make a script that adds animation keys between the previous and next key based on the keyframe of the current timeline where the user is located.

It happens to add keyframes correctly until at a given time when approaching the current timeline key then the key creation is not accurate, apparently it fails in 1 frame the distance where it should add the keys. I don't know how to correct it.
keys.gif
Code:
https://gist.github.com/Fenixdg3duy/56eae81e3064e5929938168c53d2cd88

anyone who can shed light on this issue as to why the keys do not keep the distance to a point close to the current timeline?

Justin Israel

unread,
May 10, 2024, 6:25:36 PMMay 10
to python_in...@googlegroups.com
I had a quick look at this, and what it seems to be doing is encountering a rounding issue when you are trying to set keyframes before and after the current time. When you have a mid-point that is not an even number, such as 17.5 for the previous keyframe and 32.5 for the next keyframe, and you pass those float values to setKeyframe(), it is going to round them both up to the next whole number. that is going to result in the left side being a closer distance from your current time and the right side being farther away. 
If your goal is to make them an even distance from the current time, then a possible solution is to always round the left side up, and always round the right side down.
This example is wrapping the prev and next keyframe locations in math.ceil() and math.floor(), respectively:

Justin


--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/8ccb8b62-1b9c-4da4-85f6-9e99d8743ecbn%40googlegroups.com.

Darwin Giordano

unread,
May 12, 2024, 1:42:37 PMMay 12
to Python Programming for Autodesk Maya
That's exactly the solution!

wrapping the prev and next keyframe locations in math.ceil() and math.floor()
Thank you very much for solving this problem that I had not solved for a long time. A success!
Reply all
Reply to author
Forward
0 new messages