升级 Revit 宏

如果要升级宏,则可能需要执行一些文件管理任务,以便在 Revit 中正确地更新和运行宏。

务必熟悉 Revit 软件开发工具包 (SDK) 的更改和下列宏升级信息。

升级应用程序级宏

  1. 复制宏目录并粘贴到:
    • Windows 7 和 Windows 8:%ProgramData%\Autodesk\Revit\Macros\2025 Release\Revit\AppHookup
  2. 找到 .csproj 并进行以下更改:
    • 将“<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>”更改为“<TargetFramework>net7.0-windows</TargetFramework>”。
以下是一个新的宏项目示例。
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0-windows</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' ">
    <PlatformTarget>x64</PlatformTarget>
    <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
    <AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
    <Optimize>False</Optimize>
    <DebugSymbols>True</DebugSymbols>
    <DebugType>Portable</DebugType>
    <OutputPath>..\..\Addin\</OutputPath>
    <AssemblyName>MacroTemplate</AssemblyName>
    <BaseInterMediateOutputPath>obj\</BaseInterMediateOutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <InterMediateOutputPath>obj\Debug</InterMediateOutputPath>
    <Deterministic>false</Deterministic>
    <GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
    <GenerateAssemblyDescriptionAttribute>false</GenerateAssemblyDescriptionAttribute>
    <GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
    <GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
    <GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
    <GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="..\..\..\..\..\RevitAPI.dll">
      <Private>False</Private>
    </Reference>
    <Reference Include="..\..\..\..\..\RevitAPIUI.dll">
      <Private>False</Private>
    </Reference>
  </ItemGroup>
  <Target Name="PreBuild" BeforeTargets="PreBuildEvent">
    <Exec Command="del $(OutputPath)\*.dll" />
  </Target>
</Project>

升级文档级宏

  1. Revit 2025 不支持文档级宏。您需要手动将文档级宏转换为应用程序级宏。
  2. 使用早期版本的 Revit 打开文档,然后将文档宏项目复制到应用程序宏文件夹。
  3. 更新 .csproj 文件。
  4. 更改文件名。将“ThisDocument.cs”更改为“ThisApplication.cs”、将“ThisDocument.Designer.cs”更改为“ThisApplication.Designer.cs”。
  5. 在 .cs 文件中,将类名称从“ThisDocument”更改为“ThisApplication”。
  6. 在 ThisApplication.Designer.cs 中,将父类名称从“Autodesk.Revit.UI.Macros.DocumentEntryPoint”更改为“Autodesk.Revit.UI.Macros.ApplicationEntryPoint”。
注: 如果 Revit 已在运行,则 Revit 2025 中升级的宏不会自动加载。要加载升级的宏,需要重新启动 Revit