惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园_首页
C
Check Point Blog
B
Blog RSS Feed
G
Google Developers Blog
H
Help Net Security
博客园 - Franky
Blog — PlanetScale
Blog — PlanetScale
H
Hackread – Cybersecurity News, Data Breaches, AI and More
量子位
Recent Announcements
Recent Announcements
B
Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
D
DataBreaches.Net
小众软件
小众软件
T
The Blog of Author Tim Ferriss
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
MongoDB | Blog
MongoDB | Blog
Y
Y Combinator Blog
T
Tailwind CSS Blog
J
Java Code Geeks
MyScale Blog
MyScale Blog
雷峰网
雷峰网
有赞技术团队
有赞技术团队
博客园 - 聂微东

博客园 - Albert_MIN

在 ASP.NET Core 中创建中间件的五种方式 在 ASP.NET Core MVC 中,接收数据的几种方式 Content-Type 对应不同的前端数据结构与构造方式 Revit二次开发 钢筋生成API(一) revit二次开发 钢筋布置方式 revit二次开发之 钢筋功能详细分析 revit 二次开发之收集器、过滤器和选择器 Revit Server的注意要配置说明 WCF文件配置服务 WCF服务的各种绑定 Revit二次开发之 对象的隐藏与显示 Revit二次开发之 GeometryObject分析 Revit二次开发之 Material 分析 Revit二次开发之 PolymeshTopology Revit 二次开发之 图纸的导出 Revit开发之 IExportContext接口详细 JavaScript 困惑之 ArrayBuffer JS 困惑之this的指向 Revit二次开发之 族的创建 Revit二次开发 钢筋生成 Revit二次开发之 尺寸标线(二) Revit二次开发之 尺寸标线
Revit二次开发 钢筋生成API(二)
Albert_MIN · 2025-09-17 · via 博客园 - Albert_MIN

2、自由钢筋生成API

创建一条无约束的自由形状钢筋。之后无法对该钢筋添加约束。

public static Rebar CreateFreeForm(
	Document doc,
	RebarBarType barType,
	Element host,
	IList<IList<Curve>> curves,
	out RebarFreeFormValidationResult error
)

这个合自由钢筋生成API(一)本质上没有区别,唯一的区别就是参数

IList<CurveLoop> curves 和IList<IList<Curve>> curves的不同。

这个就要看CurveLoop和IList<Curve>的区别。

  • CurveLoop:曲线循环的集合,通常用于定义建筑模型的几何边界或路径,默认会把首位相连
  • IList<Curve>:可以定义一个有多个线段组成的整线,比较适合各种形状的钢筋。

此函数的案例如下:

using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Structure;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using System;
using System.Collections.Generic;

namespace RebarExample.Cmds
{
    [Transaction(TransactionMode.Manual)]
    [Regeneration(RegenerationOption.Manual)]
    public class CreateFreeForm3 : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            try
            {
                Document doc = commandData.Application.ActiveUIDocument.Document;
                if (doc == null)
                    return Result.Failed;

                //查找到钢筋类型
                FilteredElementCollector fec = new FilteredElementCollector(doc).OfClass(typeof(RebarBarType));
                if (fec.GetElementCount() <= 0)
                    return Result.Failed;
                RebarBarType barType = fec.FirstElement() as RebarBarType;

                //启动事务
                using (Transaction tran = new Transaction(doc, "CreateFreeForm2"))
                {
                    Element host = null;
                    Selection sel = commandData.Application.ActiveUIDocument.Selection;
                    try
                    {
                        //选择主体对象
                        Reference hostRef = sel.PickObject(ObjectType.Element, "Select Host");
                        host = doc.GetElement(hostRef.ElementId);
                        if (host == null)
                            return Result.Failed;
                    }
                    catch (Exception e)
                    {
                        message = e.Message;
                        return Result.Failed;
                    }

                    tran.Start();

                    this.CreateFreeForm(doc, barType, host);


                    tran.Commit();
                }
                return Result.Succeeded;
            }
            catch (Exception ex)
            {
                message = ex.Message;
                return Result.Failed;
            }
        }


        /// <summary>
        /// 创建钢筋
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="barType"></param>
        /// <param name="host"></param>
        private void CreateFreeForm(Document doc, RebarBarType barType, Element host)
        {
            IList<IList<Curve>> curves = new List<IList<Curve>>();
            if (host is Wall wall)
            {
                //创建钢筋
                var wline = (wall.Location as LocationCurve).Curve;
                if (wline != null)
                {
              
                    for (var i = 0; i < 5; i++)
                    {
                        List<Curve> ps = new List<Curve>();
                        var start = wline.GetEndPoint(0);
                        var end = wline.GetEndPoint(1);
                        var v1 = new XYZ(start.X+0.5, start.Y, start.Z + i * 0.1);
                        var v2 = new XYZ(end.X-0.5, end.Y, end.Z + i * 0.1);
                        Curve l1 = Line.CreateBound(v1, v2);
                        var v3 = new XYZ(end.X-0.5, end.Y + 0.5, end.Z + i * 0.1);
                        Curve l2 = Line.CreateBound(v2, v3);
                        ps.Add(l1);
                        ps.Add(l2);
                        curves.Add(ps);
                    }
                }

            }

            RebarFreeFormValidationResult error;
            Rebar rebar = Rebar.CreateFreeForm(doc, barType, host, curves, out error);
        }
    }
}

生成结果展示如下:

image