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)
{
continue;
}
//get location curve
Location location = wallTemp.Location;
LocationCurve locationline = location as LocationCurve;
if (null == locationline)
{
continue;
}
//New Line
Line newLine = null;
//get reference
ReferenceArray referenceArray = new ReferenceArray();
AnalyticalModel analyticalModel = wallTemp.GetAnalyticalModel();
IList<Curve> activeCurveList =
analyticalModel.GetCurves(
AnalyticalCurveType.ActiveCurves);
foreach (Curve aCurve in activeCurveList)
{
// find non-vertical curve from analytical model
if (aCurve.GetEndPoint(0).Z ==
aCurve.GetEndPoint(1).Z)
newLine = aCurve as Line;
if (aCurve.GetEndPoint(0).Z !=
aCurve.GetEndPoint(1).Z)
{
AnalyticalModelSelector amSelector =
new AnalyticalModelSelector(aCurve);
amSelector.CurveSelector =
AnalyticalCurveSelector.StartPoint;
referenceArray.Append(
analyticalModel.GetReference(amSelector));
}
if (2 == referenceArray.Size)
break;
}
if (referenceArray.Size != 2)
{
m_errorMessage += "Did not find two references";
return false;
}
try
{
//try to add new a dimension
Autodesk.Revit.UI.UIApplication app =
m_revit.Application;
Document doc = app.ActiveUIDocument.Document;
Autodesk.Revit.DB.XYZ p1 = new XYZ(
newLine.get_EndPoint(0).X + 5,
newLine.get_EndPoint(0).Y + 5,
newLine.get_EndPoint(0).Z);
Autodesk.Revit.DB.XYZ p2 = new XYZ(
newLine.get_EndPoint(1).X + 5,
newLine.get_EndPoint(1).Y + 5,
newLine.get_EndPoint(1).Z);
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();
return false;
}
}
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.
http://thebuildingcoder.typepad.com/blog/2011/02/dimension-walls-by-iterating-faces.html
http://thebuildingcoder.typepad.com/blog/2011/02/dimension-walls-using-findreferencesbydirection.html
Please note that currently geometry references can not be found in symbolic lines using API while they can be dimensioned using UI.