BuiltInParameter by string

Hi all,

I was wondering if there is a way to make “(BuiltInParameter.ALL_MODEL_TYPE_MARK)” dynamic.

ParameterValueProvider(ElementId(BuiltInParameter.ALL_MODEL_TYPE_MARK))

Is thinking along those lines inefficient? Am I missing something? I think there’s a way to achieve this, but I don’t want to map everything, especially if the API changes.

builtInParameterMap = {
    "ALL_MODEL_TYPE_MARK": BuiltInParameter.ALL_MODEL_TYPE_MARK,
    # It's a tedious and risky task to map everything.
}

def get_parameter_value_provider(param_name):
    """
    Creates a ParameterValueProvider for a given parameter name string.

    Args:
    param_name (str): The name of the built-in parameter as a string.

    Returns:
    ParameterValueProvider: The created ParameterValueProvider instance, or None if invalid name.
    """
    built_in_param = builtInParameterMap.get(param_name)
    if built_in_param is not None:
        return ParameterValueProvider(ElementId(built_in_param))
    else:
        print(f"Parameter '{param_name}' not found.")
        return None``

i can use

getattr(BuiltInParameter, param_name)

But what if I ask users to select the parameter? I have a situation where the description of the iterator doesn’t always align with the definition name.

    all_elements = FilteredElementCollector(doc).OfCategory(mydict[category]).ToElements()
    
    # get the first element to fetch the parameters
    src_element = list(all_elements)[0]
    
    # get the parameters of the element
    p_names = {p.Definition.Name: p.Id for p in src_element.Parameters}
    

    
    param_name = forms.SelectFromList.show(p_names.keys(), button_name='Select Parameter', multiselect=False)

thank you in advance for your time :slight_smile:

@Gian_Claudio ,

i think thats the best way… to work with Parameter.Bindings…

so they can select the parameter

here is something similar