Omni Class Numbers

Revit 2010 supports OmniClass codes. The Revit Architecture help provides the following background information on these codes in the section on Preparing Content for Sharing with Autodesk Seek, which is currently only available in the English edition:

OmniClass is a new classification system for the construction industry. The Autodesk Seek website uses codes from OmniClass Table 23 to filter and identify shared content. A code consists of an OmniClass number and title.

If an OmniClass code is not already assigned to a family, you are prompted to assign one during the sharing process. However, you can continue to share with Autodesk Seek without defining one. All Revit families have parameters for assigning an OmniClass code, except for the System and Annotation families.

You can access the OmniClass Number and OmniClass Title parameters in the Family Category and Parameters dialog under Family Parameters. See Family Category and Parameters.

Question: How can I retrieve all available OmniClass numbers and their descriptions from a model? I also need to retrieve the OmniClass numbers from the elements in the model.

I am using the export to ODBC functionality in Revit Architecture to find relevant data. The export process produces an OmniClassNumbers table. You can see the OmniClass numbers in the Revit user interface by opening a family drawing and clicking on the Category and Parameters tool. The OmniClass Number field is displayed in Family Parameters in the bottom section of that window. The resulting dialog displays the same data as that exported to the OmniClassNumbers table by the built in tool.

I need to

  1. Acquire the data already exported to the OmniClassNumbers table by the built in tool.
  2. Determine what OmniClass an element or type belongs to

Answer: The Revit API defines two built-in parameters for accessing the OmniClass data:

We can extract these parameter values for the elements which are contained in the model. Some may already be present as instances in the model, some may be part of the template that was used to create it, and some may have been loaded into it as families.

We can extract these parameter values for the elements which are contained in the model. Some of these elements may already be present as instances in the model, some may be part of the template that was used to create it, and some may have been loaded into it as families.

Below is a piece of code to filter out all the elements in the model which have OmniClass data available. First, we define two class variables for the built-in parameters of interest:

BuiltInParameter _bipCode
  = BuiltInParameter.OMNICLASS_CODE;
 
BuiltInParameter _bipDesc
  = BuiltInParameter.OMNICLASS_DESCRIPTION;

Then we can implement an external command class with the following code in its Execute method, which produces the same data as the Revit exported ODBC data from the user interface:

Application app = commandData.Application;
Document doc = app.ActiveDocument;
 
List<Element> set = new List<Element>();
 
ParameterFilter f
  = app.Create.Filter.NewParameterFilter(
    _bipCode,
    CriteriaFilterType.NotEqual,
    string.Empty );
 
ElementIterator it = doc.get_Elements( f );
 
using( StreamWriter sw
  = File.CreateText( "C:/omni.txt" ) )
{
  while( it.MoveNext() )
  {
    Element e = it.Current as Element;
    sw.WriteLine( string.Format(
      "{0} code {1} desc {2}",
      Util.ElementDescription( e ),
      e.get_Parameter( bipCode ).AsString(),
      e.get_Parameter( bipDesc ).AsString() ) );
  }
  sw.Close();
}
return IExternalCommand.Result.Failed;

We use a highly efficient Revit API filter to select only those elements which have a non-empty OmniClass code. For those elements, the code and description is extracted from the element parameters and logged to a text file.

This code also demonstrates how to extract the built-in OmniClass parameters from any given individual element.

Many thanks to Saikat Bhattacharya for handling this case!

Revit 2010 Product Feature Recordings

There are a number of YouTube recordings available discussing and demonstrating new Revit 2010 product features. Here is a list of some of them: