You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Revit API创建指定偏移量屋顶的问题求助

如何通过Revit API创建带不同底部偏移的相邻屋顶

我尝试用Revit API创建如下屋顶:选中的屋顶底部偏移量为10英尺1英寸,相邻屋顶的底部偏移量为9英尺1英寸。

目标效果示意图:
目标屋顶效果

但目前用API得到的输出是这样的:
当前API输出效果

我们仅使用Revit文档中的模型线来创建,模型线如下:
用于创建屋顶的模型线


核心解决思路

问题出在没有为屋顶的不同边界单独设置底部偏移值。Revit API创建迹线屋顶(FootPrintRoof)时,需针对每个轮廓边对应的RoofBoundaryType对象单独配置偏移,而非给整个屋顶设置统一参数。

具体实现步骤及代码示例

以下是C#版本的Revit API实现代码,关键逻辑为识别不同轮廓边并设置对应偏移:

using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using System.Collections.Generic;
using System.Linq;

public void CreateOffsetRoofs(UIDocument uidoc)
{
    Document doc = uidoc.Document;
    
    // 1. 获取选中的模型线并转换为屋顶轮廓曲线
    ICollection<ElementId> selectedIds = uidoc.Selection.GetElementIds();
    List<Curve> profileCurves = new List<Curve>();
    foreach (ElementId id in selectedIds)
    {
        if (doc.GetElement(id) is ModelLine modelLine)
        {
            profileCurves.Add(modelLine.GeometryCurve);
        }
    }
    CurveLoop roofProfile = CurveLoop.Create(profileCurves);

    // 2. 获取目标屋顶类型和标高(需根据项目实际名称修改)
    RoofType targetRoofType = new FilteredElementCollector(doc)
        .OfClass(typeof(RoofType))
        .Cast<RoofType>()
        .FirstOrDefault(t => t.Name.Equals("Basic Roof"));
    
    Level targetLevel = new FilteredElementCollector(doc)
        .OfClass(typeof(Level))
        .Cast<Level>()
        .FirstOrDefault(l => l.Name.Equals("Level 1"));

    // 3. 事务内创建屋顶并设置边界偏移
    using (Transaction trans = new Transaction(doc, "创建带偏移的屋顶"))
    {
        trans.Start();
        
        ModelCurveArray roofBoundaryCurves = doc.Create.NewFootPrintRoof(roofProfile, targetLevel, targetRoofType);
        
        // 遍历边界曲线,为不同边设置对应偏移(单位:英尺,10'1"≈10.0833,9'1"≈9.0833)
        foreach (ModelCurve curve in roofBoundaryCurves)
        {
            RoofBoundaryType boundary = curve.GetRoofBoundaryType();
            // 此处需根据实际模型线特征(如坐标、ID)区分偏移规则,示例中仅做逻辑演示
            if (curve.Id.IntegerValue % 2 == 0) // 示例条件:根据曲线ID奇偶区分
            {
                boundary.set_Parameter(BuiltInParameter.ROOF_BOTTOM_OFFSET, 10.0833);
            }
            else
            {
                boundary.set_Parameter(BuiltInParameter.ROOF_BOTTOM_OFFSET, 9.0833);
            }
        }
        
        trans.Commit();
    }
}

注意事项

  1. 单位转换:Revit API长度参数默认以英尺为单位,需将英寸转换为英尺(1英寸=1/12英尺)。
  2. 边界识别逻辑:示例中用曲线ID奇偶性区分偏移,实际需根据你的模型线位置、长度或标记属性调整判断条件,确保对应边设置正确的偏移值。
  3. 轮廓有效性:确保模型线组成的轮廓是闭合、无交叉的,否则无法创建有效屋顶。

内容的提问来源于stack exchange,提问作者user16918900

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.18 03:52:38