When we were migrating Revit .NET Addin Wizard (RevitNetAddinWizard) to support more Revit API versions such as 2015 and Visual Studio ones such as (2012 and 2013), we noticed an interesting stuff. The IsReadOnly property was removed from both the Definition class and the ExternalDefinition in both version 2014 and 2015, but the new UserModifiable property was added to the ExternalDefinition class only in version 2015 only.
The following code and comments would make it clear if being tried in all the three popular versions of Revit, 2013/2014/2015.
public void DefinitionReadOnlyAndUserModifiable(RvtDocument doc)
{
BindingMap map = doc.ParameterBindings;
DefinitionBindingMapIterator it = map.ForwardIterator();
ElementBinding eleBinding = it.Current as ElementBinding;
InstanceBinding insBinding = eleBinding as InstanceBinding;
Definition def = it.Key;
if (def != null)
{
ExternalDefinition extDef = def as ExternalDefinition;
bool shared = extDef != null;
bool readOnly1 = def.IsReadOnly; //NOT working in either 2015 or 2014 but working in 2013
if (shared)
{
bool readOnly2 = extDef.IsReadOnly; //NOT working in either 2015 or 2014 but working in 2013
bool modifiable = extDef.UserModifiable; //working in 2015 ONLY
}
}
}
So, it seems no way to determine whether a parameter definition is read only or modifiable in Revit 2014 without the parameter (external) definition being instanced, i.e. such a parameter has already been created into the model and used by some elements either manually or programmatically. It is not good because many times we need to check whether the parameter definition is readable only or also writable so as to determine to use it or not, or create a new one.
That might explain why the UserModifiable was finally added to the ExternalDefinition. But still we are wondering why NOT to the Definition class this time. Does it indicate that non-shared parameters will be always modifiable?
Even if for the new property UserModifiable, its meaning is not exactly the opposite of the IsReadOnly, which fact is clearly stated in the API documentation:
“Note that for shared parameters IsReadOnly can return false for shared parameters whose UserModifiable property is also false, because the value of those parameters can be modified by the API. If a parameter is governed by a formula, IsReadOnly would return true, even if the flag for UserModifiable was set to true when the shared parameter was created.”
It is still a bit weird though that a read-only parameter can be user modifiable. Does it indicate that users have more privilege over parameters than the Revit addin itself (or the Revit API with which it’s created) that creates and maintains the parameters?
It seems the UserModifiable and IsReadOnly mean different things anyway, then doesn't it make sense to add the UnserModifiable to the Definition class as well and add the IsReadOnly back to both?
Revit Addin Wizard (RevitAddinWizard) provides various wizards, coders and widgets to help program Revit addins. It can be downloaded from the Download link at the bottom of the blog index page.