Jump to content

Keyframing with Python seems buggy?


Krion

Recommended Posts

Hi,

It's finally Python learning time for me. I thought I'd start with learning to keyframe in Python.
I searched a bit and now, inspired by the asCode() stuff, implementing it, I think I am still doing something wrong.

Because I set two keyframes at distinct times, and it acts buggy.

The first keyframe was initially only 'Hi', before I started trying to implement adding a variable to that 'Hi' (Hi it's time variable now), and that new try only shows up on some (random?) frames and the old 'Hi' keyframe is still in view mostly, even while it is no longer in the code. Also the second 'Bye' keyframe doesn't start smoothly but also with some flickering.

What am I doing wrong? 

Thanks in advance, appreciate your help

 

ffLosTest.hipnc

keyframeWithPython.thumb.gif.4d9f7b58ed68ae2862c334a16e8152f7.gif

Edited by Krion
Link to comment
Share on other sites

It does look like you have some coding errors.

 

Here is my fixup:

node = hou.pwd()
geo = node.geometry()

# Add code to modify contents of geo.
# Use drop down menu to select examples.

# KEYFRAME 1
# set variables
time1 = node.parm("time").eval()  #node.evalAtTime("time")

# get data of the font node
keyframed_font_Node = hou.node('../font3')
keyframed_font_textParm = keyframed_font_Node.parm('text')
keyframed_font_textParm.deleteAllKeyframes()

# create keyframe
skeyframe = hou.StringKeyframe()
skeyframe.setTime(time1)
skeyframe.setExpression("\"Hi, it's %s now\"" % time1 , hou.exprLanguage.Python)

# set keyframe
keyframed_font_textParm.setKeyframe(skeyframe)

# KEYFRAME 2
# set variables
time2 = node.parm("time2").eval()  #node.evalAtTime("time2")

# create keyframe
skeyframe = hou.StringKeyframe()
skeyframe.setTime(time2)
skeyframe.setExpression("\"Bye\"", hou.exprLanguage.Python)

# set keyframe
keyframed_font_textParm.setKeyframe(skeyframe)

 

  • Thanks 1
Link to comment
Share on other sites

21 minutes ago, CinnamonMetal said:

I have to slightly Hijack this thread, hopefully @Atom can respond or anyone.  Can one load Python modules inside the Python SOP have it being loaded ?

It's the same a "normal" python scripting :

import module1
import module2
import module3

 

  • Thanks 1
Link to comment
Share on other sites

but just don't use Python SOP to set keyframes, especially not if the affected node is directly upstream, since Python SOP cooks every time it's being evaluated and in the live network that can be a lot especially if it's dependent on time

use Python Expression instead to return whatever value you want depending on the frame or parameters or something

Link to comment
Share on other sites

On 4/6/2020 at 6:04 PM, anim said:

but just don't use Python SOP to set keyframes, especially not if the affected node is directly upstream, since Python SOP cooks every time it's being evaluated and in the live network that can be a lot especially if it's dependent on time

use Python Expression instead to return whatever value you want depending on the frame or parameters or something

How would that look? How would you translate the above code 'inside a Python Expression'?

I am now, for example, setting keyframes with a for loop with dynamically created spare-parameters created in that loop which then are fed back into the keyframe's time argument and stuff. Would that also be possible without the Python SOP?
Thanks,

Edited by Krion
Link to comment
Share on other sites

1 hour ago, Krion said:

How would that look? How would you translate the above code 'inside a Python Expression'?

I am now, for example, setting keyframes with a for loop with dynamically created spare-parameters created in that loop which then are fed back into the keyframe's time argument and stuff. Would that also be possible without the Python SOP?
Thanks,

Python SOP it the worst you can do for dynamic UI building as it exectes every times it's cooked, if you need to be flexible in adding new "keyframes" use multiparm and then query that in expression

here is an example:

ts_font_keys.hip

n = ch("keys")
keys = {}
for i in range(n):
    f = ch("frame%d" % i)
    t = ch("text%d" % i)
    keys[f] = t
    
sf = sorted(keys)
text = keys[sf[0]]

for f in sf:
    if hou.frame() >= f:
        text = keys[f]
        
return text

alternatively if you really need to build some UI and or set keyframes on certain parms you can trigger any python with a press of a button or shelf tool, anything but Python SOP, use Python SOP only for runtime scripts that really need to cook any time some inputs or parms change, not for something that you generate once

Edited by anim
  • Like 2
Link to comment
Share on other sites

On 4/10/2020 at 9:13 AM, anim said:

Python SOP it the worst you can do for dynamic UI building as it exectes every times it's cooked, if you need to be flexible in adding new "keyframes" use multiparm and then query that in expression

ts_font_keys.hip

Is it also possible to set parameters that way? I changed the code and put this before the beginning.

node = hou.pwd()
node.parm("keys").set(17)

That indeed set the parameters and the stuff keeped working, seemingly.
But then randomly stops working sometimes.

Below you can see a GIF where literally the same code is used on font6 and font7, and in the beginning font7 doesn't work but font6 does.. After a random change (parameter change on font6, trying to make them equal), but now it's the other way around.. i.e. font7 works and font6 doesn't.

If that is possible I would then also like to set the text channels (who are next to these 'keyframes') using strings from Python.
 

weird2.gif

Edited by Krion
Link to comment
Share on other sites

the whole point is to not set parameters from within expressions or Python SOP since it's being run all the time

to set them use either callback script or shelf tool script or something that runs just once

  • Thanks 1
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...