【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);
}
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

孤影墨客

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值