revit api明细表

news/2025/10/31 21:21:01/文章来源:https://www.cnblogs.com/miki969696/p/19181274

revit api明细表

如果想要读取明细表的内容,可以用 ViewSchedule 父类 TableView 的接口。

namespace Autodesk.Revit.DB
{public class TableView : View{public int MaximumRowHeight { get; }public int MaximumColumnWidth { get; }public int MinimumRowHeight { get; }public int MinimumColumnWidth { get; }public int MaximumGridWidth { get; }public ElementId TargetId { get; set; }public static IList<ElementId> GetAvailableParameters(Document cda, ElementId categoryId);public IList<ElementId> GetAvailableParameterCategories(SectionType sectionType, int row);public string GetCalculatedValueName(SectionType sectionType, int row, int column);public string GetCalculatedValueText(SectionType sectionType, int row, int column);public string GetCellText(SectionType sectionType, int row, int column);public bool IsValidSectionType(SectionType sectionType);}
}

ViewSchedule及相关图元创建

// ViewSchedule 相关创建接口
// Creates a keynote legend.
public static ViewSchedule CreateKeynoteLegend(Document document);
// Create a key schedule.
public static ViewSchedule CreateKeySchedule(Document document, ElementId categoryId);
// Creates a material takeoff.
public static ViewSchedule CreateMaterialTakeoff(Document document, ElementId categoryId);
// Creates a note block.
public static ViewSchedule CreateNoteBlock(Document document, ElementId familyId);
// Creates a revision schedule.
public static ViewSchedule CreateRevisionSchedule(Document document);
// Creates a regular schedule that can relate to a specific area scheme.
public static ViewSchedule CreateSchedule(Document document, ElementId categoryId, ElementId areaSchemeId);
// Creates a regular schedule.
public static ViewSchedule CreateSchedule(Document document, ElementId categoryId);
// Creates a sheet list.
public static ViewSchedule CreateSheetList(Document document);
// Creates a view list.
public static ViewSchedule CreateViewList(Document document);

设置背景色等

// 获取某一列的样式
ScheduleField field = definition.GetField(id);
TableCellStyle style = field.GetStyle();
TableCellStyleOverrideOptions options = style.GetCellStyleOverrideOptions();// Override 背景色
options.BackgroundColor = true;
style.SetCellStyleOverrideOptions(options);// 设置背景色
style.BackgroundColor = highlight;
field.SetStyle(style);

创建墙体明细表

using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.Attributes;
using System;
using System.Collections.Generic;
using System.Linq;[Transaction(TransactionMode.Manual)]
public class CreateScheduleCommand : IExternalCommand
{public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements){UIApplication uiapp = commandData.Application;UIDocument uidoc = uiapp.ActiveUIDocument;Document doc = uidoc.Document;try{// 开始事务using (Transaction trans = new Transaction(doc, "Create Wall Schedule")){trans.Start();// 创建墙体明细表ViewSchedule schedule = ViewSchedule.CreateSchedule(doc, new ElementId(BuiltInCategory.OST_Walls), ElementId.InvalidElementId);// 设置明细表名称schedule.Name = "墙体体积明细表";// 获取明细表定义ScheduleDefinition definition = schedule.Definition;// 获取可用字段IList<SchedulableField> schedulableFields = definition.GetSchedulableFields();// 查找墙类型和体积字段SchedulableField typeField = schedulableFields.FirstOrDefault(field => field.ParameterId.IntegerValue == (int)BuiltInParameter.ELEM_TYPE_PARAM);SchedulableField volumeField = schedulableFields.FirstOrDefault(field => field.ParameterId.IntegerValue == (int)BuiltInParameter.HOST_VOLUME_COMPUTED);// 检查字段是否找到if (typeField == null || volumeField == null){trans.RollBack();TaskDialog.Show("错误", "无法找到墙类型或体积参数。请检查 Revit 2021 参数可用性。");return Result.Failed;}// 添加字段到明细表ScheduleField typeScheduleField = definition.AddField(ScheduleFieldType.Instance, typeField.ParameterId); // 墙类型ScheduleField volumeScheduleField = definition.AddField(ScheduleFieldType.Instance, volumeField.ParameterId); // 体积// 设置字段标题typeScheduleField.ColumnHeading = "墙类型";volumeScheduleField.ColumnHeading = "体积";// 添加过滤器(仅显示具有体积的墙体)ScheduleFilter filter = new ScheduleFilter(volumeScheduleField.FieldId, ScheduleFilterType.GreaterThan, 0.0);definition.AddFilter(filter);// 设置排序(按墙类型排序)ScheduleSortGroupField sortField = new ScheduleSortGroupField(typeScheduleField.FieldId);definition.AddSortGroupField(sortField);trans.Commit();}TaskDialog.Show("成功", "墙体体积明细表已创建!");return Result.Succeeded;}catch (Exception ex){message = ex.Message;TaskDialog.Show("错误", $"创建明细表失败:{ex.Message}");return Result.Failed;}}
}

读取明细表第一个值

using System;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;namespace ScheduleDataReader
{[Transaction(TransactionMode.Manual)]public class ReadScheduleFirstCellCommand : IExternalCommand{public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements){try{Document doc = commandData.Application.ActiveUIDocument.Document;View activeView = doc.ActiveView;if (activeView is ViewSchedule schedule){string cellData = schedule.GetCellText(SectionType.Body, 0, 0);TaskDialog.Show("读取成功", $"明细表: {schedule.Name}\n" +$"第一单元格: {cellData}");return Result.Succeeded;}TaskDialog.Show("错误", "请先打开一个明细表");return Result.Failed;}catch (Exception ex){TaskDialog.Show("错误", $"读取失败: {ex.Message}");return Result.Failed;}}}
}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/952219.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【开题答辩实录分享】以《基于python的奶茶店分布数据分析与可视化》为例进行答辩实录分享 - 教程

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …

