Jump to content

Setting keyframes using variable with hscript or python


scp

Recommended Posts

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
Link to comment
Share on other sites

>>> 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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...