Boost Your BIM – making Revit even better

January 28, 2013

Bulk Family Parameter Editing in Excel

Filed under: Families, Parameters — Harry Mattison @ 10:45 am

After the recent discussions about the OmniClass and UniFormat parameters, I’ve been thinking about more generic tools optimized for modifying multiple parameters for multiple families.

One option would be to build a big grid-like UI as part of a Revit API app where the parameters could be edited.

Easier would be to export everything to Excel, let you make changes there, and then modify the parameters by reading back in the Excel file. The first half of this process (Export to Excel) could look like this:

In its current state, this isn’t usable for parameters that store element IDs (like Material). But if you could read this data into Revit to set text and numeric parameter values, would it be helpful?

public void FamilyParametersToExcel()
    Autodesk.Revit.ApplicationServices.Application application = this.Application;
    string directory = @"C:\ProgramData\Autodesk\RAC 2013\Libraries\US Imperial\Columns";
    string s = "";

    // loop through all files in the directory
    foreach (string filename in Directory.GetFiles(directory))
        s += "Family Name,Family Type,";
        Document doc = application.OpenDocumentFile(filename);

        if (!doc.IsFamilyDocument)
            return; // skip any files that are not families

        FamilyManager familyManager = doc.FamilyManager;

        // sort the family parameters alphabetically
        List<string> paramSorted = new List<string>();
        foreach (FamilyParameter fp in familyManager.Parameters)

        // create a header row listing the parameter names for this family
        foreach (string paramName in paramSorted)
            FamilyParameter familyParameter = familyManager.get_Parameter(paramName);
            s += familyParameter.Definition.Name + ",";
        s += "\n";

        // create a row for each family type
        foreach (FamilyType familyType in familyManager.Types)
            if (familyType.Name == " ") // skip the 'default' family type with no name

            s += doc.PathName + "," + familyType.Name + ",";

            foreach (string paramName in paramSorted)
                FamilyParameter familyParameter = familyManager.get_Parameter(paramName);
                s += ParameterValueForType(familyType, familyParameter) + ",";
            s += "\n";
        s += "\n";                

    // write the CSV file to disk
    string outfile = directory.Replace(@"\","-").Replace("C:","") + "-Parameters.";
    outfile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), outfile);
    using (StreamWriter streamWriter = new StreamWriter(outfile))

    // open the CSV file

private string ParameterValueForType(FamilyType type, FamilyParameter p)
    // return a string with the value of the parameter for this type
    string paramValue = "";
    switch (p.StorageType)
        case StorageType.Double:
            paramValue = type.AsDouble(p).ToString();
        case StorageType.ElementId:
            paramValue = type.AsElementId(p).IntegerValue.ToString();
        case StorageType.Integer:
            paramValue = type.AsInteger(p).ToString();
        case StorageType.String:
            paramValue = type.AsString(p);
    if (paramValue == null)
        paramValue = "";

    return paramValue;
About these ads


  1. Great Sir!

    Comment by flaxoice — January 28, 2013 @ 11:57 am

  2. If it imports and edits the correct parameters, we would be interested. Would it work from the Project as well? Or by directory? Or have to be in the Family? Devil in the details. :)

    Comment by Aaron Maller (twiceroadsfool) — January 28, 2013 @ 1:11 pm

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

The WordPress Classic Theme Blog at


Get every new post delivered to your Inbox.

Join 972 other followers