Jump to content

How to check if a parm has its default value in HOM?


melazoma

Recommended Posts

Hi all,

I'm trying to figure out how to determine if a parameter is at its default value in python.\

The goal is to ignore a parameter if it's at default.

Methods of node.parm has revertToDefaults() that actually reverts the parm back to default--which is not what I'm trying to do.

I'm not seeing other likely candidates in the intellisense. Where is the default parm value method hiding?

Link to comment
Share on other sites

Unfortunately there is currently no quick way to determine if a parameter is at it's default value. It's an existing RFE.

You can hack it by doing some magic involving the hou.ParmTemplate from the parm though. Unfortunately this method involves evaluating each parm so that can cause slowdown if they require significant time to evaluate. Something like this can give you what you want.

def isParmDefaultValue(parm):
	# Get the parm tuple so we can access the names of all the parms in the group.
	parm_tuple = parm.tuple()
	# Get a list of the parm names.
	parm_names = [p.name() for p in parm_tuple]
	# Find the index of our parm in the tuple.
	idx = parm_names.index(parm.name())
	# Use the index to get the correct default value.
	default_value = parm_tuple.parmTemplate().defaultValue()[idx]
	# Return whether the current value is equal to the default value.
	return parm.eval() == default_value

You can also take it a step further and add the declaration into something like your pythonrc.py file, replace the "parm" variable name with "self" and outside the declaration do something like hou.Parm.isDefaultValue = isParmDefaultValue. This way you can just call isDefaultValue from your hou.Parm instance.

Edited by graham
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...