Clear parameter value

Hello to everyone

Is there any way to reset an object’s parameter value?
because when i am trying to assign value to Comment parameter it just doesn’t work :c
image

Try putting text into a panel

Hello!

Thank you for the reply! The problem is that Comment parameter is being held as the String; so it assigns the same well

i have also tried to assign an Integer to the parameter, but it only returned an error

Are you trying to use the Integer as a calculation elsewhere in Revit? Just use the String value of 54, if you bring it back into GH it will cast to Integer once again.

If you need an Integer you have to make a new parameter in Revit, probably Shared.

Comments is hard coded string value

https://www.revitapidocs.com/2020/d64db023-f9a1-9177-1fb2-054625d19673.htm

But the thing i want to achive is to reset the parameter’s value. Like Mark value here. It is completely empty. So i want Comments to become empty again, as it is by default, when you creating a brand new wall.
image

just plug in a blank panel

oh, thanks! it works


but be careful:

Sory, but here is an another problem: the represented method doesn’t work for the integer parameters. I have found something in API:
https://www.revitapidocs.com/2020/14658620-d5d5-d8f2-1b6c-343180951d63.htm
But i am not able to create a code-script :innocent:
I think providing such kind of node would be useful for the project.

The documentation says:

This method will only succeed for Shared parameters that have their HideWhenNoValue property set to true.

What should we do with non shared parameters?

Hello, thank you for joining discussion!

i am not fluent in english, but i think this means, that it works for ALL NON-SHARED parameters AND for SHARED PARAMETERS, WHICH are not hiding when they have no value. It is logically consequent, because base project parameters are never hiding from Properties panel, simultaneously some shared parameters are.

I should just try test ClearValue() for several parameters, to check how it works, but i need to deal with programming languages first :sweat_smile: :sweat_smile: :sweat_smile: So, i hoped, someone has a ready solution yet.

Here is a related topic from our Dynamo homies:

Hi,

I tested it an unfortunately this is the result on non shared parameters.

image

We have included a new component called Reset Element Parameter that sets everything to False, 0, null, empty string, black color, depending on the parameter type.
If the parameter fulfills ClearValue() requirements we call ClearValue() on it.

As you may expect some parameters do not accept 0.0 as value like Unconnected Height in Walls, in that case the component just shows the error.

Will this help?

2 Likes

Fact,it still not developed in revit 2022, we still cannot use clear value with share parameter because function it require hidewhennovalue. :slightly_smiling_face: , because don’t have any user want hide share parameter to use, result when use function clear value when use snoop still is value 0 or not empty.

1 Like

Hi @kike

I’ve tried to use the component to clean the instance parameter “Mark”, however it returns instead of , any idea?

The element never had a value before show in the list.
image

Hi @ctu6,

I double cheked the code that ‘Reset Parameter’ component is calling.

public static bool ResetValue(this Parameter parameter)
{
  if (!parameter.HasValue)
    return true;

#if REVIT_2020
  if
  (
    parameter.IsShared &&
    (parameter.Element.Document.GetElement(parameter.Id) as SharedParameterElement)?.ShouldHideWhenNoValue() == true
  )
    return parameter.ClearValue();
#endif

  switch (parameter.StorageType)
  {
    case StorageType.Integer:   return parameter.AsInteger() == 0                            || parameter.Set(0);
    case StorageType.Double:    return parameter.AsDouble() == 0.0                           || parameter.Set(0.0);
    case StorageType.String:    return parameter.AsString() == string.Empty                  || parameter.Set(string.Empty);
    case StorageType.ElementId: return parameter.AsElementId() == ElementId.InvalidElementId || parameter.Set(ElementId.InvalidElementId);
  }

  return false;
}

First thing the method does is check if the parameter already has a value or not.
So if the parame never had before a value ‘Reset Parameter’ does not touch it.

Unfortunately there is no way to really set no value (null) to a built-in parameter like ‘Mark’.

1 Like