AutoRevit.Generator 0.0.10

dotnet add package AutoRevit.Generator --version 0.0.10
                    
NuGet\Install-Package AutoRevit.Generator -Version 0.0.10
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AutoRevit.Generator" Version="0.0.10" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AutoRevit.Generator" Version="0.0.10" />
                    
Directory.Packages.props
<PackageReference Include="AutoRevit.Generator" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add AutoRevit.Generator --version 0.0.10
                    
#r "nuget: AutoRevit.Generator, 0.0.10"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=AutoRevit.Generator&version=0.0.10
                    
Install AutoRevit.Generator as a Cake Addin
#tool nuget:?package=AutoRevit.Generator&version=0.0.10
                    
Install AutoRevit.Generator as a Cake Tool

AutoRevit.Generator

概述

AutoRevit.Generator 是一个专为 Revit 二次开发设计的源生成器库,旨在通过自动生成代码简化开发流程。它支持生成外部命令和外部事件处理器,帮助开发者快速集成 Revit API,减少重复性工作。

特性

  • 外部命令生成器:自动生成继承 IExternalCommand 的类。
  • 外部事件处理器生成器:自动生成继承 IExternalEventHandler 的类。
  • 灵活的配置:支持通过特性参数自定义生成的类行为。
  • 高效开发:减少手动编写样板代码的时间。

安装

通过 NuGet 安装此库:

dotnet add package AutoRevit.Generator

使用指南

1. 外部命令生成器

示例

以下是一个使用 AutoExternalCommand 特性生成外部命令的示例:

public class AutoCommand
{
    [AutoExternalCommand]
    internal static Result CreateWall(ExternalCommandData commandData, ref string message)
    {
        try
        { // 业务逻辑
          return Result.Succeeded; 
        } 
        catch (Exception ex) 
        { 
            message = ex.Message; 
            return Result.Failed;
        } 
    } 
}
生成的代码

上述代码会自动生成以下类:

[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)] 
public class CreateWallAutoExternalCommand : Autodesk.Revit.UI.IExternalCommand 
{ 
    public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements) 
    { 
        return AutoCommand.CreateWall(commandData, ref message); 
    } 
}
使用要求
  • 方法必须标注 [AutoExternalCommand] 特性。
  • 方法必须是 static,且修饰符为 internalpublic
  • 返回值必须为 Autodesk.Revit.UI.Result
  • 支持的参数类型:
    • ExternalCommandData
    • string(需使用 ref
    • ElementSet
    • IRevitData(需引用 AutoRevit 包)

2. 外部事件处理器生成器

示例

以下是一个使用 AutoExternalEventHandler 特性生成外部事件处理器的示例:

[AutoExternalEventHandler] 
public static void ExecuteEvent(UIApplication uiApp) 
{ 
    TaskDialog.Show("Event", "External Event Executed");
}
生成的代码

上述代码会自动生成以下类:

public class ExecuteEventAutoExternalEventHandler : Autodesk.Revit.UI.IExternalEventHandler
{
    public void Execute(UIApplication app)
    {
        AutoEvent.ExecuteEvent(app);
    }
    public string GetName()
    {
        return "ExecuteEvent";
    }
}
使用方法

创建外部事件处理器实例并调用:

var eventHandler = ExternalEvent.Create(new ExecuteEventAutoExternalEventHandler()); 
eventHandler.Raise();

3. 特性参数说明

AutoExternalCommandAttribute
  • Namespace: 自定义命令空间,默认为方法的命名空间。
  • ClassName: 自定义生成类的名称。
  • TransactionMode: 定义事务模式(如 ManualReadOnly)。
  • JournalingMode: 定义日志记录模式。
  • RegenerationOption: 定义 Regeneration Option。
AutoExternalEventHandlerAttribute
  • Namespace: 自定义命令空间,默认为方法的命名空间。
  • ClassName: 自定义生成类的名称。
  • EventName: 自定义事件名称。
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.0.10 132 4/27/2025
0.0.4 150 4/23/2025