ModelCurve

ModelCurve represents model lines in the project. It exists in 3D space and is visible in all views.

The following pictures illustrate the four ModelCurve derived classes:

Figure 92:ModelLine and ModelArc

Figure 93: ModelEllipse and ModelNurbSpline

Creating a ModelCurve

The key to creating a ModelCurve is to create the Geometry.Curve and SketchPlane where the Curve is located. Based on the Geometry.Curve type you input, the corresponding ModelCurve returned can be downcast to its correct type.

The following sample illustrates how to create a new model curve (ModelLine and ModelArc):

Code Region 17-2: Creating a new model curve
// get handle to application from document
Autodesk.Revit.ApplicationServices.Application application = document.Application;

// Create a geometry line in Revit application
XYZ startPoint = new XYZ(0, 0, 0);
XYZ endPoint = new XYZ(10, 10, 0);
Line geomLine = Line.CreateBound(startPoint, endPoint);

// Create a geometry arc in Revit application
XYZ end0 = new XYZ(1, 0, 0);
XYZ end1 = new XYZ(10, 10, 10);
XYZ pointOnCurve = new XYZ(10, 0, 0);
Arc geomArc = Arc.Create(end0, end1, pointOnCurve);

// Create a geometry plane in Revit application
XYZ origin = new XYZ(0, 0, 0);
XYZ normal = new XYZ(1, 1, 0);
Plane geomPlane = Plane.CreateByNormalAndOrigin(normal, origin);

// Create a sketch plane in current document
SketchPlane sketch = SketchPlane.Create(document, geomPlane);

// Create a ModelLine element using the created geometry line and sketch plane
ModelLine line = document.Create.NewModelCurve(geomLine, sketch) as ModelLine;

// Create a ModelArc element using the created geometry arc and sketch plane
ModelArc arc = document.Create.NewModelCurve(geomArc, sketch) as ModelArc;

Members

GeometryCurve

The GeometryCurve property is used to get or set the model curve's geometry curve. Except for ModelHermiteSpline, you can get different Geometry.Curves from the four ModelCurves;

The following code sample illustrates how to get a specific Curve from a ModelCurve.

Code Region 17-3: Getting a specific Curve from a ModelCurve
//get the geometry modelCurve of the model modelCurve
Autodesk.Revit.DB.Curve geoCurve = modelCurve.GeometryCurve;

if (geoCurve is Autodesk.Revit.DB.Line)
{
        Line geoLine = geoCurve as Line;
}
The GeometryCurve property return value is a general Geometry.Curve object, therefore, you must use an As operator to convert the object type.

Note: The following information applies to GeometryCurve:
  • In Revit you cannot create a Hermite curve but you can import it from other software such as AutoCAD. Geometry.Curve is the only geometry class that represents the Hermite curve.
  • The SetPlaneAndCurve() method and the Curve and SketchPlane property setters are used in different situations.
    • When the new Curve lies in the same SketchPlane, or the new SketchPlane lies on the same planar face with the old SketchPlane, use the Curve or SketchPlane property setters.
    • If new Curve does not lay in the same SketchPlane, or the new SketchPlane does not lay on the same planar face with the old SketchPlane, you must simultaneously change the Curve value and the SketchPlane value using SetPlaneAndCurve() to avoid internal data inconsistency.

      Line Styles

Line styles are represented by the GraphicsStyle class. All line styles for a ModelCurve are available from the GetLineStyleIds() method which returns a set of ElementIds of GraphicsStyle elements.