This is one problem took more time to solve.
Requirement: Addin should create parameters on launch.
Problem: We didn’t face any issues unless there are doors inside groups in the Revit model.
Step 1: Creating parameter is straight forward implementation from Revit API.
try
{
var doc = UIApp.ActiveUIDocument.Document;/*create a temporary file to store parameters then apply to model*/
string originalFile = UIApp.Application.SharedParametersFilename;
string tempFile = Path.GetTempFileName() + “.txt”;
using (File.Create(tempFile)) { }
UIApp.Application.SharedParametersFilename = tempFile;
ExternalDefinitionCreationOptions edCO = new ExternalDefinitionCreationOptions(parameterName, parameterType);
edCO.Visible = isVisible;
var definition = UIApp.Application.OpenSharedParameterFile().Groups.Create(groupName).Definitions.Create(edCO);/*revert file back to original file*/
UIApp.Application.SharedParametersFilename = originalFile;
File.Delete(tempFile);var newCategory = doc.Settings.Categories.get_Item(builtInCategory);
var newCategorySet = UIApp.Application.Create.NewCategorySet();
newCategorySet.Insert(newCategory);
Autodesk.Revit.DB.Binding binding = UIApp.Application.Create.NewInstanceBinding(newCategorySet);doc.ParameterBindings.Insert(definition, binding, paramGroup);
}
Now Step 2, mark that parameter with vary by group instance flag
var doc = UIApplication.ActiveUIDocument.Document;
/*Here element could be door and the parameterName that you just created or want to change*/
var opdef = element.LookupParameter(parameterName).Definition as InternalDefinition;
if (opdef != null && !opdef.VariesAcrossGroups)
opdef.SetAllowVaryBetweenGroups(doc, true);
Now Step 3: Here is the final change need to be done.
we tried to create different parameters with different data types like integer and text.
Note: Revit allowed us to create only parameters with type Text. It didn’t allow any other data types.
So in Step 1, Always set the parameterType to ParameterType.Text.