Krion Posted April 2, 2020 Share Posted April 2, 2020 (edited) 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 Edited April 2, 2020 by Krion Quote Link to comment Share on other sites More sharing options...
Atom Posted April 2, 2020 Share Posted April 2, 2020 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) 1 Quote Link to comment Share on other sites More sharing options...
Krion Posted April 2, 2020 Author Share Posted April 2, 2020 Thanks Atom, it's indeed a smart idea to first delete all the keyframes. Quote Link to comment Share on other sites More sharing options...
CinnamonMetal Posted April 6, 2020 Share Posted April 6, 2020 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 ? Quote Link to comment Share on other sites More sharing options...
DonRomano Posted April 6, 2020 Share Posted April 6, 2020 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 1 Quote Link to comment Share on other sites More sharing options...
anim Posted April 6, 2020 Share Posted April 6, 2020 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 Quote Link to comment Share on other sites More sharing options...
Krion Posted April 10, 2020 Author Share Posted April 10, 2020 (edited) 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 April 10, 2020 by Krion Quote Link to comment Share on other sites More sharing options...
anim Posted April 10, 2020 Share Posted April 10, 2020 (edited) 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 April 10, 2020 by anim 2 Quote Link to comment Share on other sites More sharing options...
Krion Posted April 15, 2020 Author Share Posted April 15, 2020 (edited) 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. Edited April 15, 2020 by Krion Quote Link to comment Share on other sites More sharing options...
anim Posted April 15, 2020 Share Posted April 15, 2020 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 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.