'hidden' parms in hidden folders on HDA

   4212   2   2
User Avatar
Member
79 posts
Joined: April 2011
Offline
so if you have a hidden folder and do not hide the parms on an Digital Asset the parms do not show up in the parameter interface. However, if you do a hou.pwd().parm('foo').isHidden() it returns ‘false’! What is the best way to check and see if that parm is actually displayed to the user - is there some hou.parmTemplate or hou.folderParmTemplate way.

I've been playing around with it but seems quite unintuitive - you would think that if a folder is hidden and the parms inside of it do not show up in the interface that the above command would return ‘true’.

Regardless, if there is a way to determine which parms are ‘hidden’ (ie. not showing up in the parameter interface and hou.pwd().parm('foo').isHidden() = false) that would be great at least I can work around this.

Cheers,
User Avatar
Member
3 posts
Joined: June 2018
Offline
I've run into this problem as well and I managed to get something working with a helper function like so:

def is_parm_hidden(parm):
    """Determine whether the given parameter is hidden.

    Args:
        parm (hou.Parm): The parameter to check the visibility of.

    Returns:
        bool: Whether the parameter is hidden in the Parameter
        interface.
    """
    is_hidden = False

    parm_template = parm.parmTemplate()
    if parm_template.isHidden():
        # ignore invisible parameters
        is_hidden = True
    else:
        # ignore parameters in invisible folders
        node = parm.node()
        parm_template_group = node.parmTemplateGroup()
        try:
            parm_folder = parm_template_group.containingFolder(
                parm_template.name()
            )
        except hou.OperationFailed:
            pass
        else:
            if parm_folder.isHidden():
                is_hidden = True

    return is_hidden

It only checks for a single folder as is but it worked for my purposes. If you have multiple levels of folders that might or might not be invisible then you would need to modify the script.

This would be nice if SideFX could change the isHidden to be intuitive like you said. But for now hopefully the python script helps.
User Avatar
Member
30 posts
Joined: Sept. 2023
Offline
I had to combine solutions from multiple posts to get this working, but here's the snippet..
See is_parm_hidden and is_parm_disabled
from typing import List

def get_indexed_parm_name(name: str, multiparm_instance_indices: List[str]):
    """
    Convert something like my_int#_# to my_int2_3 based on the given multiparm indices
    :param name: name of the parameter to format
    :param multiparm_instance_indices: list of multiparm indices which can be obtained from hou.Parm
    :return: indexed parameter name based on current parameter context name
    """
    indexed_parm_name = name

    multiparm_index = 0
    pound_sign_index = name.find("#")
    while pound_sign_index != -1:
        index_value = multiparm_instance_indices[multiparm_index]
        indexed_parm_name = indexed_parm_name.replace("#", str(index_value), 1)
        multiparm_index += 1
        pound_sign_index = indexed_parm_name.find("#")

    return indexed_parm_name


def get_unindexed_parm_name(name: str, multiparm_instance_indices: List[int]):
    """
    Convert something like my_string1_2 to my_string#_#
    :param name: name of the parameter to format
    :param multiparm_instance_indices: list of multiparm indices which can be obtained from hou.Parm
    :return: unindexed parameter name with pound signs from
    """
    old_suffix_index = 0
    for i in range(len(multiparm_instance_indices) - 1, -1, -1):
        index = multiparm_instance_indices[i]
        old_suffix = f"_{str(index)}" if i > 0 else str(index)
        old_suffix_index = name.rfind(old_suffix)
        name = name[:old_suffix_index] + name[old_suffix_index + len(old_suffix):]

    name = name[:old_suffix_index] + "_".join(["#"] * len(multiparm_instance_indices)) + name[old_suffix_index:]
    return name


def _check_conditionals_in_hierarchy(parm: hou.Parm, func):
    """
    Helper function to evaluate conditionals in a parm, respecting its parents' conditionals
    """
    if func(parm):
        return True

    node = parm.node()
    parm_template_group = node.parmTemplateGroup()
    # Because parmTemplateGroup doesn't contain FolderSet, use name instead. The names are unique anyway.
    topmost_parms = [entry.name() for entry in parm_template_group.entries()]

    current_parm = parm
    while current_parm.parmTemplate().name() not in topmost_parms:
        parm_template_name = get_unindexed_parm_name(current_parm.parmTemplate().name(),
                                                     current_parm.multiParmInstanceIndices())

        if parm_template_group.find(parm_template_name):
            parent_folder = parm_template_group.containingFolder(parm_template_name)
            parent_folder_indexed_name = get_indexed_parm_name(parent_folder.name(),
                                                               current_parm.multiParmInstanceIndices())
            current_parm = node.parm(parent_folder_indexed_name)
        elif current_parm.isMultiParmInstance():
            # Ramp positions (e.g ramp_1pos, ramp_2pos) have parent names that don't exactly match a pattern (e.g. ramp)
            # Use parentMultiParm to find the parent
            current_parm = current_parm.parentMultiParm()

        # If the parent parm template is invisible, the parm would be None
        if current_parm is None or func(current_parm):
            return True

    return False

def is_parm_hidden(parm: hou.Parm):
    """
    returns whether a parm is hidden within the entire hierarchy, respecting its parent folders' conditionals
    """
    return _check_conditionals_in_hierarchy(parm, hou.Parm.isHidden)


def is_parm_disabled(parm: hou.Parm):
    """
    returns whether a parm is disabled or hidden within the entire definition hierarchy,
    respecting its parent folders' conditionals
    """
    return _check_conditionals_in_hierarchy(parm, hou.Parm.isDisabled)

It'd be great for the devs to add something built-in to the API to achieve a similar effect
Edited by nd_sliu - Oct. 22, 2024 19:32:02
  • Quick Links