Jump to content

Updating / Recooking the UI while running a python loop


Recommended Posts

Hey Guys,

I'm trying to update attributes with a python sop and seeing downstream results live.

I'm using the executeInMainThreadWithResult() function that comes with hdefereval.py and I am able to print the values live in the python shell / console while maintaining an interactive viewport during runtime, but the attributes don't update until the script finished.

Im running this code (HIP is also attached):

node = hou.pwd()
geo = node.geometry()

import hou
import hdefereval
import threading
import time

points = geo.points()

def houdini_command():
    for i,point in enumerate(points):
        point.setAttribValue("move", float(n))

def updateUI():
def worker():
    global n
    n = 0  
    while n < 5:
        n += 1

thread = threading.Thread(target=worker)
thread.daemon = True



Is there a way to hack this together to be able to view the changes of each loop live without having to wait until the full script is processed?


I also tried writing the attributes to a different node & piece of geometry but that didn't work because python sop only gets read access to geometry owned by other respective node.

Any pointers would be much appreciated! Thanks in advance




Link to comment
Share on other sites

I suggest you to rethink what you're trying to do, because when you reach out to threading and hdefereval in Python SOP that's a red flag right there unless you're just toying around. Python runs on the main thread and other parts of Houdini can't see the result of it until it's completed. 

For example you could replace your for loop with ForEach-family of SOPs.

Link to comment
Share on other sites

Hmm, you are probably right. I'm not depending on it working but it would have been nice. Unfortunately I can't do it with a SOP for-each-loop or a solver since my data has to stay in python while running the loop.

Thank you for your answer!

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.

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...