Curves are often needed as inputs to Revit API methods. They can be created a number of ways.
Curves have a number of derived types with static methods for curve creation. The base Curve class also has methods for creating new Curves from existing curves.
Curve creation methods prevent creation of curves that are shorter than Revit's tolerance. This tolerance is exposed through the Application.ShortCurveTolerance property.
The Curve class has several methods for creating new curves from existing curves.
There are two static methods for creating a new Line.
Code Region: Create an unbound linear curve |
// define start point and direction for unbound line XYZ startPoint = new XYZ(0, 0, 0); XYZ directionPt = new XYZ(10, 10, 10); // create line Line line = Line.CreateUnbound(startPoint, directionPt); |
The overloaded static Create() method allows for an Arc to be created in one of three ways:
Code Region: Create arc with 3 points |
// Create a new arc using two ends and a point on the curve XYZ end0 = new XYZ(1, 0, 0); // start point of the arc XYZ end1 = new XYZ(10, 10, 10); // end point of the arc XYZ pointOnCurve = new XYZ(10, 0, 0); // point along arc Arc arc = Arc.Create(end0, end1, pointOnCurve); |
Code Region: Create arc with plane |
Arc CreateArcByGivingPlane(Autodesk.Revit.ApplicationServices.Application application, Plane plane) { // Create an arc which is placed on the plane and whose center is the plane's origin double radius = 10; double startAngle = 0; // The unit is radian double endAngle = 2 * Math.PI; // this arc will be a circle return Arc.Create(plane, radius, startAngle, endAngle); } |
Code Region: Create arc with axes |
// Create a new arc defined by its center, radios, angles and 2 axes double radius = 10; double startAngle = 0; // In radian double endAngle = Math.PI; // In radian XYZ center = new XYZ(5, 0, 0); XYZ xAxis = new XYZ(1, 0, 0); // The x axis to define the arc plane. Must be normalized XYZ yAxis = new XYZ(0, 1, 0); // The y axis to define the arc plane. Must be normalized Arc arc = Arc.Create(center, radius, startAngle, endAngle, xAxis, yAxis); |
Note for the latter two options, if the angle range is equal to or greater than 2 * PI, the curve will be automatically converted to an unbounded circle.
The static Create() method creates an Ellipse given the center, the x vector and y vector radii of the ellipse, the x and y axes to define the plane of the ellipse and the start and end parameters. Depending on the values, this will create an ellipse or an elliptical arc.
The static Create() method of CylindricalHelix creates a new CylindricalHelix from the base point of the axis, a radius, x vector, z vector, pitch, a start angle to specify the start point of the helix and an end angle to specify the end point of the helix. The z vector is the axis direction and should be perpendicular to the x vector. A positive pitch yields a right-handed helix while a negative pitch yields a left-handed helix.
The NurbSpline class represents a NURBS, or Non-Uniform Rational B-Spline, curve. The overloaded static Create() method offers two ways to create a NURBS curve. The first way is using the same calculations that Revit uses when sketching splines in the user interface. It takes a list of control points and weights to create a new NurbSpline. Knots and degree of the spline are computed from the given control points and weights.
The second option also requires a list of control points and weights, but also a list of knots as well as the degree of the NurbSpline. Two additional parameters indicate whether the NurbSpline is closed or open, and whether or not it is rational. The degree must be 3 or greater. If rational, the control points and weights array must be the same size. There must be at least degree+1 control points. The size of knots must equal the sum of degree, the size of the control points array and 1. The first degree+1 knots should be identical, as should the last degree+1 knots. The knots in the middle of the sequence must be non-decreasing.
The overloaded static HermiteSpline.Create() method provides two options for creating Hermite splines. The simplest way creates a Hermite spline with default tangency at its endpoints and requires only a list of control points and a flag indicating whether or not the Hermite spline is periodic. The second option creates a Hermite spline with specified tangency at its endpoints. It has an additional parameter of a HermiteSplineTangents object to specify the tangents at the start and/or end of the curve.