2025.10.31

今天没课在宿舍躺一天

使用RNNoise进行音频降噪

使用RNNoise进行音频降噪操作系统:Debian 12.5_x64 & Windows10_x64 rnnoise版本:0.2 gcc版本:12.2.0 python版本: 3.9.13 RNNoise是一个将传统数字信号处理与深度学习相结合的开源实时音频降噪库,可在消耗极…

程序员修炼之道:从小工到专家读后感(2025_10_31)

在正确与容易之间:每个程序员都面临的永恒选择 《程序员修炼之道》的第七章像一面镜子,照出了每个程序员日常工作中最真实的挣扎。当“在正确与容易之间做选择”这个命题出现在面前时,我感到心头一震——这不正是我…

Python测试(下) _ 高效率把bug揪出来

Python测试(下) _ 高效率把bug揪出来#导入测试内置模块import unittest#导入要测试的api,Student为类名from _oop import Studentfrom _oop import SmallStudent#需要继承unittest.TestCase,def函数必须用test_开头…

如何精准驱动菜品识别模型--基于米尔瑞芯微RK3576边缘计算盒

在人工智能与边缘计算深度融合的今天,将AI模型高效部署于终端设备已成为产业智能化的关键。本文将分享基于米尔MYD-LR3576边缘计算盒子部署菜品识别安卓Demo的实战经验。该设备凭借其内置的强劲瑞芯微RK3576芯片,为视…

MPK(Mirage Persistent Kernel)源码笔记(4)--- 转译系统

MPK(Mirage Persistent Kernel)源码笔记(4)--- 转译系统 目录MPK(Mirage Persistent Kernel)源码笔记(4)--- 转译系统0x00 概要0x01 Task和Event1.1 可执行任务1.1.1 任务定义1.1.2 任务类型1.2 事件1.2.1 事件…

征程 6 | 多任务 不同帧率 部署方案

1.方案描述 推理多任务模型时,可能会有不同任务分支 部署不同帧率的需求,例如 BEV 动态任务 20 帧,静态任务 10 帧这种情况。最简单的方式是编译两个模型,分开推理:模型 1:backbone+neck+ 动态 head 模型 2:bac…

10月31号

今天进行了外语学习。

10月29号

今天进行了离散数学和马克思主义的学习

️ 深度解析我的 Overleaf 私有化部署:一份稳定、高兼容性的 `docker-compose.yaml`

通过私有化部署 Overleaf(ShareLaTeX CE),我们能彻底掌控一个功能完整的 LaTeX 协作环境,为您的论文编写和数据安全提供强大保障,告别官方服务的付费限制与硬件兼容性烦恼。大家好,我是 XuHe。在上一篇博客告别 …

支配点对小记

支配点对小记 此类问题的形式一般为:多次询问某范围内最优点对(的贡献)。 考虑一些特别的情况,若某点对被严格偏序,显然无需考虑该点对。于是考虑只保留可能成为最优解的点对,称之为支配点对。 对于两个点对 \(a…

2025赣南脐橙最新推荐品牌榜,源头赣南脐橙果园品牌综合评测!

2025赣南脐橙最新推荐品牌榜,源头赣南脐橙果园品牌综合评测!摘要 本文基于行业数据与用户调研及《GB/T 20355-2006 地理标志产品 赣南脐橙》中的质量指标(包括感官指标、理化指标、卫生指标、净含量),对市面上主流…

Kosaraju 笔记

在做 ARC069F Flags 时看到有一个用 kosaraju 的 nb 做法,于是研究了一下 kosaraju。 Kosaraju 算法 kosaraju 算法是一种找出强连通分量的算法,用途和 tarjan 类似,但是代码更好写,并且在某些题上比 tarjan 算法有…

Manacher 代码贴贴

#include<bits/stdc++.h> using namespace std; const int N=1.1e7+5; char rS[N]; char S[N<<1]; int P[N<<1],n; void init(){n=strlen(rS);int k=0;S[k++]=$;S[k++]=#;for(int i=0;i<n;i++){S…

Python测试(上)_ 不存在不写bug的程序员

Python测试(上)_ 不存在不写bug的程序员#导入测试内置模块import unittest#导入要测试的apifrom _try_except import condition#需要继承unittest.TestCase,def函数必须用test_开头class MyTestCase(unittest.TestC…

P9119 [春季测试 2023] 圣诞树

首先需要发现一些性质,不然就真成不可做问题了,考虑凸多边形的一些性质。 考虑四边形定理,两条相交边长度一定大于两条不交边长度,这启示我们路径连线本质不交,然后我们继续思考路径形态。 路径形态是这样子的,你…

Java性能调优的艺术:从字节码到云端的全链路优化

在Java开发的世界里,我们常常享受其“一次编写,到处运行”的便利和垃圾回收带来的自动化管理。然而,当应用变得复杂、负载升高时,性能问题便会悄然而至:响应缓慢、吞吐量下降、频繁GC,甚至内存溢出导致服务崩溃。…

2025.10.31总结 - A

今天没课,在宿舍休息了,加油,依旧按时完成博客园,加油

用隐式马尔科夫模型检测XSS攻击Payload

其实XSS说白了,就是通过向网页中注入恶意的脚本代码,一般来说都是 JavaScript,让代码在其他用户的浏览器中执行,从而达到窃取信息、冒充身份、传播木马等目的。换句话说,网站本来应该只展示安全的内容的,但是攻击…