nodeが作られたタイミングをイベントとして受け取って、何かPythonで処理したい時のscript。
これでname conventionやらcolor conventionがしやすくなるし、自作したPyQt Panelとリアルタイムな感じでやり取りできるので、便利そう。
サンプルなので、attribute wrangleのノードの色変えるだけです。。。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def setUpCallback(node): | |
node.addEventCallback((hou.nodeEventType.ChildCreated,), onNodeChange) | |
def onNodeChange(**kwargs): | |
childNode = kwargs["child_node"] | |
setUpCallback(childNode) | |
setClr(childNode) | |
def allSubChildren(node): | |
yield node | |
for child_node in node.children(): | |
for n in allSubChildren(child_node): | |
yield n | |
#################################### | |
def setClr(node): | |
if node.type().name() == "attribwrangle": | |
attribClr = hou.Color((1.0,0.8,0)) | |
node.setColor(attribClr) | |
#################################### | |
for node in allSubChildren(hou.node("/")): | |
#node.removeAllEventCallbacks() | |
setUpCallback(node) |
yieldって使ったことなくて勉強になりました。