Create key not fractional

Create key not fractional

dg3duy
Collaborator Collaborator
222 Views
2 Replies
Message 1 of 3

Create key not fractional

dg3duy
Collaborator
Collaborator

When creating the key it is created fractionally, is it possible to change the code so that it does not add it in a fractional frame? I can't think of a way to do it.

import maya.cmds as mc

def insertKeyPercentage(percentage = 50):
    
    key1 = mc.currentTime(q = True)
    key2 = mc.findKeyframe(t = (key1,key1), w = "next")
    
    p = ((key2-key1)/100)*percentage
    
    newKey = mc.setKeyframe(i = True, t = (key1 +p))
    
insertKeyPercentage(percentage = 50)


keys fractional.gif

0 Likes
Accepted solutions (1)
223 Views
2 Replies
Replies (2)
Message 2 of 3

Kahylan
Advisor
Advisor
Accepted solution

Hi!

 

You just need to add the round() function to the final result of you newkey time value:

newKey = mc.setKeyframe(i = True, t = (round(key1 +p)))

 

I hope it helps!

Message 3 of 3

dg3duy
Collaborator
Collaborator

@Kahylan thank you very much! the end result is accurate now!

0 Likes