Community
Maya Programming
Welcome to Autodesk’s Maya Forums. Share your knowledge, ask questions, and explore popular Maya SDK topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Create key not fractional

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
dg3duy
131 Views, 2 Replies

Create key not fractional

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

2 REPLIES 2
Message 2 of 3
Kahylan
in reply to: dg3duy

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
in reply to: dg3duy

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report