How to add your knowledge

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 = application.Create.NewLine(startPoint, endPoint, true);
    
    // 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 = application.Create.NewArc(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 = application.Create.NewPlane(normal, origin);
    
    // Create a sketch plane in current document
    SketchPlane sketch = document.Create.NewSketchPlane(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;
    

    Properties

    ModelCurve has properties that help you set specific GeometryCurves. In this section, the GeometryCurve and LineStyle properties are introduced.

    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;

    • Line
    • Arc
    • Ellipse
    • Nurbspline.

    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.

    NoteThe 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.

    LineStyle

    Line style does not have a specific class but is represented by the Document.Element class.

    • All line styles for a ModelCurve are available from the LineStyles property in the Element Properties dialog box.
    • The Element object that represents line style cannot provide information for all properties. Most properties will return null or an empty collection.
    • The only information returned is the following:
      • Id
      • UniqueId
      • Name.
    • Use the getLineStyle() method to retrieve the current line style or use the setLineStyle() method to set the current line style to one returned from the LineStyles property.