Python access HDA UI parm onCreate

   580   4   2
User Avatar
Member
53 posts
Joined: 7月 2017
Offline
I'm trying to change some String parameters in my UI based on the scene and variables, once, when the HDA is created.
Basically, these are editable fields, but with default values changed based on the scene.

Since these are supposed to be user-editable fields, I'm trying to avoid putting the Python code within the default field in the Parameter Editor itself, but instead automatically modify them from one of the Python Script Modules on creation.


But if I try to access the HDA UI params via the Python module OnCreate, I get NoneType errors. I assume because the OnCreate script triggers before the UI is initialized. I wonder if there's another way of doing this, or just not possible?
I tried OnLoaded, which doesn't seem to trigger at all on node creation, and I couldn't really find any more in-depth description of the different Event Handlers.



In short, can I set() or eval() the HDA UI parameters from the Python Module or Event Handlers, once, automatically when the HDA is created?
User Avatar
Member
46 posts
Joined: 4月 2008
Offline
Hello,
The case you are referring to is: preFirstCreate,
where the tool isn't created yet but you can use it to set some stuff.

The onCreate module should actually work, I am using it with success.

I usually create the python definitions inside the pythonModule and call them from the onCreate module like so:

kwargs["node"].hdaModule().yourScriptName(...)
User Avatar
Member
4 posts
Joined: 3月 2013
Offline
AlexNardini1
Hello,
The case you are referring to is: preFirstCreate,
where the tool isn't created yet but you can use it to set some stuff.

The onCreate module should actually work, I am using it with success.

I usually create the python definitions inside the pythonModule and call them from the onCreate module like so:

kwargs["node"].hdaModule().yourScriptName(...)

Interesting, I've done exactly that and I get "AttributeError: 'NoneType' object has no attribute 'set'"

Perhaps it's the way I call the node within the HoudiniModule function?

def TestFunction():
    node = hou.pwd()
    ident = 'test'
    node.parm('identifier').set(ident)

But I can call the same function from a button press etc. without errors.
Edited by Trono - 2024年9月26日 17:03:48
User Avatar
Member
46 posts
Joined: 4月 2008
Offline
I think it is because hou.pwd() you get nothing since the node it self isn't directly accessible yet,
but you can get it with kwargs:

def TestFunction(kwargs):
    node = kwargs['node']
    ident = 'test'
    node.setParms({'identifier': ident})
User Avatar
Member
53 posts
Joined: 7月 2017
Offline
Ahh, yep, there we go. Seems to be working well now. Thank you! I've spend too many hours on this silly thing.
Edited by Tronotrond - 2024年9月26日 18:06:43
  • Quick Links