ExternalDefinition.HideWhenNoValue and Parameter.ClearValue() never work

ExternalDefinition.HideWhenNoValue and Parameter.ClearValue() never work

mhannonQ65N2
Collaborator Collaborator
1,723 Views
5 Replies
Message 1 of 6

ExternalDefinition.HideWhenNoValue and Parameter.ClearValue() never work

mhannonQ65N2
Collaborator
Collaborator

Calling Parameter.ClearValue() doesn't work when HideWhenNoValue is set to true. I have tried setting HideWhenNoValue to true from within code, but it would later revert to false and Parameter.ClearValue() would fail.

I tried setting it to true immediately before calling Parameter.ClearValue() but it still failed. Finally, I edited the actual shared parameter file and it still fails.

 

 

if (defs.TryGetValue(shared.GUID, out var def) && def.HideWhenNoValue)
{
    shared.ClearValue();
}

 

When it fails, it does so with the message 'Cannot call ClearValue when HideWhenNoValue is false.' (I have also double checked and the parameter is not ReadOnly and is shared). How are the HideWhenNoValue property and ClearValue() method supposed to be used?

 

Additionally, even when HideWhenNoValue is set to true, the parameter still shows up in the properties panel.

0 Likes
1,724 Views
5 Replies
Replies (5)
Message 2 of 6

jeremytammik
Autodesk
Autodesk

Interesting. I never noticed these properties before. Hence, no idea how they are supposed to be used. It sounds as if they may be broken.

 

Whenever you have a question about how to use some Revit API call, please check the SDK first of all.

 

I found an occurrence of HideWhenNoValue here:

 

  • .../SDK/Samples/RebarFreeForm/CS/AddSharedParams.cs, line 90

 

I don't see any calls to ClearValue, though.

 

If you are sure they are broken, please submit separate minimal reproducible cases for each of the issues you describe and I can ask the development team to take a look at them:

  

https://thebuildingcoder.typepad.com/blog/about-the-author.html#1b

  

Please keep every issue clear, minimal, unequivocal and separate. Thank you!

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 3 of 6

mhannonQ65N2
Collaborator
Collaborator

I started on a minimal reproducible case and it seems like ClearValue() works when HideWhenNoValue is (manually) set to true in the parameter file before (manually) importing shared parameters as project parameters.

 

It seems that when a shared parameter is loaded into a project (by making a project parameter or using the documents ParameterBindings), Revit stores that parameter's information somewhen and doesn't change it even when the shared parameter is modified (at least for HideWhenNoValue, I am haven't tried this with any other data of the parameter). When accessing Parameter or ParameterElement objects in a document I am only able to see the InternalDefinition, not any ExternalDefinition it may be based on.

 

Is it possible to set HideWhenNoValue to true for a shared parameter that is already used in the project without losing data? Also, If I modify HideWhenNoValue on an ExternalDefinition from a DefinitionFile, how can I make Revit save that change to the shared parameters file (In my testing that change was never saved, I had to do it manually)?

0 Likes
Message 4 of 6

jeremytammik
Autodesk
Autodesk

Interesting observations. Shared parameters are first and foremost an end user feature. Hence, I would ask these questions in the end user Revit architecture forum first. Once that side is clarified, we can return to look at the programming aspects.

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 5 of 6

mhannonQ65N2
Collaborator
Collaborator

I suppose shared parameters are an end user feature, but in the end, both edits through Revit and using the API operate on the same underlying data (though the sets of possible operations available to each option are not equal).

 

I can check what the value of HideWhenNoValue was on a shared parameter when Revit imported/bound it by calling the SharedParameterElement.ShouldHideWhenNoValue() method.

 

I am currently testing if I can ReInsert an ExternalDefinition with the same (or equivalent) bindings when its value for HideWhenNoValue is different from when it was previously imported to achieve the desired result. If not, I strongly suspect that I can use a more complicated and (likely) slow process to do so.

0 Likes
Message 6 of 6

tamas.somsakBX
Explorer
Explorer

I have been struggling with the same problem. The solution was the following: 

  1. I looked for the internal definition of the project parameter (created based on the shared parameter) - got the Definition instance
  2. I used a FilteredElementCollector to search for the corresponding SharedParameterElement in the Revit database with the same Definition
  3. After using ParameterBindings.Remove method on the shared parameter external defintition, I also deleted the correspondig SharedParameterElement instance from the document. (Document.Delete method) - this does cause data loss unfortunately
  4. At this point I changed the HideWhenNoValue property of the external definition to True, than created a new parameter binding with it.
  5. From this point the ClearValue method works fine.

This is my experience on this issue. I hope I could help with it.

0 Likes