ShrlAlgo 6523d20f49 Improve README with clearer usage instructions
Updated instructions for using .NET Upgrade Assistant and clarified command generation steps.
2025-09-04 16:38:51 +08:00
2025-09-04 16:10:58 +08:00
2025-09-04 16:10:58 +08:00
2025-09-04 11:42:36 +08:00
2025-09-03 21:46:26 +08:00
2025-09-03 21:46:26 +08:00

注意事项

  • 使用该包的项目的源生成器,需要使用新的.Net SDK 样式,如果不是,可以在https://marketplace.visualstudio.com/vs或者visual studio菜单-扩展-管理扩展,搜索.NET Upgrade Assistant安装
  • 之后在项目鼠标右键-升级(选最后一项 将项目转换为SDK样式- 右键RevitGen项目打包生成nuget可以修改版本。
  • 在插件项目本地去引用nuget包本地路径需要修改nuget.config中的相对路径。

使用方法

  • 使用partial修饰你的命令类
  • 使用RevitCommand生成外部命令和面板
  • Icon如果是路径的图标的话,需要属性窗口中把生成方式改成嵌入式资源
  • 自带事务处理,不需要使用默认事务时,可以使用[RevitCommand("测试", UsingTransaction = false)]
  • 使用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} 面墙。");
        }
    }
}
Description
No description provided
Readme MIT 66 KiB
Languages
C# 100%