I need to add new parameters to all rooms in a project. I can't figure this out, any help is most appreciated. Here's where I am:
using (Transaction t = new Transaction(doc, "Update room parameters"))
{
t.Start();
foreach (var model in roomDataModels)
{
Room room = model.Room;
try
{
Autodesk.Revit.DB.Parameter parameter = room.LookupParameter("Sample new parameter");
if (parameter == null)
{
// Add the missing parameter to the rooms here
// Make it a text parameter, with no default value
}
else if (parameter != null && parameter.HasValue == false)
{
parameter.Set(model.SampleNewParameter);
}
}
catch (Exception e)
{
// ignored
}
}
t.Commit();
I found this solution, but can't seem to get it to work:
https://forums.autodesk.com/t5/revit-api-forum/add-parameters-to-element/m-p/7709609#M28042
The approach in the thread you point out looks fine to me, just taking a quick look. I answered a related question in the Revit API discussion forum yesterday, on how to create and add custom attributes:
You can achieve this using shared parameters. They can optionally be made visible and editable by the user in the UI as well. Another option is to implement extensible storage data. In that case, the user has no access or UI to see or edit, and only the add-in can access and modify data.
The Building Coder shares numerous examples on how to add shared parameters programmatically in the parameters category. One of my favourite implementations is described in Driving CNC Fabrication and Shared Parameters.