升級 Revit 巨集

如果您升級 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