Error adding "CookComplete" event handler

   1716   3   2
User Avatar
Member
67 posts
Joined: Jan. 2014
Online
Hi,

I just upgraded from H18.0.416 to H18.0.460 and started getting errors on the event handler for “pdg.EventType.CookComplete”. The code inside the event is selecting the first workitem, like this:

myNode.setSelectedWorkItem(event.node.workItems[0].id)

…and the error message:

Error running Python callback 'Event Handler':
Traceback (most recent call last):
  File "C:/PROGRA~1/SIDEEF~1/HOUDIN~1.460/houdini/python2.7libs\hou.py", line 63874, in setSelectedWorkItem
    return _hou.TopNode_setSelectedWorkItem(*args)
Error: This function can only be called from the main thread

What is the recommended way to avoid this ?

Thanks.
Edited by fabriciochamon - June 19, 2020 13:15:55
User Avatar
Member
67 posts
Joined: Jan. 2014
Online
Looking at the changelog, this is probably the result of this:

Houdini 18.0.454 Added checks to several hou.TopNode functions to prevent access off of main thread. Fri. May 1, 2020

I'm trying to use the hdefereval module without success. Code:

import pdg
import hdefereval

node = hou.node('/obj/topnet1/test')
pdgNode = node.getPDGNode()

def onFinished(event):
    hdefereval.executeDeferred(node.setSelectedWorkItem(event.node.workItems[0].id))
    
pdgNode.removeAllEventHandlers()
pdgNode.addEventHandler(onFinished, filter=pdg.EventType.CookComplete)

So the idea is simple: I want to select the first workitem once a top node cook is complete. any hints ?
User Avatar
Member
603 posts
Joined: Sept. 2016
Offline
you need to pass executeDeferred the thing you want executed. What you're doing is executing right away. For example:

hdefereval.executeDeferred(node.setSelectedWorkItem, event.node.workItems[0].id)
User Avatar
Member
67 posts
Joined: Jan. 2014
Online
ah should have used help() on the module. that works. Thank you Chris!
  • Quick Links