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

推荐订阅源

Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
V
Vulnerabilities – Threatpost
L
LINUX DO - 热门话题
H
Hacker News: Front Page
Hacker News - Newest:
Hacker News - Newest: "LLM"
L
Lohrmann on Cybersecurity
Cisco Talos Blog
Cisco Talos Blog
O
OpenAI News
S
Securelist
Security Latest
Security Latest
T
Threat Research - Cisco Blogs
H
Heimdal Security Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Recorded Future
Recorded Future
Microsoft Azure Blog
Microsoft Azure Blog
MyScale Blog
MyScale Blog
Webroot Blog
Webroot Blog
The Hacker News
The Hacker News
Google Online Security Blog
Google Online Security Blog
Latest news
Latest news
N
Netflix TechBlog - Medium
N
News and Events Feed by Topic
D
Docker
D
DataBreaches.Net
A
About on SuperTechFans
T
Tor Project blog
V
V2EX
G
Google Developers Blog
博客园 - Franky
N
News | PayPal Newsroom
T
The Blog of Author Tim Ferriss
I
InfoQ
H
Help Net Security
V2EX - 技术
V2EX - 技术
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
S
Security Affairs
SecWiki News
SecWiki News
The Register - Security
The Register - Security
人人都是产品经理
人人都是产品经理
NISL@THU
NISL@THU
小众软件
小众软件
B
Blog
T
Threatpost
P
Palo Alto Networks Blog
博客园 - 【当耐特】
L
LangChain Blog
AWS News Blog
AWS News Blog
月光博客
月光博客
宝玉的分享
宝玉的分享

博客园 - Albert_MIN

在 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