I am writing a Revit Add-In that adds a shared instance parameter to the built in category OST_Doors.
I want the parameter to be visible in the Properties panel when I select a door but I do not want the user to be able to change the value of the parameter in the Properties panel. I can see there are some read-only type parameters for door types.
Is there any whay to create a read-only instance parameter for a door? I still want to be able to modify the value of the parameter through code.
Solved! Go to Solution.
Hi,
parameters are readonly or not, this depends not on the person who accesses them (GUI or API).
But there might be a workaround:
Define two parameters instead of one.
The first one is visible, the other one not.
Using API, you can fill the invisible one with your values.
These values are to be copied to the visible parameter, whose values are overwritten hereby.
This overwriting process may be invoked either manually or via an IUpdater.
Your user will see the copied values.
He may edit them, but he cannot overwrite the original parameter's values since this parameter is invisible for him.
Additionally, his modifications to the copied values will be overwritten soon.
Hope that helps.
Cheers,
Revitalizer
Hey Revitalizer,
Thank you for that very cool tip!
Cheers,
Jeremy
How are you reading the instance type parameter? I'm able to set the parameter via the API, but I can't see the value later through the API. I can see that the parameter exists, but I can only see the value if the user clicks on the object directly. Is there no way to parse through all the objects of that type in the document and report the values of the instance parameters without requiring the user to click?
Regards,
Glen
Here is an example of how I get a parameters value.
famInstance is the FamilyInstance object.
"parameterName" is the name of the parameter.
Parameter param = famInstance.ParametersMap.get_Item("parameterName");
String parameterValue = param.AsString();
In the Revit API version for Revit 2015 it is now possible to define a shared parameter that is visible but read only for the user but can be modified through the API. This can be done with the UserModifiable member of the ExternalDefinitonCreationOptions class.
ExternalDefinitonCreationOptions options = new ExternalDefinitonCreationOptions("myparameter", ParameterType.Text);
options.Visible = true;
options.UserModifiable = false;
This has solved my problem.
what if shared parameter already being used in Revit which is visible and writable, how to make it read-only or locked?
I do not think the API enables you to change it after it has been created.
Hi,
Here's my code to create a project parameter:
public static bool CreateProjectParameter(string parameterName,string sharedParemeterFileName,
BuiltInParameterGroup parameterGroup, List<BuiltInCategory> bics, Document doc)
{
bool retValue = true;
Application app = doc.Application;
string oriFile = app.SharedParametersFilename;
string tempFile = sharedParemeterFileName;
app.SharedParametersFilename = tempFile;
DefinitionFile defFile = app.OpenSharedParameterFile();
var v = (from DefinitionGroup dg in defFile.Groups
from ExternalDefinition d in dg.Definitions
where d.Name == parameterName
select d);
if (v == null || v.Count() < 1) throw new Exception("Invalid Name Input!");
ExternalDefinition def = v.First();
CategorySet cats = app.Create.NewCategorySet();
foreach (BuiltInCategory bic in bics)
{
cats.Insert(doc.Settings.Categories.get_Item(bic));
}
Autodesk.Revit.DB.Binding binding = app.Create.NewInstanceBinding(cats);
BindingMap map = (new UIApplication(app)).ActiveUIDocument.Document.ParameterBindings;
map.Insert(def, binding, parameterGroup);
app.SharedParametersFilename = oriFile;
return retValue;
}
Now I would like to add an option for a read only parameter using ExternalDefinitionCreationOptions but I don't know how to implement it in my code.
Any help?
Thanks
You can do this, but there are a couple steps.
1. Remove Parameter from project (Internal and External Definition of SP)
private void DeleteParameters(Document doc)
{
List<string> names = new List<string>()
{
"Param Name 1",
"Param Name 2",
"Param Name 3"
};
using(Transaction t = new Transaction(doc))
{
t.Start("Delete Parameters");
using(FilteredElementCollector fec = new FilteredElementCollector(doc).OfClass(typeof(ParameterElement)))
{
foreach(ParameterElement param in fec.ToElements())
{
try
{
if(names.Contains(param.Name))
{
doc.Delete(param.Id);
}
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString(), param.Name);
continue;
}
}
}
t.Commit();
}
}
2. Modify Shared Parameter file to indicate Visible (0 or 1), User Modifiable (0 or 1)
# This is a Revit shared parameter file.
# Do not edit manually.
*META VERSION MINVERSION
META 2 1
*GROUP ID NAME
GROUP 1 Project Information
*PARAM GUID NAME DATATYPE DATACATEGORY GROUP VISIBLE DESCRIPTION USERMODIFIABLE HIDEWHENNOVALUE
PARAM 92eb4500-29a8-4e46-b1ef-13852bd93911 Param Name 1 TEXT 1 1 Describe the Parameter 0 0
3. Add Parameter back to Project