Jump to content

Updating the viewport with python to see change in parameters


paulkay1902

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.

Link to comment
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
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...