OTL onCreate: extractAndDelete?

   1189   3   2
User Avatar
Member
240 posts
Joined: 10月 2014
Offline
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).

Any insight into what I'm doing wrong?
Edited by Tim Crowson - 2022年9月19日 15:12:53
- Tim Crowson
Technical/CG Supervisor
User Avatar
Member
280 posts
Joined: 12月 2015
Offline
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.
https://www.imdb.com/name/nm8408875/ [www.imdb.com]
User Avatar
Member
1906 posts
Joined: 11月 2006
Offline
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:
import objecttoolutils
node = objecttoolutils.genericTool(kwargs, '$HDA_NAME')

if not kwargs["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
User Avatar
Member
240 posts
Joined: 10月 2014
Offline
Thanks, Graham!
- Tim Crowson
Technical/CG Supervisor
  • Quick Links