Is it possible to rename families in a project through the API. We are recently updating and standardizing our family naming convention. I'd like to build an add-in that would rename the families in existing project to the new standard names. I haven't had any success finding an example of this online.
Solved! Go to Solution.
Solved by mikako_harada. Go to Solution.
Hi Danny,
Looking at RevitAPI.chm file, I see Family class has name property which is get/set. Could you try it?
Nicklas,
Below is my class. I'm using a dictonary lookup but I think that its very easy to look up the name using Excel or replace with whatever you'd like.
I hope this helps.
class changeFamilyNames { public virtual string Name { get; set; } int count; public void changeFamiliesNames(Document doc) { //Gets the families Family familyNames = null; FilteredElementCollector collector = new FilteredElementCollector(doc); ICollection<Element> collection = collector.OfClass(typeof(Family)).ToElements(); ValueDictionary dictionaryList = new ValueDictionary(); var dictionary = dictionaryList.GetRenameFamilies(); using (Transaction t = new Transaction(doc)) { t.Start("new name"); foreach (Element e in collection) { familyNames = e as Family; string familyName = familyNames.Name; try { //Checks the dictionary and if found renames the family if (dictionary.ContainsKey(familyName)) { string value = dictionary[familyName]; familyNames.Name = value; count++; } } catch { } } t.Commit(); string message = "Number of Families Renamed: "; MessageBox.Show(message + count.ToString()); } } }
How does this work? I am not a software programmer. I need a script to run in Revit projects to check the family names and replace them with a new custom naming conventions. How can I run this from an Excel spreadsheet or can the list be built in the dictionary list?
The above is only a partial solution so of no use to a non-programmer.
I've written a macro for this (attached as a text file) and it can be added to the Revit document macros and run in the following way:
Open Macros Manager
Select the document Tab you want to rename families in (1). Create a new module (2). Set language of new module to VB.NET and add a name for the module (3).
In SharpDevelop insert contents of enclosed text file to location noted below:
In SharpDevelop build the project (1) then save the project (2) and close SharpDevelop.
Back in Macro Manager select the 'StartRename' macro (1) and run it (2).
You will be prompted for a comma delimited file this can be created from Excel by doing a SaveAs and then selecting 'CSV (Comma delimited)(*.csv)' from the list. There are various other options of saving CSV files from Excel but I use the one I've just noted and can't comment on the suitability of the others.
The CSV file should be in the form:
Current FamilyName1,New FamilyName1
Current FamilyName2,New FamilyName2
etc.
Various check are undertaken: illegal family name characters, desired name already exists in project, family of name has already been named previously in CSV, another family already named with desired name etc. A log should be presented at the end if any of these items occur.
Work sharing element ownership/update status not allowed for.
Thank you, this macro is really useful. Do you know how to add an option to change family type name as well?
Can't find what you're looking for? Ask the community or share your knowledge.