Revit二次开发之创建倾斜楼板(Create a slope floor / slab)

一、函数

链接: 官方文档地址.

/*使用给定的水平轮廓创建默认样式楼板。*/
public Floor NewSlab(
	CurveArray profile,//斜板水平投影轮廓
	Level level,//水平投影标高
	Line slopedArrow,//倾斜轴,即水平投影与斜边相交的边
	double slope,//倾斜角度
	bool isStructural//是否结构
)

二、图示

在这里插入图片描述

三、代码

 public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
         try {
             UIDocument uiDoc = commandData.Application.ActiveUIDocument;
             Document doc = uiDoc.Document;
             Selection sel = uiDoc.Selection;
             Autodesk.Revit.Creation.Application acreation = commandData.Application.Application.Create;
             Autodesk.Revit.Creation.Document dcreation = doc.Create;

             Transaction ts = new Transaction(doc, "www");
             ts.Start();

             
             double h = 7;//斜板较高一端与斜板较低一端的高度差
             double l = 5;//斜板水平投影长度
             double w = 10;//斜板水平投影宽度

             double x0 = 0;
             double y0 = 0;
             double z0 = 1;

             XYZ p_s0 = new XYZ(x0, y0, z0);
             XYZ p_s1 = new XYZ(x0, y0 + w, z0);
             XYZ p_s2 = new XYZ(x0 + l, y0 + w, z0);
             XYZ p_s3 = new XYZ(x0 + l, y0, z0);
             
             Line l_s0 = Line.CreateBound(p_s0, p_s1);
             Line l_s1 = Line.CreateBound(p_s1, p_s2);
             Line l_s2 = Line.CreateBound(p_s2, p_s3);
             Line l_s3 = Line.CreateBound(p_s3, p_s0);

             CurveArray fProfile = new CurveArray();
             fProfile.Append(l_s0);
             fProfile.Append(l_s1);
             fProfile.Append(l_s2);
             fProfile.Append(l_s3);

             var levelCollector = new FilteredElementCollector(doc).OfClass(typeof(Level));
             var slablevel = levelCollector.FirstOrDefault(e => e.Name == "斜板标高") as Level;
             if (slablevel == null) {
                 slablevel = Level.Create(doc, z0);
                 slablevel.Name = "斜板标高";
             } else slablevel.Elevation = z0;


            
             Line slopeLine = l_s0;//斜板与其投影面相交的线
             double slope = Math.Atan(h / w);//斜板的角度
             var slopeSlab = dcreation.NewSlab(fProfile, slablevel, slopeLine, slope, true);
             ts.Commit();

             return Result.Succeeded;
         } catch (Exception ex) {
             var r = 0;
             return Result.Succeeded;

         }

}
  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
### 回答1: 我们可以使用 Revit API 来创建楼板。下面是一个示例代码:// 创建一个新的楼板 Floor floor = Floor.Create(doc, lineArray); // 设置楼板的高度 floor.get_Parameter(BuiltInParameter.FLOOR_HEIGH_PARAM).Set(10); // 设置楼板的类型 floor.get_Parameter(BuiltInParameter.FLOOR_ATTR_THICKNESS_PARAM).Set(floorType.Id); ### 回答2: Revit二次开发是指在Revit软件的基础上,使用API(Application Programming Interface)进行编程,以创建自定义功能、定制工具和插件。以下是展示Revit二次开发创建楼板的示例代码: ```csharp using Autodesk.Revit.UI; using Autodesk.Revit.DB; using Autodesk.Revit.Attributes; [Transaction(TransactionMode.Manual)] public class CreateFloorCommand : IExternalCommand { public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { // 获取Revit文档 Document doc = commandData.Application.ActiveUIDocument.Document; // 获取楼层板类型 ElementId floorTypeId = null; FilteredElementCollector floorTypeCollector = new FilteredElementCollector(doc) .OfClass(typeof(FloorType)); foreach (FloorType floorType in floorTypeCollector) { if (floorType.Name == "楼板类型名称") { floorTypeId = floorType.Id; break; } } if (floorTypeId != null) { // 获取楼层高度 double floorHeight = 3000; // 楼层高度为3000毫米 // 获取边界线 Line floorBoundaryLine = Line.CreateBound(new XYZ(0, 0, 0), new XYZ(5000, 0, 0)); CurveArray floorBoundary = new CurveArray(); floorBoundary.Append(floorBoundaryLine); // 创建楼板 using(Transaction trans = new Transaction(doc, "创建楼板")) { trans.Start(); Floor floor = doc.Create.NewFloor(floorBoundary, false); floor.get_Parameter(BuiltInParameter.FLOOR_HEIGHTABOVELEVEL_PARAM) .Set(floorHeight); floor.FloorType = doc.GetElement(floorTypeId) as FloorType; trans.Commit(); } return Result.Succeeded; } else { message = "找不到指定的楼板类型"; return Result.Failed; } } } ``` 以上代码使用了Revit API中的相关类和方法,通过获取Revit文档,楼板类型,楼层高度和边界线等信息,创建了一个自定义的楼板。需要替换代码中的`楼板类型名称`为实际楼板类型的名称,在使用该代码之前,请确保已经正确安装并配置了Revit API开发环境。 ### 回答3: Revit二次开发创建楼板的代码如下: 首先,我们需要导入Revit API的命名空间,包括`Autodesk.Revit.DB`和`Autodesk.Revit.UI`。 然后,创建一个继承自`IExternalCommand`接口的类,以便我们可以在Revit中运行这个命令。我们将命令命名为"CreateFloor"。 在类中,我们需要实现`Execute`方法,该方法将在运行命令时被调用。在这个方法中,我们将创建楼板并将其添加到当前项目中。 以下是示例代码: ```csharp using Autodesk.Revit.DB; using Autodesk.Revit.UI; public class CreateFloor : IExternalCommand { public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { // 获取当前文档 Document doc = commandData.Application.ActiveUIDocument.Document; // 创建标高 Level level = new FilteredElementCollector(doc) .OfClass(typeof(Level)) .FirstOrDefault(e => e.Name.Equals("Level 1")) as Level; // 定义楼板的几何形状 CurveArray curveArray = new CurveArray(); XYZ p1 = new XYZ(0, 0, 0); XYZ p2 = new XYZ(10, 0, 0); XYZ p3 = new XYZ(10, 10, 0); XYZ p4 = new XYZ(0, 10, 0); Line line1 = Line.CreateBound(p1, p2); Line line2 = Line.CreateBound(p2, p3); Line line3 = Line.CreateBound(p3, p4); Line line4 = Line.CreateBound(p4, p1); curveArray.Append(line1); curveArray.Append(line2); curveArray.Append(line3); curveArray.Append(line4); // 创建楼板 using (Transaction transaction = new Transaction(doc, "Create Floor")) { transaction.Start(); Floor floor = doc.Create.NewFloor(curveArray, false); floor.get_Parameter(BuiltInParameter.FLOOR_HEIGHTABOVELEVEL_PARAM).Set(0); // 设置楼板高度 transaction.Commit(); } return Result.Succeeded; } } ``` 以上示例代码演示了如何使用Revit API创建楼板。我们首先获取当前文档,然后创建一个标高。接下来,我们定义了楼板的几何形状,最后创建楼板并将其添加到项目中。在事务中运行代码,以确保操作的完整性和一致性。 以上是简单的创建楼板代码示例,该代码仅供参考。在实际开发过程中,可能需要根据具体需求进行更多的参数设置和处理。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值