Jump to content
paulkay1902

Updating the viewport with python to see change in parameters

Recommended Posts

Hello guys,

I'm new to Houdini and to writing python scripts for Houdini. I'm currently working on a project where I want to change the Rotation, Scale or Transformation of a geometry node by moving physical rotary encoders, which are connected to an Arduino Uno. The serial connection between Houdini and the Arduino works fine. In my script, which I save as a custom shelf tool, I change the parameters of the node by using the set() function of the Parm object. The amount of change comes from the encoders. For example:

node.parm('tx').set(change)

The problem for me is that while the script is running and I change, for example, the rotation of a cube, like node.parm('rx').set(25), the cube is not rotating in the viewport. The cube is only changing once the script has finished and stopped running. Basically, the viewport is only updated with the new, for example, rotation parameters once the script has finished running. The geometry node is not moving in the viewport while the script is running. My goal would have been to have the script running in the background while working on Houdini like usual, and when changing the rotation of a node via set(), the node is also rotating in the viewport.


Therefore, my main question: Is there a way with the hou object to force the viewport to display all the currently new set parameters of a node (like Scale, Rotation and Transformation) while a python script from the shelf is running.

Thank you for your help.

Share this post


Link to post
Share on other sites

You could try GeometryViewport.draw(), but it's quite possible the redraw request won't be processed until the end of your script.

Share this post


Link to post
Share on other sites

As Mark said above, the GeometryViewport.draw() won't update the viewport because your script is running in the main thread and therefore is blocking any updates. What you need to do is to run your script in a separate thread and communicate with Houdini via hdefereval.execute_in_main_thread_with_result(callback)

 

See $HH/python2.7libs/hdefereval.py for more info.

Edited by Stalkerx777
formatting

Share this post


Link to post
Share on other sites

Thank you guys very much for the replies.

That sounds to be exactly what I'm looking for. I will try to get it to work, and keep you posted :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×