2

I modified a number of Revit Beam and Column families to add a parameter to be used to associate a series of model elements for scheduling purposes. Now my boss has asked me to change the name of that parameter (from the name he had first suggested).

Note that this parameter is an instance parameter which is not a shared parameter.

Now I want to do two things programmatically -- first, I would like to rename that parameter whenever it is used to the new name. Secondly, I would like to ADD that parameter (new name) to other beam/column families if it has not been defined in those families.

I have explored a couple methods online, such as:

    BindingMap All_Binding = doc.ParameterBindings;
    DefinitionBindingMapIterator Iterator = All_Binding.ForwardIterator();
    Iterator.Reset(); List<string> BindingList = new List<string>();
    while (Iterator.MoveNext())
    {
        Definition def = Iterator.Key;
        ElementBinding Binders = (ElementBinding)Iterator.Current;
        BindingList.Add(def.Name);
    }
    BindingList.Sort();

This returns a list of the Shared Parameters available in the project.

I've also explored the FamilyManager, but that is not well documented. I tried:

doc.FamilyManager.RenameParameter(FamilyParameter *****, "Label Group") but the FamilyManager options are not well documented (and I'm not even sure if the "FamilyParameter" listed matches a parameter defined inside a ".rfa" file, or another thing entirely). I tried putting the Parameter associated with ElementName.Parameters as the FamilyParameter *******, but Visual Studio says wrong type, and when I try adding "as Family Parameter", it says "cannot implicitly convert Parameter to FamilyParameter".

Can anyone offer me pointers about how I might add or rename parameters for families already in my project?

KeachyPeen
  • 147
  • 2
  • 13

2 Answers2

2

If you know the name of the parameter you want to change than you can use the below solution (edit family mode):

Document doc = this.ActiveUIDocument.Document;

if( !doc.IsFamilyDocument )
{
    TaskDialog.Show("Error","This is not a family document");
    return;
}

//give here old and new name
string oldname = "Reverse_direction";
string newname = "Reverse direction";

FamilyManager fman = doc.FamilyManager;

if (fman.get_Parameter(oldname) != null)
{
    using (Transaction t = new Transaction(doc,"Change name"))
    {
        t.Start();
        FamilyParameter param = fman.get_Parameter(oldname);
        fman.RenameParameter(param, newname);
        t.Commit();
    }
}
adam.k
  • 324
  • 3
  • 14
0

I think you were more on the right track staying within the document and trying to modify the Project Parameters there; though I'm not sure if you'll be able to get those back into the family easily. I would try looking at Element.ParametersMap instead and try to edit the document itself anytime itself. You could even think about an event that's triggered everytime the document is opened to look for parameters with "X_Name" and have it change from there. Ultimately though you're changing the document, not the family which is why I think you kept getting errors when trying to convert from Parameter to FamilyParameter.

Let me know if that works out by the way, I'm trying to do something similar at the moment too!

prestonsmith
  • 758
  • 1
  • 9
  • 29