Dynamically changing spare parameter defaults

   2503   1   1
User Avatar
Member
2042 posts
Joined: Sept. 2015
Offline
Hi,

I was hoping someone could help me figure out how to change my “spare” parameter default settings dynamically.

With a drag and drop I inserted an Integer parameter into my node.
I want to be able to adjust its' maximum range value dynamically according to other parameter settings that change with use.

The only references I found was this link:

http://www.sidefx.com/index.php?option=com_forum&Itemid=172&page=viewtopic&t=29094&view=next&sid=0530cb5dc2bec8f3ac12c215ddd7d9e6 [sidefx.com]

It seems I am wanting to do the same basic thing as this guy, but I haven't been able to translate the example response given.

The only difference being is that I'm not trying to change a paramenter that's within an OTL. It's just in a hip file node.

I tried reading up on some help files that seemed related and looked at some of the examples given, but alas my experience with hou classes and methods is still very limited and I am not able to make the translation from the examples to my specific need.

Some of the help files I read were:

http://www.sidefx.com/docs/houdini15.0/hom/hou/ParmTemplateGroup [sidefx.com]

http://www.sidefx.com/docs/houdini15.0/hom/hou/Node#parmTemplateGroup [sidefx.com]

http://www.sidefx.com/docs/houdini15.0/hom/hou/IntParmTemplate [sidefx.com]


In the Help section of hou.IntParmTemplate I noticed there is a Method of,

setMaxValue - which I believe at some point in my code I need to use this Method.

But it's strange when I look at the example of the first link I referenced that I don't see the guy using this method as part of his code.

In opening up a python script window to play around to figure this out I'm only able to start off with;

anyword = hou.node(“obj/vc_control_tx/Controller”)

..and inside my node “Controller” the parameter I am attempting to change as said before, is named “factor_amount”.

Any feedback in helping me understand how to do this is much appreciated.

Thanks
User Avatar
Member
2042 posts
Joined: Sept. 2015
Offline
I'm stoked…

With little experience working with hou classes and methods it's been a bit difficult to understand the help files to do what I wanted to do.

But somehow I managed put it together to make it work.

So I'm writting here to explain what I did just in case someone in the future wants to do the same and has some reference.

So the following I did in the python shell and have yet to put it in an expression or in my case I will be making a function out of it, placing it in a PythonModule and calling it from my desired parameter “text expression box”.

So the first thing to note the user defined “variables” I am using below I all start off with “my” so as to help newbies differentiate from the houdini class and methods.
In my previous post I made some references to what I was attempting and was using a different file, node and parameter, so don't reference what I am doing here with my previous post.

So I start with this line:

my_node = hou.node(“obj/sphere_object1/sphere1”)

“obj/sphere_object1/sphere1” is simply the node I dropped down to play with and see what can be done, this part in brackets will change depending on the node you use that has the parameter you want to change in it.

Next Line:

my_template_group = my_node.parmTemplateGroup()

This is basically a container for holding the different paramters as templates of their settings; I may not be describing this accurately and there also probably more to it than this so here's the doc on it:

http://www.sidefx.com/docs/houdini15.0/hom/hou/ParmTemplateGroup#find [sidefx.com]

Next 2 lines:

my_new_max_range = 45
my_parameter_template_replacement = hou.IntParmTemplate('my_integer_parameter', ‘My Integer Parameter’, 1, (), 1, my_new_max_range, 1, 1 )

So here from what I understand so far in my reading is that we are creating a “template” of what we want my parameter to be changed to.

I originally created my parameter “manually” by opening the nodes “Edit Parameter Interface” and from the “Create Parameters” column which is the first column and under the “By Type” tab, dragged and dropped an “Integer” parameter into the middle column of “Existing Parameters”. This created my new parameter and allowed me to set in the third column its Name, Label, Range and so on.

So in the above line of code in which hou.IntParmTemplate is used, the reason this is used is because it corresponds to making changes to integer parameters only.

If you dragged and dropped a Label or Float parameter you would have to use a different “Template”;

If you look at this link and go down to the sub heading of Parameter templates you will find the one I used and the others that correspond to the parameter type you wish to work with.

http://www.sidefx.com/docs/houdini15.0/hom/hou/_index [sidefx.com]

So in the code line above the arguments within the brackets is where you define what you want your parameter to “look” like.

In my case I want to keep its name and label so ‘my_integer_parameter’ and ‘My Integer Parameter’ is same as what I entered manually when I created the parameter.

And I have left it the same because I don't want to change it. The only thing I do want to change is the Maximum Range and in this case I predefined a “variable” name and assigned a value to it of 45.

So this is still in the template phase, I'm just defining what I want to change my parameter too not actually doing the changes yet.

Also, what I have entered for the other arguments I really don't understand fully yet as I just cut and paste from other examples and changed the argument I was interested in.

You can get more doc info here on this particular int template class : http://www.sidefx.com/docs/houdini15.0/hom/hou/IntParmTemplate [sidefx.com]

And if you notice, the very first method of this class describes the content arguments of the code line I used above.

This threw me off when I first started reading this because it describes the method as __init__ so I wasn't sure what I would use it for.

But by comparing examples I realized this just tells you what the different arguments are for.

One thing I still don't understand how to apply the information here. If you noticed I've only included 9 arguments but the __init__ method for this class has 23 possible arguments. I don't know what happens when you omit arguments. I guess it will just default to the existing paramter settings if nothing is given.

Also, in my case, maximum range is the 6th paramter. What if I wanted to omit typing the first two arguments because I'm not changing them. Is there some default “placeholder” I can use so that it knows my maximum range is going to be?


Next line:

my_template_group.replace('my_integer_parameter', my_parameter_template_replacement )

So this line replaces the current template of the specific parameter we are currently working with to the new one we want.
But this will not yet show results because we still have to set the nodes group template as a whole to reflect the “new” specific paramter template with the next and final line of code. I may not be adequately describing what's going on here well enough as the way I am describing it seems like we are replacing twice. All I know is we need to do this line of code and the one that follows:

my_node.setParmTemplateGroup(my_template_group)


So here are all the lines of code again but together:


my_node = hou.node(“obj/sphere_object1/sphere1”)
my_template_group = my_node.parmTemplateGroup()
my_new_max_range = 45
my_parameter_template_replacement = hou.IntParmTemplate('my_integer_parameter', ‘My Integer Parameter’, 1, (), 1, my_new_max_range, 1, 1 )
my_template_group.replace('my_integer_parameter', my_parameter_template_replacement )
my_node.setParmTemplateGroup(my_template_group)


And the next time I want to change the max range all my function has to do is the last 4 lines of code.
The first two are only necessary for the initial set up for future changes.

If I want to change my max range to 12 my function would just have to run:

my_new_max_range = 12
my_parameter_template_replacement = hou.IntParmTemplate('my_integer_parameter', ‘My Integer Parameter’, 1, (), 1, my_new_max_range, 1, 1 )
my_template_group.replace('my_integer_parameter', my_parameter_template_replacement )
my_node.setParmTemplateGroup(my_template_group)


Hope this becomes useful to some newbie like myself in the future.

Cheers.
  • Quick Links