Jump to content

Running py code on frame change?


leytonian

Recommended Posts

Hi

 

I want to be able to run python code on each frame if and only a certain node is selected. I assume this must be a hou.session thing but the my hou.session scripts do not run on each frame if I am seeing it correctly. They are just some globally acccesed code.

 

Basically I am looking for a frame change hook that runs in the session.

 

 

thanks

 

Link to comment
Share on other sites

Just drop down a python node at the OBJ level and put your code there. It does not really matter which context you are in when the code runs. Using Python you can reach into other contexts, for instance to force cook a node in the img context.

hou.node('/img/comp1/default_pic').cook(force=True)

 

There was an old trick I read about that by simply referencing the variable $F in back ticks, inside a python node, would cause it to evaluate every frame. I am not sure how reliable that is, however. The concept was that because you were using an hScript variable replacement that some kind of evaluation would happen after the fact.

curframe = `$F`

 

Basically Python updates while manually scrubbing the time line are not very realistic unless it is the simplest of manipulations. As you grow your scene, your FPS will drop to the floor. But you can always guarantee your python script will run every frame at render time by making it force cook in the Pre-Frame Render script event of any ROP that processes frames. (such as a Mantra node)

hou.node('/obj/my_python_node').cook(force=True)

 

Edited by Atom
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...