New annotations such as Dimensions and ModelText and TextNote objects can also be created in families, as well as curve annotation elements such as SymbolicCurve, ModelCurve, and DetailCurve. See Annotation Elements for more information on Annotation elements.
Additionally, a new Alignment can be added, referencing a View that determines the orientation of the alignment, and two geometry references.
The following example demonstrates how to create a new arc length Dimension.
Code Region: Creating a Dimension |
public Dimension CreateArcDimension(Document document, SketchPlane sketchPlane) { Autodesk.Revit.Creation.Application appCreate = document.Application.Create; Line gLine1 = Line.CreateBound(new XYZ(0, 2, 0), new XYZ(2, 2, 0)); Line gLine2 = Line.CreateBound(new XYZ(0, 2, 0), new XYZ(2, 4, 0)); Arc arctoDim = Arc.Create(new XYZ(1, 2, 0), new XYZ(-1, 2, 0), new XYZ(0, 3, 0)); Arc arcofDim = Arc.Create(new XYZ(0, 3, 0), new XYZ(1, 2, 0), new XYZ(0.8, 2.8, 0)); Autodesk.Revit.Creation.FamilyItemFactory creationFamily = document.FamilyCreate; ModelCurve modelCurve1 = creationFamily.NewModelCurve(gLine1, sketchPlane); ModelCurve modelCurve2 = creationFamily.NewModelCurve(gLine2, sketchPlane); ModelCurve modelCurve3 = creationFamily.NewModelCurve(arctoDim, sketchPlane); //get their reference Reference ref1 = modelCurve1.GeometryCurve.Reference; Reference ref2 = modelCurve2.GeometryCurve.Reference; Reference arcRef = modelCurve3.GeometryCurve.Reference; Dimension newArcDim = creationFamily.NewArcLengthDimension(document.ActiveView, arcofDim, arcRef, ref1, ref2); if (newArcDim == null) { throw new Exception("Failed to create new arc length dimension."); } return newArcDim; } |
Figure 51: Resulting arc length dimension
Some types of dimensions can be labeled with a FamilyParameter. Dimensions that cannot be labeled will throw an Autodesk.Revit.Exceptions.InvalidOperationException if you try to get or set the Label property. In the following example, a new linear dimension is created between two lines and labeled as "width".
Code Region: Labeling a dimension |
public Dimension CreateLinearDimension(Document document) { // first create two lines XYZ pt1 = new XYZ(5, 5, 0); XYZ pt2 = new XYZ(5, 10, 0); Line line = Line.CreateBound(pt1, pt2); Plane plane = Plane.CreateByNormalAndOrigin(pt1.CrossProduct(pt2), pt2); SketchPlane skplane = SketchPlane.Create (document, plane); ModelCurve modelcurve1 = document.FamilyCreate.NewModelCurve(line, skplane); pt1 = new XYZ(10, 5, 0); pt2 = new XYZ(10, 10, 0); line = Line.CreateBound(pt1, pt2); plane = Plane.CreateByNormalAndOrigin(pt1.CrossProduct(pt2), pt2); skplane = SketchPlane.Create (document, plane); ModelCurve modelcurve2 = document.FamilyCreate.NewModelCurve(line, skplane); // now create a linear dimension between them ReferenceArray ra = new ReferenceArray(); ra.Append(modelcurve1.GeometryCurve.Reference); ra.Append(modelcurve2.GeometryCurve.Reference); pt1 = new XYZ(5, 10, 0); pt2 = new XYZ(10, 10, 0); line = Line.CreateBound(pt1, pt2); Dimension dim = document.FamilyCreate.NewLinearDimension(document.ActiveView, line, ra); // create a label for the dimension called "width" FamilyParameter param = document.FamilyManager.AddParameter("width", BuiltInParameterGroup.PG_CONSTRAINTS, ParameterType.Length, false); dim.FamilyLabel = param; return dim; } |
Figure 52: Labeled linear dimension