We have CreateDimensions SDK sample. This sample shows you how to create dimensions by simplifying the part of finding geometry references from the analytical line of a wall. However, the sample does not work in Revit 2013 (and 2012) since it has not incorporated the change. The geometries of the analytical model have to be accessed from the analytical model of each element.
If you replace the part of Command.cs in the sample with the following code, the sample will find the geometries from the analytical mode and creates the dimension.
//get out all the walls in this array, and create a dimension from its start to its end
for (int i = 0; i < m_walls.Count; i++)
Wall wallTemp = m_walls[i] as Wall;
if (null == wallTemp)
//get location curve
Location location = wallTemp.Location;
LocationCurve locationline = location as LocationCurve;
if (null == locationline)
Line newLine = null;
ReferenceArray referenceArray = new ReferenceArray();
AnalyticalModel analyticalModel = wallTemp.GetAnalyticalModel();
IList<Curve> activeCurveList =
foreach (Curve aCurve in activeCurveList)
// find non-vertical curve from analytical model
if (aCurve.GetEndPoint(0).Z ==
newLine = aCurve as Line;
if (aCurve.GetEndPoint(0).Z !=
AnalyticalModelSelector amSelector =
if (2 == referenceArray.Size)
if (referenceArray.Size != 2)
m_errorMessage += "Did not find two references";
//try to add new a dimension
Autodesk.Revit.UI.UIApplication app =
Document doc = app.ActiveUIDocument.Document;
Autodesk.Revit.DB.XYZ p1 = new XYZ(
newLine.get_EndPoint(0).X + 5,
newLine.get_EndPoint(0).Y + 5,
Autodesk.Revit.DB.XYZ p2 = new XYZ(
newLine.get_EndPoint(1).X + 5,
newLine.get_EndPoint(1).Y + 5,
Line newLine2 = app.Application.Create.
NewLine(p1, p2, true);
Dimension newDimension = doc.Create.NewDimension(
doc.ActiveView, newLine2, referenceArray);
// catch the exceptions
catch (Exception ex)
m_errorMessage += ex.ToString();
Please do not confused with this sample. You can create dimension for elements not in the analytical model, of course. The most difficult part is to find geometry references which you want to attach the dimension. Thanks to Jeremy that his API blogs introduce how to find geometry references with some typical use cases.
Please note that currently geometry references can not be found in symbolic lines using API while they can be dimensioned using UI.