Limit the Range of HDA Parameter

   826   3   1
User Avatar
Member
27 posts
Joined: Sept. 2017
Offline
Hi All,

In the attached example I have a simple HDA with two parameters, what I need is for the second param to have a maximum range dependent on the value of the first param (max range limited to half the value of the first param).

Although it's possible to inject HScript snippets in the Channels tab of the Operator Type Property window, it's apparently not possible to do the same in the range input.

Any ideas on how to achieve this?

Thanks
Edited by netlander - June 19, 2023 07:16:34

Attachments:
Screenshot 2023-06-19 121040.png (98.6 KB)
Limit the Range of HDA Parmeter.hipnc (100.7 KB)

User Avatar
Member
48 posts
Joined: Aug. 2017
Offline
the range option is purely for cosmetic purpose, it only affect how the interface will display the parameter and wouldn't prevent the user from adding value above the defined range and you can't setup a dynamic behavior for it.
one way I see you could 'enforce' a real range is using the hda's python module script that would automatically update the value of the Bevel parameter when the value of the size and/or bevel parameter change (using the callback script).

for exemple (not tested) :
def enforceRange(kwargs):
node = kwargs["node"]
sizeValue = node.evalParm("Size")
bevelValue = node.evalParm("Bevel")
if bevelValue > sizeValue:
node.parm("Bevel").set(sizeValue)

you could also make it a bit more dynamic by giving the 2 parameter you'd wish to enforce and reuse the function in the callback parameter :
def enforceRange(kwargs, rangeParm, parm):
node = kwargs["node"]
range = node.evalParm(rangeParm)
value= node.evalParm(parm)
if value> range :
node.parm(parm).set(range )

callback :
hou.phm().enforceRange(kwargs, "Size", "Bevel")

second way is to use a clamp hscript function on whichever node you're using inside the hda to ensure the limit is always enforced no matter what.

I wouldn't recommend trying to cheat by updating the UI of the hda using python.
Edited by SciTheSqrl - June 19, 2023 08:15:34
User Avatar
Member
27 posts
Joined: Sept. 2017
Offline
Thanks for the answer which is somewhat more involved than I hoped and will likely look into it at some point as I need to embrace this aspect of Houdini scripting.

SciTheSqrl
the range option is purely for cosmetic purpose, it only affect how the interface will display the parameter and wouldn't prevent the user from adding value above the defined range...

There is the padlock icon next to the range boudaries to prevent the end-user from going outside of the range.
User Avatar
Member
1 posts
Joined: May 2024
Offline
Hello,

I tryed to dynamicly "enforce" max range value of a switch with the number of switch input like this :

def enforceRange(kwargs):
node = kwargs
inputvalue = opninputs(',')-1

node.parm("Range").set(0,inputvalue)

but of course it doesn't work because the range need two values (min and max)...how do I set the max value ? any ideas ?

By the way got the error : Traceback (most recent call last): File "Sop/Test::1.0/ModByC", line 1, in <module>
TypeError: enforceRange() takes 1 positional argument but 2 were given
  • Quick Links