python node force cook every frame?

   4586   5   0
User Avatar
Member
28 posts
Joined: Nov. 2015
Offline
This works only when I middle-click the python node (forcing it to cook?). I was expecting it to append the frame number to file as I scrubbed the timeline…

Attachments:
python_write_frame.png (10.8 KB)

User Avatar
Member
2537 posts
Joined: June 2008
Offline
Python is kind of ‘lose’ as far as scrubbing refresh goes. I have not yet been able to get full update when scrubbing, but you can get full update when rendering or exporting of you populate the Pre-Frame or Post-Frame script of any ROP.

Here is the code, replace the path with the path to your Python node and python def.
exec(hou.node("/obj/subnet1/pythonscript1").parm('python').eval());myDef("my_data_if_any") 

PS: Don't forget to switch the script field from the default language of Hscript to Python.
Edited by Enivob - April 16, 2017 19:30:02
Using Houdini Indie 20.0
Windows 11 64GB Ryzen 16 core.
nVidia 3050RTX 8BG RAM.
User Avatar
Member
28 posts
Joined: Nov. 2015
Offline
Thanks for the response. However, it's not really the direction I'm looking to go.

My original intent was to accumulate an arbitrary value over frames, much like @Frame or @Time. I banged my head with detail once and timeshift until I realized everything I was doing was effectively constant (unchanged). The same graph is evaluated every frame, so all the same values are calculated every frame, and nothing carries over. At least, that's my current mental model.

My next thought was to flush those values to disk, to persist them between frames. And that's where I am. I'm new to Houdini, and probably abusing it, so any advice is appreciated.
Edited by aoakenfo - April 16, 2017 20:24:16
User Avatar
Member
2041 posts
Joined: Sept. 2015
Offline
If you want values to persist with python you could create them in the Python Source Editor and access them with hou.session.
User Avatar
Member
2537 posts
Joined: June 2008
Offline
Hmm…this code worked for me in a quick test. I clicked Play and a bunch of numbers accumulated.
with open(r"C:\Users\YourUserName\Desktop\foo.txt", "a") as f:
    f.write(hou.expandString("$F"))
I think the problem in your first posted code is that you are passing the ‘w’ parameter. Passing the ‘a’ parameter allows for appending to existing file as well as creating it if it does not exist.
Edited by Enivob - April 16, 2017 21:32:49
Using Houdini Indie 20.0
Windows 11 64GB Ryzen 16 core.
nVidia 3050RTX 8BG RAM.
User Avatar
Member
28 posts
Joined: Nov. 2015
Offline
Cha-ching!!! Thanks a lot. I was thinking >> would append, like bash. Thank you kindly for all your help.
Edited by aoakenfo - April 16, 2017 22:32:15
  • Quick Links