创建墙的方法有五个重载。方法和用途如下表:
方法 | 用途 |
public static Wall Create(Document document, IList<Curve> profile, bool structural); | 给定曲线和标高,使用默认墙类型创建墙 |
public static Wall Create(Document document, Curve curve, ElementId levelId, bool structural); | 给定墙的曲线形状,使用默认墙类型创建墙 |
public static Wall Create(Document document, IList<Curve> profile, ElementId wallTypeId, ElementId levelId, bool structural); | 给定墙的曲线形状,指定标高和墙类型, 而不是使用默认的墙类型 |
public static Wall Create(Document document, IList<Curve> profile, ElementId wallTypeId, ElementId levelId, bool structural, XYZ normal); | 与上面类似,增加一个参数normal可以指定墙的朝向 |
public static Wall Create(Document document, Curve curve, ElementId wallTypeId, ElementId levelId, double height, double offset, bool flip, bool structural); | 创建墙,并设置墙的高度(height参数),底部偏移 (offset参数),是否翻转(flip) |
一)、创建梯形墙
WallCreate(Document document,IList<Curve〉profile,bool structural) 这个函数,给定
墙的曲线形状,使用默认墙类型创建墙
IList<Curve>curves = new List<Curve>();
curves.Add(Line.CreateBound(newXYZ(100, 20, 0), new XYZ(100, -20, 0)));
curves.Add(Line.CreateBound(newXYZ(100, -20, 0), new XYZ(100, -10, 10)));
curves.Add(Line.CreateBound(newXYZ(100, -10, 10), new XYZ(100, 10, 10)));
curves.Add(Line.CreateBound(newXYZ(100, 10, 5), new XYZ(100, 20, 0)));
using(Transaction transaction = new Transaction(RevitDoc))
{
transaction.Start("Create wall");
Wall wall = Wall.Create(RevitDoc, curves,false);
transaction.Commit();
}
注意:
•曲线形状是墙的正面,即创建的是一面墙,而不是创建一系列的墙。
•形状是必须闭合的,否则抛异常,创建失败。
•无法创建斜的墙。
二)、创建带正反面的墙
public static Wall Create(Documentdocument, IList<Curve> profile, ElementId wallTypeId, ElementId levelId,bool structural, XYZ normal);
参数 normal可以指定墙的朝向。如果创建的墙的朝向不符合要求,可以使用Wall.Flip()实例方法来调整墙的朝向。
ElementId levelId = new ElementId(311);
ElementId wallTypeId = new ElementId(397);
IList<Curve> curves = newList<Curve>();
// 创建墙
XYZ[] vertexes = new XYZ[] { new XYZ(0, 0,0), new XYZ(0, 100, 0), new XYZ(0, 0, 100) };
for (int ii = 0; ii < vertexes.Length;ii++)
{
if(ii != vertexes.Length - 1)
curves.Add(Line.CreateBound(vertexes[ii], vertexes[ii + 1]));
else
curves.Add(Line.CreateBound(vertexes[ii], vertexes[0]));
}
Wall wall = null;
using (Transaction transaction = newTransaction(RevitDoc))
{
transaction.Start("Create wall 1");
wall = Wall.Create(RevitDoc, curves, wallTypeId, levelId, false, newXYZ(-1, 0, 0));
transaction.Commit();
}
// 创建第二面墙,朝向相反
curves.Clear();
vertexes = new XYZ[] { new XYZ(0, 0, 100),new XYZ(0, 100, 100), new XYZ(0, 100, 0) };
for (int ii = 0; ii < vertexes.Length;ii++)
{
if(ii != vertexes.Length - 1)
curves.Add(Line.CreateBound(vertexes[ii], vertexes[ii + 1]));
else
curves.Add(Line.CreateBound(vertexes[ii], vertexes[0]));
}
using (Transaction transaction = newTransaction(RevitDoc))
{
transaction.Start("Create wall 2");
wall = Wall.Create(RevitDoc, curves, wallTypeId, levelId, false, newXYZ(1, 0, 0));
transaction.Commit();
}
=========【更多高级应用请关注公众号】========
===================================