internal class Class5 : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
Document revitDoc = commandData.Application.ActiveUIDocument.Document;
ReferenceArrayArray raa = new ReferenceArrayArray();
ReferenceArray ra = new ReferenceArray();
int y = 100;
int x = 50;
XYZ ptA = new XYZ(-x, y, 0);
XYZ ptB = new XYZ(x, y, 0);
XYZ ptC = new XYZ(0, y + 10, 10);
using (Transaction tr = new Transaction(revitDoc, "tl"))
{
tr.Start();
ModelCurve modelCurve = FormUtils.MakeArc(revitDoc, ptA, ptB, ptC);
ra.Append(modelCurve.GeometryCurve.Reference);
raa.Append(ra);
ra = new ReferenceArray();
y = 40;
ptA = new XYZ(-x, y, 5);
ptB = new XYZ(x, y, 5);
ptC = new XYZ(0, y, 25);
modelCurve = FormUtils.MakeArc(revitDoc, ptA, ptB, ptC);
ra.Append(modelCurve.GeometryCurve.Reference);
raa.Append(ra);
ra = new ReferenceArray();
y = -20;
ptA = new XYZ(-x, y, 0);
ptB = new XYZ(x, y, 0);
ptC = new XYZ(0, y, 15);
modelCurve = FormUtils.MakeArc(revitDoc, ptA, ptB, ptC);
ra.Append(modelCurve.GeometryCurve.Reference);
raa.Append(ra);
ra = new ReferenceArray();
y = -60;
ptA = new XYZ(-x, y, 0);
ptB = new XYZ(x, y, 0);
ptC = new XYZ(0, y+10, 20);
modelCurve = FormUtils.MakeArc(revitDoc, ptA, ptB, ptC);
ra.Append(modelCurve.GeometryCurve.Reference);
raa.Append(ra);
ra = new ReferenceArray();
raa.Append(ra);
Form form = revitDoc.FamilyCreate.NewLoftForm(true, raa);
tr.Commit();
}
return Result.Succeeded;
}
}
class FormUtils
{
public static ModelCurve MakeArc(Document document, XYZ ptA, XYZ ptB, XYZ ptC)
{
Arc arc = Arc.Create(ptA, ptB, ptC);
Line line1 = Line.CreateBound(ptA, ptB);
Line line2 = Line.CreateBound(ptB, ptC);
Line line3 = Line.CreateBound(ptC, ptA);
CurveLoop loop = new CurveLoop();
loop.Append(line1);
loop.Append(line2);
loop.Append(line3);
Plane plane = loop.GetPlane();
SketchPlane sketchPlane = SketchPlane.Create(document,plane);
ModelCurve modelCurve = document.FamilyCreate.NewModelCurve(arc, sketchPlane);
return modelCurve;
}
public static ModelCurve MakeLine(Document document, XYZ ptA, XYZ ptB)
{
Line line = Line.CreateBound(ptA, ptB);
XYZ norm = ptA.CrossProduct(ptB);
if (norm.GetLength() == 0) norm = XYZ.BasisZ;
Plane plane = Plane.CreateByNormalAndOrigin(norm, ptB);
SketchPlane skplane = SketchPlane.Create(document, plane);
ModelCurve modelcurve = document.FamilyCreate.NewModelCurve(line, skplane);
return modelcurve;
}
public static ModelCurve MakeLine(Document document, XYZ ptA, XYZ ptB, XYZ norm)
{
Line line = Line.CreateBound(ptA, ptB);
Plane plane = Plane.CreateByNormalAndOrigin(norm, ptB);
SketchPlane skplane = SketchPlane.Create(document, plane);
ModelCurve modelcurve = document.FamilyCreate.NewModelCurve(line, skplane);
return modelcurve;
}
}
07-25
5791
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)