Jump to content
Sign in to follow this  
scp

Setting keyframes using variable with hscript or python

Recommended Posts

scp    0

Hi all,

I have been trying to automate adding keyframes at a frame specified by a control on the outside of a Digital Asset. I'm picking up the variable $freeze from the asset controls and then trying to input it into the chkey hscript at -f to specify the frame. Then I'm trying to add another keyframe the frame after in order to switch a switch.

Here's the hscript I'm using wrapped within the general python script I'm using. I just can't get it to read the variables at integers for the frame numbers.

hou.hscript("set here = oppwf;freeze = opparm -d $oppwf freeze1;opcf /switch1;chadd switch1 input;chkey -f $freeze -v 0 switch1/input;chkey -f $freeze+1 -v 15 switch1/input")

Is it possible to use variables this way or can I incorporate variables created in Python into the Hscript string. If anyone knows or knows how to set keyframes with python directly that would be hugely appreciated.

Thanks

Simon

Edited by scp

Share this post


Link to post
Share on other sites
edward    331
>>> print hou.node('/obj/torus_object1').asCode()
...
# Code for keyframes on tx
hou_keyed_parm = hou_node.parm("tx")
hou_keyframe = hou.Keyframe()
hou_keyframe.setTime(0)
hou_keyframe.setValue(0)
hou_keyframe.setSlope(0)
hou_keyframe.setAccel(0.361111)
hou_keyframe.setExpression("bezier()", hou.exprLanguage.Hscript)
hou_keyed_parm.setKeyframe(hou_keyframe)
hou_keyframe = hou.Keyframe()
hou_keyframe.setTime(1.08333)
hou_keyframe.setValue(0)
hou_keyframe.setSlope(0)
hou_keyframe.setAccel(0.333333)
hou_keyframe.setExpression("bezier()", hou.exprLanguage.Hscript)
hou_keyed_parm.setKeyframe(hou_keyframe)
hou_keyframe = hou.Keyframe()
hou_keyframe.setTime(2.08333)
hou_keyframe.setValue(0)
hou_keyframe.setSlope(0)
hou_keyframe.setAccel(0.333333)
hou_keyframe.setExpression("bezier()", hou.exprLanguage.Hscript)
hou_keyed_parm.setKeyframe(hou_keyframe)
...

  • Like 1

Share this post


Link to post
Share on other sites
scp    0

Hi

Thanks for the Python, I'm almost getting there with the hscript using $here with opparm. However it is returning more than I require. All I need is the last 8 as an integer so that I can use it as a frame value for setting my keyframes.

set -g fog = `execute("opparm -d $here freeze1")`

echo $fog

opparm /obj/car/rollandcombine2 freeze1 ( 8 )

If anyone has any ideas to just get that 8 that would be great.

Thanks

Simon

Share this post


Link to post
Share on other sites
scp    0

Hi Edward

Thanks again for the Python as it works great now! No more hscript for me. I must remember how good node.asCode is

Thanks

Simon

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×