Is it possible to have an HDA run extractAndDelete() on itself when it's created? If so what is the appropriate methodology for this? If I try the naive approach of running
node=kwargs['node']node.extractAndDelete()
in an OnCreate event, I get a "InitScriptFailed: Node initiliazation script failed"
My guess is that I'm asking the node to extractAndDelete prior to it being fully initialized, but I'm just not sure.
If instead of
kwargs['node']
I try
hou.pwd()
I get a type error, that the node is not a subnet (even though the extractAndDelete() method runs fine on the same node when run manually later).
I've been trying the same thing for a while now the closest I got is creating an extract and delete button but Even if you make the HDA press the button onCreated it will give the same result as you.
Usually you would want to do this as part of the digital asset's shelf/menu tool to avoid any issues like you're seeing with trying to futher mutate the scene state while Houdini is creating the nodes. I would add something like the following under the Interactive > Shelf Tools > {default tool} > Script tab in the Type Properties:
importobjecttoolutilsnode=objecttoolutils.genericTool(kwargs,'$HDA_NAME')ifnotkwargs["ctrlclick"]:# So you can easily instantiate your container to work on it.nodes=node.extractAndDelete()# ... Anything else you might want to do with the extracted items
This of course only works when you're creating the node interactively so if you're needing to do it when creating the node via scripting you'd just have to manually call extractAndDelete() after you've created your node, or if you need to do other things as well then probably throw it in a function in the PythonModule section that can be called by the tool or your code.
Graham Thompson, Technical Artist @ Rockstar Games