A reference point is an element that specifies a location in the XYZ work space of the conceptual design environment. You create reference points to design and plot lines, splines, and forms. A ReferencePoint can be added to a ReferencePointArray, then used to create a CurveByPoints, which in turn can be used to create a form.
The following example demonstrates how to create a CurveByPoints object. See the "Creating a loft form" example in the next section to see how to create a form from multiple CurveByPoints objects.
Code Region 14-1: Creating a new CurveByPoints |
ReferencePointArray rpa = new ReferencePointArray(); XYZ xyz = document.Application.Create.NewXYZ(0, 0, 0); ReferencePoint rp = document.FamilyCreate.NewReferencePoint(xyz); rpa.Append(rp); xyz = document.Application.Create.NewXYZ(0, 30, 10); rp = document.FamilyCreate.NewReferencePoint(xyz); rpa.Append(rp); xyz = document.Application.Create.NewXYZ(0, 60, 0); rp = document.FamilyCreate.NewReferencePoint(xyz); rpa.Append(rp); xyz = document.Application.Create.NewXYZ(0, 100, 30); rp = document.FamilyCreate.NewReferencePoint(xyz); rpa.Append(rp); xyz = document.Application.Create.NewXYZ(0, 150, 0); rp = document.FamilyCreate.NewReferencePoint(xyz); rpa.Append(rp); CurveByPoints curve = document.FamilyCreate.NewCurveByPoints(rpa); |
Figure 54: CurveByPoints curve
Reference points can be created based on XYZ coordinates as in the example above, or they can be created relative to other geometry so that the points will move when the referenced geometry changes. These points are created using the subclasses of the PointElementReference class. The subclasses are:
For example, the last two lines of code in the previous example create a reference point in the middle of the CurveByPoints.
Forms can be created using model lines or reference lines. Model lines are "consumed" by the form during creation and no longer exist as separate entities. Reference lines, on the other hand, persist after the form is created and can alter the form if they are moved. Although the API does not have a ReferenceLine class, you can change a model line to a reference line using the ModelCurve.ChangeToReferenceLine() method.
Code Region 14-2: Using Reference Lines to create Form |
private FormArray CreateRevolveForm(Document document) { FormArray revolveForms = null; // Create one profile ReferenceArray ref_ar = new ReferenceArray(); XYZ ptA = new XYZ(0, 0, 10); XYZ ptB = new XYZ(100, 0, 10); Line line = Line.CreateBound(ptA, ptB); ModelCurve modelcurve = MakeLine(document, ptA, ptB); ref_ar.Append(modelcurve.GeometryCurve.Reference); ptA = new XYZ(100, 0, 10); ptB = new XYZ(100, 100, 10); modelcurve = MakeLine(document, ptA, ptB); ref_ar.Append(modelcurve.GeometryCurve.Reference); ptA = new XYZ(100, 100, 10); ptB = new XYZ(0, 0, 10); modelcurve = MakeLine(document, ptA, ptB); ref_ar.Append(modelcurve.GeometryCurve.Reference); // Create axis for revolve form ptA = new XYZ(-5, 0, 10); ptB = new XYZ(-5, 10, 10); ModelCurve axis = MakeLine(document, ptA, ptB); // make axis a Reference Line axis.ChangeToReferenceLine(); // Typically this operation produces only a single form, // but some combinations of arguments will create multiple froms from a single profile. revolveForms = document.FamilyCreate.NewRevolveForms(true, ref_ar, axis.GeometryCurve.Reference, 0, Math.PI / 4); return revolveForms; } public ModelCurve MakeLine(Document doc, XYZ ptA, XYZ ptB) { Autodesk.Revit.ApplicationServices.Application app = doc.Application; // Create plane by the points Line line = Line.CreateBound(ptA, ptB); XYZ norm = ptA.CrossProduct(ptB); if (norm.IsZeroLength()) norm = XYZ.BasisZ; Plane plane = app.Create.NewPlane(norm, ptB); SketchPlane skplane = SketchPlane.Create(doc, plane); // Create line here ModelCurve modelcurve = doc.FamilyCreate.NewModelCurve(line, skplane); return modelcurve; } |
Figure 55: Resulting Revolve Form