Search the Uniformat file & Set the Parameter

Steve makes a good observation in this post:

It would be nice if we could search for keywords when attempting to assign the parameters for both Omniclass and Uniformat. Sometimes the best category to use in Revit isn’t necessarily the correct category in these classification systems. This means a fair bit of time wasted hunting for an appropriate value. I search the source files to find keywords first which isn’t the most straightforward.

Here’s a proof-of-concept showing how it could be done without too much heavy lifting. I haven’t coded a UI for this as I mention in the source code comments, but getting the search string from the text note is a fine simplification to show what to do with the search string.

public void uniformatSearch()
    UIDocument uidoc = this.ActiveUIDocument;
    Document doc = this.ActiveUIDocument.Document;

    // select the element whose Uniformat parameter will be set
    Element e = doc.GetElement(uidoc.Selection.PickObject(ObjectType.Element, "Select the element to set Assembly Code."));

    // select a text note whose text indicates the string to search for
    // in a real app there would be UI to enter this search string, but this works for a proof of concept macro
    TextNote text = doc.GetElement(uidoc.Selection.PickObject(ObjectType.Element, "Select the text note with the search term.")) as TextNote;

    // the location of the Uniformat file
    string appData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
    string uniformatFile = Path.Combine(appData, @"Autodesk\revit\Autodesk Revit Architecture 2013", "UniformatClassifications.txt");

    IList<string> matches = new List<string>();
    // read the uniformat file one line at a time
    using (StreamReader read = new StreamReader(uniformatFile))
        string line;
        while ((line = read.ReadLine()) != null)
            // add the line to the list of matches if it contains the search string
            if (line.Contains(text.Text))
    // show all matches
    TaskDialog.Show("Matches for " + text.Text, listToString(matches));

    // get the type of the selected element and its uniformat parameter
    ElementType eType = doc.GetElement(e.GetTypeId()) as ElementType;
    Parameter p = eType.get_Parameter(BuiltInParameter.UNIFORMAT_CODE);

    // set the value of the parameter to the first entry in the match list - good enough for this proof-of-concept
    using (Transaction t = new Transaction(doc,"Set Uniformat"))
        // the uniformat file is a tab-delimited file
        // the string to use to set the parameter is the first entry [0] in the array created by splitting the complete string
private string listToString(IList<string> stringList)
    string ret = "";
    foreach (string s in stringList)
        ret += s.Replace("\t"," ") + "\n";
    return ret;

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s