Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Family Rename

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
Anonymous
5858 Views, 8 Replies

Family Rename

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.

8 REPLIES 8
Message 2 of 9
mikako_harada
in reply to: Anonymous

Hi Danny, 

 

Looking at RevitAPI.chm file, I see Family class has name property which is get/set.  Could you try it? 


Mikako Harada
Developer Technical Services
Message 3 of 9
Anonymous
in reply to: mikako_harada

Thank you.  That worked perfectly.

 

Message 4 of 9
Anonymous
in reply to: Anonymous

How did you do this? I get an error when I try this.

Message 5 of 9
Anonymous
in reply to: Anonymous

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());
            }
        }
    }
Message 6 of 9
Anonymous
in reply to: Anonymous

Thank you. Your little sample code worked perfectly.

Message 7 of 9
walter
in reply to: Anonymous

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?  

Message 8 of 9
RPTHOMAS108
in reply to: walter

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

200426a.png

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).

200426b.png

In SharpDevelop insert contents of enclosed text file to location noted below:

200426c.png

In SharpDevelop build the project (1) then save the project (2) and close SharpDevelop.

200426d.png

Back in Macro Manager select the 'StartRename' macro (1) and run it (2). 

200426e.png

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.

 

Message 9 of 9
C.Benke
in reply to: RPTHOMAS108

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.

Post to forums  

Forma Design Contest


Rail Community