Python: Is it possible to dynamically edit interface parms?

   10658   18   1
User Avatar
Member
466 posts
Joined: Aug. 2014
Offline
Is it possible to dynamically create, edit, hide/show, remove and create dependencies (disable/hide when…) between interface parameters of nodes with just python code?

Simple example:
geo = hou.node('/obj').createNode('geo')
null = geo.createNode('null')
file = hou.node(geo.path()+'/file1')
Let's say I need to hide the copyinput and cacheinput parms of my null SopNode, create a button and a Float parameter that will reference data of some other node. Or maybe promote reload parameter (button) of the file SopNode to my geo node.
Can it be done?
User Avatar
Member
1391 posts
Joined: Dec. 2010
Offline
I think this is your answer :
write your Python script for doing that in the Edit Operator Type Properties window.
Open this window and go to Scripts page ,Set Event Handler to "On Created" and set Edit as parameter in the right section to "Python".
Then every Python code that you write , Executed after creating your node !
https://www.youtube.com/c/sadjadrabiee [www.youtube.com]
Rabiee.Sadjad@Gmail.Com
User Avatar
Member
1391 posts
Joined: Dec. 2010
Offline
I used this method for changing color of my custom node after creation !
https://www.youtube.com/c/sadjadrabiee [www.youtube.com]
Rabiee.Sadjad@Gmail.Com
User Avatar
Member
466 posts
Joined: Aug. 2014
Offline
Thank you Joker386, but that's not what I'm after.
I just took another look at the hou module and I think it's the hou.ParmTemplate class I should look into. I need to test it out.
User Avatar
Member
1391 posts
Joined: Dec. 2010
Offline
Do you want something like this :

# address of your null node
node = hou.node('/obj/geo1/null1')
# name of your parameters
parm1 = node.parm('copyinput')
parm2 = node.parm('cacheinput')

# hide these parameters
parm1.hide(1)
parm2.hide(1)
https://www.youtube.com/c/sadjadrabiee [www.youtube.com]
Rabiee.Sadjad@Gmail.Com
User Avatar
Member
1391 posts
Joined: Dec. 2010
Offline
And this script to add String and Button parameters :

node = hou.node('/obj/geo1/null1')
StringParms = hou.StringParmTemplate(“JK_Name” , “JK_Label” , 2 , (“Sadjad”,“Rabiee”))
ButtonParms = hou.ButtonParmTemplate(“JKButton”,“JKButton”)

node.addSpareParmTuple(StringParms)
node.addSpareParmTuple(ButtonParms)
https://www.youtube.com/c/sadjadrabiee [www.youtube.com]
Rabiee.Sadjad@Gmail.Com
User Avatar
Member
466 posts
Joined: Aug. 2014
Offline
Excellent! This is exactly what I was looking for!
Many thanks Master Joker386. Your help was invaluable.
User Avatar
Member
1391 posts
Joined: Dec. 2010
Offline
ajz3d
Excellent! This is exactly what I was looking for!
Many thanks Master Joker386. Your help was invaluable.

Really thanks man :wink:
https://www.youtube.com/c/sadjadrabiee [www.youtube.com]
Rabiee.Sadjad@Gmail.Com
User Avatar
Member
466 posts
Joined: Aug. 2014
Offline
Hi.
I have one more question, loosely related to this subject.

I've noticed that any print() functions and parameter changes are displayed AFTER the script reaches its end. Is there any way that I can feed them to standard output or, when it comes to parameters display, update them during run-time?

I have this String parameter called ‘hdaStatus’ in my HDA node, which I want to display information on what the HDA is currently processing, and I'm breaking my head trying to figure out how to do it. There's a line in which I'm loading a hi-res geometry and before it, I placed the:
self.hdaNode.parm('hdaStatus').set('Loading reference mesh. This may take a while…')
…but the UI representation of the ‘hdaStatus’ parameter updates AFTER the script finishes its job.
User Avatar
Member
466 posts
Joined: Aug. 2014
Offline
As a workaround I ended up using the hou.InterruptableOperation class to display a progress window with some info on what is going on. The class is so clever that apart of user-specified string, it even provides some info on what Houdini is currently doing under the hood.
User Avatar
Member
1391 posts
Joined: Dec. 2010
Offline
ajz3d
As a workaround I ended up using the hou.InterruptableOperation class to display a progress window with some info on what is going on. The class is so clever that apart of user-specified string, it even provides some info on what Houdini is currently doing under the hood.

