Adjusting range of parm templates

   2188   7   2
User Avatar
Member
207 posts
Joined: 11月 2015
Offline
Hi;

I have an HDA I'm building that does some stuff, and builds a list, and I would like to adjust the min/max range of a parameter to reflect this length of this list.

    group = node.parmTemplateGroup()
    index_parm_template = group.find("index")
    if index_parm_template:
        index_parm_template.setMaxValue(some_new_length)
        index_parm_template.setMaxIsStrict(True)
        group.replace("index", index_parm_template)

This is almost exactly what's described in the docs, yet this does not seem to work.

How does one specify the min/max range of a paramter in python?
Edited by dhemberg - 2023年2月20日 22:11:12
User Avatar
Member
466 posts
Joined: 8月 2014
Offline
If I remember correctly, you need to use setParmTemplateGroup()function to overwrite the old parm template group with the modified one. Currently you're just modifying a copy of it and none of the changes you're doing will affect the original ParmTemplateGroupinstance.
User Avatar
Member
207 posts
Joined: 11月 2015
Offline
Hi there;

Thank you! Yes, indeed, I tried that as well. It doesn't seem to affect anything; the parameter I'm trying to modify remains unchanged.

I even tried removing the parameter and remaking it, but this attempt at a workaround fails as well. It seems as though once the range has been set, it can't be changed, which makes me wonder what the min/max parmTemplate attributes are useful for...
Edited by dhemberg - 2023年2月22日 22:55:51
User Avatar
Member
466 posts
Joined: 8月 2014
Offline
node = hou.node('/obj/geo1/null1')
group = node.parmTemplateGroup()
parm_template = group.find('index')

if parm_template:
    parm_template.setMaxValue(100)
    parm_template.setMaxIsStrict(True)
    group.replace('index', parm_template)
    node.setParmTemplateGroup(group)
I just checked this, and it works correctly.
User Avatar
Member
207 posts
Joined: 11月 2015
Offline
No kidding! This exact code does NOT work for me; maybe some more details are needed here.

My parm "index" is on that I'm creating on an HDA. I have another parm ("set_index") that has a callback on it; this callback is defined in the HDA's Python Module, and is intended to resize my "index" parm when it's adjusted.

My function in the pythonModule exactly matches your code:


def resize_index_slider(**kwargs):

    node = kwargs["node"]
    scene_controller = hou.node(node.evalParm("scene_controller"))
    if not scene_controller:
        raise hou.NodeWWarning("Error: Please provide a Scene Controller")
        
    num_scene_colors = scene_controller.evalParm("scene_colors")
    

    group = node.parmTemplateGroup()
    parm_template = group.find('index')
    
    if parm_template:
        parm_template.setMaxValue(num_scene_colors )
        parm_template.setMaxIsStrict(True)
        group.replace('index', parm_template)
        node.setParmTemplateGroup(group)


Is there some nuance here that I'm misunderstanding? Am I not allowed to do this in a parameter callback? Or, do I need to create the initial "index" parameter dynamically, rather than creating it via the Parameters pane of the HDA UI?
Edited by dhemberg - 2023年2月23日 12:36:14
User Avatar
Member
466 posts
Joined: 8月 2014
Offline
Ah yes, in this case it won't work.

However, what you're trying to do feels somewhat uncommon. You basically want to expose a parameter that would allow for making changes to non-spare ParmTemplate of an HDA definition.

First of all, I have doubts that this would work on a locked asset. Second of all, and if I'm not mistaken, this would cause a situation, where all changes to your range ParmTemplate initiated by your script callback, would propagate to all existing instances of your asset. In other words, your range limits and strictness of this ParmTemplate would change to identical values in all existing HDA instances. If that's what you want, then you might as well set appropriate constant values in Type Properties, as it will have an identical effect.

That's how I see it, but it's possible that I'm wrong.
Edited by ajz3d - 2023年2月23日 16:00:25
User Avatar
Member
52 posts
Joined: 6月 2017
Offline
I believe that ajz3d is correct. Working with parmTemplates is more for dynamically generating/changing UI... so you COULD have a situation where you don't hardwire the parms you want into the HDA, then dynamically generate those in the "On Created" event of the HDA or on callbacks perhaps.
Houdini TD, I focus on tools for procedural asset creation.

www.jaworenko.design
User Avatar
Member
207 posts
Joined: 11月 2015
Offline
Thank you! If I had a nickel for every time I'm told something I'd like to try is "uncommon" I could probably buy SideFX.

Unfortunately, though, I'm unsure what value to draw from that...it doesn't really dissuade me from needing to do the thing I need to do, which is to dynamically change the UI. Specifically, I am trying to design a colorpicker of sorts. There are no "menu" item options for the color UI widget, so I'm trying to hammer out a way to represent the various colors I want to offer as choices by way of a multiparm, then allow a user a way to choose which color they want to use.

I see there was a comment (now deleted) suggesting running the code on the HDA definition itself, rather than a node instance of the HDA, but I worry that would run into the same issue @ajz3d is describing (updating it in one location would propagate to all created node instances, rendering the operation useless).

The solution proposed by @EJaworenko does seem to be a likely path forward, though I find it kind of confusing (particularly for my future self...I will wonder why I had to do it this way). It seems odd to me that I have to do it this way.

Anyway, thanks again for humoring all this!
  • Quick Links