Parameter Clear Values

Parameter Clear Values

Rajamanickam.G
Participant Participant
4,408 Views
8 Replies
Message 1 of 9

Parameter Clear Values

Rajamanickam.G
Participant
Participant

Can someone please explain how Parameter.ClearValue() work?

 

I see this new feature has been implemented from 2020 API, but i struggle to make it work.

 

Any help would be appreciated. Thanks

0 Likes
Accepted solutions (1)
4,409 Views
8 Replies
Replies (8)
Message 2 of 9

architect.bim
Collaborator
Collaborator

Hi!

Some parameters have there initial value. For example if you create project "Yes/No" parameter in Revit UI it looks like this:

210120_1620_002.jpg

It is neither checked, nor unchecked.

If you check it once you are unable to return it to its initial state again via UI. But Revit API allows you to do this with ClearValue() method.

 

There are some other cases when it may be helpful. For instance if you work with Shared Parameters and make them visible only if they have value. If you want them to disappear again from UI, you need to use this method to turn them to initial state.


Maxim Stepannikov | Architect, BIM Manager, Instructor
0 Likes
Message 3 of 9

architect.bim
Collaborator
Collaborator

Small addition: this method can be applied only for Shared Parameters.


Maxim Stepannikov | Architect, BIM Manager, Instructor
0 Likes
Message 4 of 9

Rajamanickam.G
Participant
Participant

Hi @architect.bim ,

 

Thanks for your reply. It is clear and I am now able to get some picture of how this works.

 

What I am actually after, I could explain with an example

 

I have a shared parameter called SP_Space_Temperature with °C as unit and null as value.

Once someone enters a value and applies it to the element, it always requires a value, but in my case I don't need any value even 0 and want to reset it to the initial value i.e null.

 

ValuesValues

 

But it shows the following error when i try to erase the value.

 

errorerror

 

So i thought this could be solved with Parameter.ClearValue() method. Is this possible?

 

Thank you.

0 Likes
Message 5 of 9

architect.bim
Collaborator
Collaborator

I think this method is definitely for your case!


Maxim Stepannikov | Architect, BIM Manager, Instructor
0 Likes
Message 6 of 9

Rajamanickam.G
Participant
Participant

This is what I tried till now

 

public void resetParamValues()
{
    UIDocument uidoc = this.ActiveUIDocument;
    Document doc = uidoc.Document;
    
    Selection sel = uidoc.Selection;
    Reference spaRefer = sel.PickObject(ObjectType.Element, "Select the space");
    
    var elem = doc.GetElement(spaRefer) as Element;
    
    var parameter = elem.LookupParameter("SP_Space_Temperature");
    
    var check = parameter.ClearValue();
}

 

error messageerror message

How could i set the HideWhenNoValue of this shared parameter to true? and clear the value?

0 Likes
Message 7 of 9

architect.bim
Collaborator
Collaborator
Accepted solution

Oh, I see. Unfortunately there is one more limitation written in docs (sorry, I missed it).

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

This property can be set to true only in Shared Parameters File before you add your parameter to the project.

You can do it either through Revit API (modifying ExternalDefinition object) or manually - open Shared Parameters File in text editor and change value for a particular parameter.

210120_1836_003.jpg

After this you can add this parameter to your project. And use ClearValue method. But keep in mind: with HideWhenNoValue property set to True your parameter will also be hidden in Revit UI after you use this method.

 

But unfortunately there is no other way to turn parameter value to its initial state.


Maxim Stepannikov | Architect, BIM Manager, Instructor
0 Likes
Message 8 of 9

Rajamanickam.G
Participant
Participant

Very nice. This actually works.

 

But you are right if we turn the property HideWhenNoValue on, then we don't have the possibility to enter the value again after clearing the values since they disappear from the UI.

 

Thanks a lot for your time.

Message 9 of 9

ciganek
Enthusiast
Enthusiast

I had hoped that ClearValue would reset any parameter back to the 'unchanged' state. This is of very limited use when only available for shared parameters with HideWhenNoValue set to true as this feature, though useful, is probably not used that often as the user can not set a value manually. Oh well - maybe we will be given a Reset() method in a future release...