That's interesting
https://www.youtube.com/c/sadjadrabiee [www.youtube.com]
Rabiee.Sadjad@Gmail.Com
User Avatar
Member
466 posts
Joined: Aug. 2014
Offline
Hello.
I need to ask another question. I don't want to create another thread, so I'll just post here as it's still regarding Python in Houdini.

I have an HDA node with Python code in its Type Properties->Scripts. It basically contains a class and a dozen of functions with which I generate a network of OBJ and SOP nodes, with “one control node to rule them all”.

I create interface parameters of this control node from within the code inside my HDA. However, amongst those parameters there are some buttons to which I'd like to assign callback scripts. And this the problematic part, because the code of my HDA is invisible to the control node, so I can't just assign a function from my main script to the callback, because it will simply be inaccessible.

There are also some lists containing instances of various nodes that I need to pass to the callback function for processing.

I found this thread on OD|Force forum: http://forums.odforce.net/topic/9607-buttons-callback-script/?hl=%2Bscript+%2Bcallback [forums.odforce.net]
Some suggestions are made there to simply import Python module. But how do I import a module that is embedded into my HDA?

How should I approach this problem? What's the right way of doing it?
User Avatar
Member
1391 posts
Joined: Dec. 2010
Offline
Ok , that's easy .

for using some function in the scripts part we should use :
hou.pwd().hdaModule().FunctionName()

right !?

Now , you wanna call a custom function witch defined in the root node (HDA) with a child node (e.g Control node).

the above script take function from hdaModule in the current node (because hou.pwd() ).

So if you wanna call this function from any node (even outside of HDA) , Just you should define address of the specify node that contain your custom function instead of hou.pwd().

let me to make a simple example for you :wink:
https://www.youtube.com/c/sadjadrabiee [www.youtube.com]
Rabiee.Sadjad@Gmail.Com
User Avatar
Member
1391 posts
Joined: Dec. 2010
Offline
Check this file 8)

Attachments:
JKNode.zip (13.2 KB)

https://www.youtube.com/c/sadjadrabiee [www.youtube.com]
Rabiee.Sadjad@Gmail.Com
User Avatar
Member
466 posts
Joined: Aug. 2014
Offline
Brilliant! This explains a lot! Thank you for taking your time to create this example.

However, there's a problem when I pass the callback script as an arg:

myButton = hou.ButtonParmTemplate('my_button',
‘My Button’,
script_callback=“hou.node('/obj/myHDA').hdaModule().test('foo!')”,
script_callback_language=hou.scriptLanguage.Python)


If I do this, and then click the button, I'm presented with a “NameError: name ‘test’ is not defined” error. And when I inspect the callback field of my button inside the control node, I see that it only stores the:
test(“foo!”)
function call, stripped of the path to my HDA node. So no wonder it can't find the function.

Do you have any suspicions as to why this happens?
User Avatar
Member
466 posts
Joined: Aug. 2014
Offline
Hm. This is weird. I just created a simple scene for testing purposes and it works just fine there - no stripping occurs. The code I used is exactly the same as in my main HDA. :shock:
User Avatar
Member
466 posts
Joined: Aug. 2014
Offline
Okay, I think it had something to do with script caching or whatever, because when I deleted everything from the Type Properties->Scripts, I noticed that the HDA was still working as if nothing has happened(!). Saving operator type and locking it up didn't help either. I had to delete the HDA node from my scene and restart Houdini. And only then it finally forgot that blasted script.
Then, I pasted the newest version of the script and now everything is working perfectly fine. Phew!
User Avatar
Member
1391 posts
Joined: Dec. 2010
Offline
ajz3d
Okay, I think it had something to do with script caching or whatever, because when I deleted everything from the Type Properties->Scripts, I noticed that the HDA was still working as if nothing has happened(!). Saving operator type and locking it up didn't help either. I had to delete the HDA node from my scene and restart Houdini. And only then it finally forgot that blasted script.
Then, I pasted the newest version of the script and now everything is working perfectly fine. Phew!

That sounds good
https://www.youtube.com/c/sadjadrabiee [www.youtube.com]
Rabiee.Sadjad@Gmail.Com
User Avatar
Member
7 posts
Joined: Jan. 2018
Offline
Hi,

node = hou.node('/obj/geo1/null1')
StringParms = hou.StringParmTemplate(“JK_Name” , “JK_Label” , 2 , (“Sadjad”,“Rabiee”))
ButtonParms = hou.ButtonParmTemplate(“JKButton”,“JKButton”)

node.addSpareParmTuple(StringParms)
node.addSpareParmTuple(ButtonParms)

Sadjad, in the Code can you define where to add a specific parameter among more existing one ?
I mean I have a filecache an I want to add button after a button.

THX!
G
  • Quick Links