Search the Community
Showing results for tags 'ondeleted'.
-
Hey Guys, Still quite new to Python, hoping someone can help point me in the right direction on this that I've been grappling with for a while now. I have a simple filecache .hda that I'd like to change color if it can/can't find the cache on disk. I've been able to use hou.ui.addEventLoopCallback() to continuously track and check the file parameter to see if the cache exists, and the color changing now works as expected. Where I'm having trouble is removing the event loop when the .hda is deleted from the node graph. An error pops up because Houdini is still trying to access the deleted node. I've been trying to look for a way to use the OnDeleted event handler, or hou.nodeEventType.BeingDeleted, but no luck yet and I feel out of my depth with my limited python experience. The .hda is attached, and there's a preview of the code below. Any help would be appreciated! custom_filecache.hda ####PythonModule#### import os import hou def nodeColor(kwargs): node = kwargs["node"] def colorCallback(): filepath = node.evalParm("file") if(os.path.exists(filepath)): node.setColor(hou.Color((0.0, 0.8, 0.0))) node.setComment(filepath) node.setGenericFlag(hou.nodeFlag.DisplayComment,True) else: node.setColor(hou.Color((0.8, 0.0, 0.0))) node.setComment("File not found") node.setGenericFlag(hou.nodeFlag.DisplayComment,True) startCallback(colorCallback) #adding this code below crashes Houdini when hda is deleted #node.addEventCallback([hou.nodeEventType.BeingDeleted], endCallback(colorCallback)) def startCallback(callback): hou.ui.addEventLoopCallback(callback) def endCallback(callback): hou.ui.removeEventLoopCallback(callback) ####OnCreated#### kwargs["node"].hdaModule().nodeColor(kwargs)