【Revit二次开发】楼板、天花板、屋顶和洞口
介绍
Creates a slab within the project with the given horizontal profile using the default floor style.
public Floor NewSlab(
CurveArray profile,
Level level,
Line slopedArrow,
double slope,
bool isStructural
)
在Revit二次开发中,楼板、天花板、屋顶和洞口都是Revit中的构件类型,可以使用Revit API来创建、修改和删除这些构件。
楼板(Floor):在Revit中,楼板是由一个或多个边界定义的平面构件。可以使用Floor类来创建、修改和删除楼板。下面是一个创建楼板的示例:
// 创建一个新的楼板
Floor floor = doc.Create.NewFloor(profile, floorType, level, false);
其中,profile是一个CurveArray对象,表示楼板的边界,floorType是楼板类型,level是楼板所在的标高。
天花板(Ceiling):在Revit中,天花板是一个平面构件,它被放置在房间上方,可以用于隐藏房间的结构和设备。可以使用Ceiling类来创建、修改和删除天花板。下面是一个创建天花板的示例:
// 创建一个新的天花板
Ceiling ceiling = doc.Create.NewCeiling(level, profile, ceilingType);
其中,level是天花板所在的标高,profile是一个CurveArray对象,表示天花板的边界,ceilingType是天花板类型。
屋顶(Roof):在Revit中,屋顶是由一个或多个边界定义的斜面构件。可以使用FootPrintRoof类或ExtrusionRoof类来创建、修改和删除屋顶。下面是一个创建屋顶的示例:
// 创建一个新的足迹屋顶
FootPrintRoof roof = doc.Create.NewFootPrintRoof(profile, roofType, level, false);
其中,profile是一个CurveArray对象,表示屋顶的边界,roofType是屋顶类型,level是屋顶所在的标高。
洞口(Opening):在Revit中,洞口可以用于在墙、楼板等构件中创建一个洞,以便放置门、窗等构件。可以使用Opening类来创建、修改和删除洞口。下面是一个创建洞口的示例:
// 创建一个新的洞口
Opening opening = doc.Create.NewOpening(host, plane, true);
其中,host是包含洞口的构件,plane是洞口所在的平面。
这些示例只是Revit API中创建这些构件的一种方法,可以根据自己的需要选择不同的方法。另外,创建这些构件之前,需要先定义它们的类型、标高等信息。
代码
using Autodesk.Revit.DB.Structure;
using System.Collections.Generic;
namespace Autodesk.Revit.DB
{
public class Wall : HostObject
{
public CurtainGrid CurtainGrid { get; }
public WallType WallType { get; set; }
public double Width { get; }
public StructuralWallUsage StructuralUsage { get; set; }
public bool Flipped { get; }
public bool IsStackedWall { get; }
public bool IsStackedWallMember { get; }
public ElementId StackedWallOwnerId { get; }
public WallCrossSection CrossSection { get; set; }
public XYZ Orientation { get; }
public ElementId SketchId { get; }
public static Wall Create(Document document, Curve curve, ElementId levelId, bool structural);
public static Wall Create(Document document, IList<Curve> profile, 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);
public static Wall Create(Document document, Curve curve, ElementId wallTypeId, ElementId levelId, double height, double offset, bool flip, bool structural);
public bool CanHaveProfileSketch();
public Sketch CreateProfileSketch();
public void Flip();
public IList<ElementId> GetStackedWallMemberIds();
public bool IsWallCrossSectionValid(WallCrossSection wallCrossSection);
public void RemoveProfileSketch();
}
}
//============代码片段4-7 创建默认墙============
ElementId levelId = new ElementId(311);
using (Transaction transaction = new Transaction(RevitDoc))
{
transaction.Start("Create wall");
Wall wall = Wall.Create(RevitDoc, Line.CreateBound(new XYZ(0, 0, 0), new XYZ(100, 0, 0)), levelId, false);
transaction.Commit();
}
//============代码片段4-8 创建梯形墙============
IList<Curve> curves = new List<Curve>();
curves.Add(Line.CreateBound(new XYZ(100, 20, 0), new XYZ(100, -20, 0)));
curves.Add(Line.CreateBound(new XYZ(100, -20, 0), new XYZ(100, -10, 10)));
curves.Add(Line.CreateBound(new XYZ(100, -10, 10), new XYZ(100, 10, 10)));
curves.Add(Line.CreateBound(new XYZ(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();
}
//============代码片段4-9 创建正反两面墙============
ElementId levelId = new ElementId(311);
ElementId wallTypeId = new ElementId(397);
IList<Curve> curves = new List<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 = new Transaction(RevitDoc))
{
transaction.Start("Create wall 1");
wall = Wall.Create(RevitDoc, curves, wallTypeId, levelId, false, new XYZ(-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 = new Transaction(RevitDoc))
{
transaction.Start("Create wall 2");
wall = Wall.Create(RevitDoc, curves, wallTypeId, levelId, false, new XYZ(1, 0, 0));
transaction.Commit();
}
//============代码片段4-10 创建墙,并设置高度,偏移和是否翻转============
ElementId levelId = new ElementId(311);
ElementId wallTypeId = new ElementId(397);
using (Transaction transaction = new Transaction(RevitDoc))
{
transaction.Start("Create wall");
Wall wall = Wall.Create(RevitDoc, Line.CreateBound(new XYZ(0, 0, 0), new XYZ(0, 100, 0)), wallTypeId, levelId, 200, 300, true, false);
transaction.Commit();
}
//============代码片段4-11 创建三角形墙============
CurveArray curveArray = new CurveArray();
curveArray.Append(Line.CreateBound(new XYZ(0, 0, 0), new XYZ(100, 0, 0)));
curveArray.Append(Line.CreateBound(new XYZ(100, 0, 0), new XYZ(0, 100, 0)));
curveArray.Append(Line.CreateBound(new XYZ(0, 100, 0), new XYZ(0, 0, 0)));
using (Transaction transaction = new Transaction(RevitDoc))
{
transaction.Start("Create floor");
Floor floor = RevitDoc.Create.NewFloor(curveArray, false);
transaction.Commit();
}
//============代码片段4-12 创建屋顶============
using (Transaction transaction = new Transaction(RevitDoc))
{
View view = RevitDoc.ActiveView;
//先创建一个参照平面
XYZ bubbleEnd = new XYZ(0, 0, 0);
XYZ freeEnd = new XYZ(0, 100, 0);
XYZ thirdPnt = new XYZ(0, 0, 100);
transaction.Start("Create reference plane");
ReferencePlane plane =
RevitDoc.Create.NewReferencePlane2(bubbleEnd, freeEnd, thirdPnt, view);
transaction.Commit();
//创建屋顶前准备参数
Level level = RevitDoc.GetElement(new ElementId(311)) as Level;
RoofType roofType = RevitDoc.GetElement(new ElementId(335)) as RoofType;
CurveArray curveArray = new CurveArray();
curveArray.Append(Line.CreateBound(new XYZ(0, 0, 50), new XYZ(0, 50, 100)));
curveArray.Append(Line.CreateBound(new XYZ(0, 50, 100), new XYZ(0, 100, 50)));
//创建屋顶
transaction.Start("Create roof");
RevitDoc.Create.NewExtrusionRoof(curveArray, plane, level, roofType, 10, 200);
transaction.Commit();
}
//============代码片段4-13 创建带洞口屋顶============
using (Transaction transaction = new Transaction(RevitDoc))
{
//创建屋顶前准备参数
Level level = RevitDoc.GetElement(new ElementId(311)) as Level;
RoofType roofType = RevitDoc.GetElement(new ElementId(335)) as RoofType;
CurveArray curveArray = new CurveArray();
//屋顶外边框
curveArray.Append(Line.CreateBound(new XYZ(0, 0, 0), new XYZ(30, 0, 0)));
curveArray.Append(Line.CreateBound(new XYZ(30, 0, 0), new XYZ(30, 30, 0)));
curveArray.Append(Line.CreateBound(new XYZ(30, 30, 0), new XYZ(0, 30, 0)));
curveArray.Append(Line.CreateBound(new XYZ(0, 30, 0), new XYZ(0, 0, 0)));
//在中间添加洞口
curveArray.Append(Line.CreateBound(new XYZ(5, 5, 0), new XYZ(5, 15, 0)));
curveArray.Append(Line.CreateBound(new XYZ(5, 15, 0), new XYZ(15, 5, 0)));
curveArray.Append(Line.CreateBound(new XYZ(15, 5, 0), new XYZ(5, 5, 0)));
//创建屋顶
transaction.Start("Create roof");
ModelCurveArray modelCurveArray = new ModelCurveArray();
FootPrintRoof roof =
RevitDoc.Create.NewFootPrintRoof(curveArray, level, roofType, out modelCurveArray);
//设置屋顶坡度
ModelCurve curve1 = modelCurveArray.get_Item(0);
ModelCurve curve3 = modelCurveArray.get_Item(2);
roof.set_DefinesSlope(curve1, true);
roof.set_SlopeAngle(curve1, 0.5);
roof.set_DefinesSlope(curve3, true);
roof.set_SlopeAngle(curve3, 1.6);
transaction.Commit();
}
//============代码片段4-14 创建独立实例============
// place a furniture at (0,0,0)
FamilySymbol familySymbol = RevitDoc.GetElement(new ElementId(99774)) as FamilySymbol;
using (Transaction transaction = new Transaction(RevitDoc))
{
transaction.Start("Create standard-alone instance");
FamilyInstance familyInstance = m_creation.NewFamilyInstance(
new XYZ(0, 0, 0), familySymbol, StructuralType.NonStructural);
transaction.Commit();
Trace.WriteLine(familyInstance.Id);
}
//============代码片段4-15 墙上创建门============
// 在墙上创建一扇门
FamilySymbol familySymbol = RevitDoc.GetElement(new ElementId(49480)) as FamilySymbol;
Level level = RevitDoc.GetElement(new ElementId(30)) as Level;
Wall hostWall = RevitDoc.GetElement(new ElementId(180736)) as Wall;
using (Transaction transaction = new Transaction(RevitDoc))
{
transaction.Start("Create standard-alone instance");
FamilyInstance familyInstance = m_creation.NewFamilyInstance(
new XYZ(0, 0, 0), familySymbol, hostWall, level, StructuralType.NonStructural);
transaction.Commit();
Trace.WriteLine(familyInstance.Id);
}
//============代码片段4-16 创建柱子============
// place a column at (0,0,0),
FamilySymbol familySymbol = RevitDoc.GetElement(new ElementId(52557)) as FamilySymbol;
Level level = RevitDoc.GetElement(new ElementId(331)) as Level;
using (Transaction transaction = new Transaction(RevitDoc))
{
transaction.Start("Create a level based instance");
FamilyInstance familyInstance = m_creation.NewFamilyInstance(
new XYZ(0, 0, 0), familySymbol, level, StructuralType.NonStructural);
transaction.Commit();
Trace.WriteLine(familyInstance.Id);
}
本文来自博客园,作者:Patrick-Rex,转载请注明原文链接:https://www.cnblogs.com/patrickrex/p/18028759
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性
· 全网最简单!3分钟用满血DeepSeek R1开发一款AI智能客服,零代码轻松接入微信、公众号、小程
· .NET 10 首个预览版发布,跨平台开发与性能全面提升