创建点的位置线
private void PointNewModelLineXYZ(Document RevitDoc, XYZ point)
{
XYZ startpoint1 = new XYZ(point.X, point.Y, point.Z);
XYZ endpoint1 = new XYZ(point.X + 10, point.Y, point.Z);
XYZ startpoint2 = new XYZ(point.X, point.Y, point.Z);
XYZ endpoint2 = new XYZ(point.X, point.Y + 10, point.Z);
XYZ startpoint3 = new XYZ(point.X, point.Y, point.Z);
XYZ endpoint3 = new XYZ(point.X, point.Y, point.Z + 10);
using (Transaction transaction = new Transaction(RevitDoc))
{
transaction.Start("Create Model Line");
//创建sketchPlane
SketchPlane modelSketch1 = SketchPlane.Create(RevitDoc, Plane.CreateByNormalAndOrigin(XYZ.BasisZ, point));
SketchPlane modelSketch2 = SketchPlane.Create(RevitDoc, Plane.CreateByNormalAndOrigin(XYZ.BasisZ, point));
SketchPlane modelSketch3 = SketchPlane.Create(RevitDoc, Plane.CreateByNormalAndOrigin(XYZ.BasisX, point));
//创建线
Line Line1 = Line.CreateBound(startpoint1, endpoint1);
Line Line2 = Line.CreateBound(startpoint2, endpoint2);
Line Line3 = Line.CreateBound(startpoint3, endpoint3);
//创建模型线
RevitDoc.Create.NewModelCurve(Line1, modelSketch1);
RevitDoc.Create.NewModelCurve(Line2, modelSketch2);
RevitDoc.Create.NewModelCurve(Line3, modelSketch3);
transaction.Commit();
}
}
创建平面四周的线
private void FaceNewModelLine(Document RevitDoc, PlanarFace face)
//根据PlanarFace创建平面模型线
{
foreach (EdgeArray e in face.EdgeLoops)
{
foreach (Edge e2 in e)
{
Curve line = e2.AsCurve();
using (Transaction transaction = new Transaction(RevitDoc))
{
transaction.Start("Create Model Line");
//创建sketchPlane
Plane plane = (face.GetSurface())as Plane;//这里不要使用face.Reference,会出现错误,错误提示是不在曲线不在一个平面上
SketchPlane modelSketch = SketchPlane.Create(RevitDoc, plane);
//SketchPlane modelSketch = SketchPlane.Create(RevitDoc, face.Reference);
//创建模型线
RevitDoc.Create.NewModelCurve(line, modelSketch);
transaction.Commit();
}
}
}
}
创建LocationCurve的模型线
private void LineNewModelLineXYZ(Document RevitDoc, LocationCurve locationCurve)
//根据获取的位置线创建模型线,只允许在XY的平面中创建,平行于XY平面
{
XYZ point1 = (locationCurve.Curve as Line).Direction;
XYZ point2 = (locationCurve.Curve as Line).Origin;
using (Transaction transaction = new Transaction(RevitDoc))
{
transaction.Start("Create Model Line");
//创建sketchPlane
SketchPlane modelSketch = SketchPlane.Create(RevitDoc, Plane.CreateByNormalAndOrigin(XYZ.BasisZ, point2));
//原点加上Z轴的向量就可以创建一个平面
//创建线
Line line = locationCurve.Curve as Line;
//创建模型线
RevitDoc.Create.NewModelCurve(line, modelSketch);
transaction.Commit();
}
}