Files
RevitGen/README.md
2025-09-04 15:53:29 +08:00

66 lines
2.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
- 右键RevitGen项目打包生成nuget可以修改版本。
- 在插件项目去引用nuget包本地路径需要修改nuget.config中的相对路径。
- 使用partial修饰你的命令类
- 使用RevitCommand生成命令和面板
- CommandHandler来定义运行的逻辑方法
- 如果是路径的图标的话,需要属性窗口中把生成方式改成嵌入式资源
- 命令自带UIApplication,UIDocument,Document,ActiveView等属性
- 自带事务处理
- 命令的特性会生成一个RevitGenApplication的类注册命令生成面板。
```
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using RevitGen.Attributes;
using RevitGenTest.Properties;
namespace RevitGenTest
{
[RevitCommand("我的第一个命令", ToolTip = "这是一个自动生成的酷炫命令!", PanelName = "核心功能", Icon = nameof(Resources.CodeList_32px))]
public partial class RevitAddinOne
{
[CommandHandler]
private void Run()
{
var walls = new FilteredElementCollector(Document)
.OfCategory(BuiltInCategory.OST_Walls)
.WhereElementIsNotElementType()
.ToElements();
if (walls.Count == 0)
{
// 如果出现问题,只需设置属性即可
this.ErrorMessage = "项目中没有找到任何墙。";
this.Result = Result.Failed;
return; // 提前返回
}
TaskDialog.Show("成功", $"找到了 {walls.Count} 面墙。");
}
}
[RevitCommand("我的第二个命令", ToolTip = "这是自动生成的酷炫命令!", PanelName = "核心功能", Icon = "Resources/CodeList_32px.png")]
public partial class RevitAddinTwo
{
[CommandHandler]
private void Run()
{
var walls = new FilteredElementCollector(Document)
.OfCategory(BuiltInCategory.OST_Walls)
.WhereElementIsNotElementType()
.ToElements();
if (walls.Count == 0)
{
// 如果出现问题,只需设置属性即可
this.ErrorMessage = "项目中没有找到任何墙。";
this.Result = Result.Failed;
return; // 提前返回
}
TaskDialog.Show("成功", $"找到了 {walls.Count} 面墙。");
}
}
}
```