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?
Python: Is it possible to dynamically edit interface parms?
10700 18 1- ajz3d
- Member
- 474 posts
- Joined: Aug. 2014
- Offline
- Sadjad Rabiee
- 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 !
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 !
- Sadjad Rabiee
- Member
- 1391 posts
- Joined: Dec. 2010
- Offline
- ajz3d
- Member
- 474 posts
- Joined: Aug. 2014
- Offline
- Sadjad Rabiee
- Member
- 1391 posts
- Joined: Dec. 2010
- Offline
- Sadjad Rabiee
- 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)
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)
- ajz3d
- Member
- 474 posts
- Joined: Aug. 2014
- Offline
- Sadjad Rabiee
- Member
- 1391 posts
- Joined: Dec. 2010
- Offline
- ajz3d
- Member
- 474 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.
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.
- ajz3d
- Member
- 474 posts
- Joined: Aug. 2014
- Offline
- Sadjad Rabiee
- Member
- 1391 posts
- Joined: Dec. 2010
- Offline
- ajz3d
- Member
- 474 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?
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?
- Sadjad Rabiee
- 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:
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:
- Sadjad Rabiee
- Member
- 1391 posts
- Joined: Dec. 2010
- Offline
- ajz3d
- Member
- 474 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?
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?
- ajz3d
- Member
- 474 posts
- Joined: Aug. 2014
- Offline
- ajz3d
- Member
- 474 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!
Then, I pasted the newest version of the script and now everything is working perfectly fine. Phew!
- Sadjad Rabiee
- 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
- szabolcs.illes
- 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
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