paulkay1902 Posted February 5, 2020 Share Posted February 5, 2020 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. Quote Link to comment Share on other sites More sharing options...
malexander Posted February 5, 2020 Share Posted February 5, 2020 You could try GeometryViewport.draw(), but it's quite possible the redraw request won't be processed until the end of your script. Quote Link to comment Share on other sites More sharing options...
Stalkerx777 Posted February 5, 2020 Share Posted February 5, 2020 (edited) 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 February 5, 2020 by Stalkerx777 formatting Quote Link to comment Share on other sites More sharing options...
paulkay1902 Posted February 5, 2020 Author Share Posted February 5, 2020 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 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.