-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
257 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+7.19 KB
(110%)
DesignAutomationConsole/Bundle/RevitAddin.DA.Tester.bundle.zip
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
using Autodesk.Revit.ApplicationServices; | ||
using Autodesk.Revit.DB; | ||
using DesignAutomationFramework; | ||
using System; | ||
|
||
namespace Revit.DesignApplication | ||
{ | ||
public abstract class DesignApplication : IExternalDBApplication, IDesignAutomation | ||
{ | ||
public ControlledApplication Application { get; private set; } | ||
public abstract void OnStartup(); | ||
public abstract void OnShutdown(); | ||
public abstract bool Execute(Application application, string filePath, Document document); | ||
|
||
private IExternalDBApplication designApplication; | ||
public ExternalDBApplicationResult OnStartup(ControlledApplication application) | ||
{ | ||
this.Application = application; | ||
|
||
designApplication = DesignApplicationLoader.LoadVersion(this); | ||
|
||
if (designApplication is IExternalDBApplication) | ||
{ | ||
return designApplication.OnStartup(application); | ||
} | ||
|
||
Console.WriteLine("----------------------------------------"); | ||
Console.WriteLine($"FullName: \t{this.GetType().Assembly.FullName}"); | ||
Console.WriteLine($"AddInName: \t{this.Application.ActiveAddInId?.GetAddInName()}"); | ||
Console.WriteLine("----------------------------------------"); | ||
|
||
OnStartup(); | ||
DesignAutomationBridge.DesignAutomationReadyEvent += DesignAutomationReadyEvent; | ||
|
||
return ExternalDBApplicationResult.Succeeded; | ||
} | ||
|
||
public ExternalDBApplicationResult OnShutdown(ControlledApplication application) | ||
{ | ||
this.Application = application; | ||
|
||
if (designApplication is IExternalDBApplication) | ||
{ | ||
try | ||
{ | ||
return designApplication.OnShutdown(application); | ||
} | ||
finally | ||
{ | ||
DesignApplicationLoader.Dispose(); | ||
} | ||
} | ||
|
||
OnShutdown(); | ||
DesignAutomationBridge.DesignAutomationReadyEvent -= DesignAutomationReadyEvent; | ||
|
||
return ExternalDBApplicationResult.Succeeded; | ||
} | ||
|
||
|
||
private void DesignAutomationReadyEvent(object sender, DesignAutomationReadyEventArgs e) | ||
{ | ||
DesignAutomationBridge.DesignAutomationReadyEvent -= DesignAutomationReadyEvent; | ||
|
||
var data = e.DesignAutomationData; | ||
|
||
Console.WriteLine("--------------------------------------------------"); | ||
Console.WriteLine($"RevitApp: {data.RevitApp} \tFilePath: {data.FilePath} \tRevitDoc: {data.RevitDoc} \nAddInName:{data.RevitApp.ActiveAddInId?.GetAddInName()}"); | ||
Console.WriteLine("--------------------------------------------------"); | ||
|
||
e.Succeeded = Execute(data.RevitApp, data.FilePath, data.RevitDoc); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
using Autodesk.Revit.DB; | ||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Runtime.Versioning; | ||
|
||
namespace Revit.DesignApplication | ||
{ | ||
internal static class DesignApplicationLoader | ||
{ | ||
private static Assembly loadAssembly; | ||
public static IExternalDBApplication LoadVersion<T>(T designApplication) where T : DesignApplication | ||
{ | ||
var type = designApplication.GetType(); | ||
|
||
var similar = AppDomain.CurrentDomain.GetAssemblies().Where(e => e.FullName == type.Assembly.FullName); | ||
if (similar.Count() >= 2) | ||
{ | ||
return null; | ||
} | ||
|
||
var location = type.Assembly.Location; | ||
var revitAssemblyReference = type.Assembly.GetReferencedAssemblies().FirstOrDefault(e => e.Name.Equals("RevitAPI")); | ||
var revitAssembly = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(e => e.GetName().Name.Equals("RevitAPI")); | ||
|
||
var revitReferenceVersion = revitAssemblyReference.Version.Major + 2000; | ||
var revitVersion = revitAssembly.GetName().Version.Major + 2000; | ||
|
||
Console.WriteLine("--------------------------------------------------"); | ||
Console.WriteLine($"DesignApplicationLoader: \t{revitVersion} -> {revitReferenceVersion}"); | ||
|
||
for (int version = revitVersion; version > revitReferenceVersion; version--) | ||
{ | ||
var directory = Path.GetDirectoryName(location); | ||
var directoryVersionRevit = Path.Combine(directory, "..", version.ToString()); | ||
var fileName = Path.Combine(directoryVersionRevit, Path.GetFileName(location)); | ||
|
||
//Console.WriteLine($"DesignApplicationLoader Try: \t{version}"); | ||
|
||
if (File.Exists(fileName)) | ||
{ | ||
fileName = new FileInfo(fileName).FullName; | ||
Console.WriteLine($"DesignApplicationLoader File Exists: \t{fileName}"); | ||
Console.WriteLine($"DesignApplicationLoader Version: \t{version}"); | ||
Console.WriteLine($"DesignApplicationLoader LoadFile: \t{Path.GetFileName(fileName)}"); | ||
AppDomain.CurrentDomain.AssemblyResolve += LoadAssemblyResolve; | ||
loadAssembly = Assembly.LoadFile(fileName); | ||
break; | ||
} | ||
} | ||
|
||
Console.WriteLine("----------------------------------------"); | ||
|
||
if (loadAssembly is not null) | ||
{ | ||
var loadType = loadAssembly.GetType(type.FullName); | ||
|
||
Console.WriteLine($"DesignApplicationLoader Type: {loadType}"); | ||
Console.WriteLine($"DesignApplicationLoader FrameworkName: \t{loadType.Assembly.GetCustomAttribute<TargetFrameworkAttribute>()?.FrameworkName}"); | ||
Console.WriteLine("----------------------------------------"); | ||
|
||
return Activator.CreateInstance(loadType) as IExternalDBApplication; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
private static Assembly LoadAssemblyResolve(object sender, ResolveEventArgs args) | ||
{ | ||
var assemblyName = new AssemblyName(args.Name); | ||
var assemblyPath = Path.Combine(Path.GetDirectoryName(loadAssembly.Location), assemblyName.Name + ".dll"); | ||
if (File.Exists(assemblyPath)) | ||
{ | ||
var folderName = Path.GetFileName(Path.GetDirectoryName(assemblyPath)); | ||
Console.WriteLine($"AssemblyResolve LoadFile: {folderName}\\{assemblyName.Name + ".dll"}"); | ||
return Assembly.LoadFile(assemblyPath); | ||
} | ||
return null; | ||
} | ||
|
||
public static void Dispose() | ||
{ | ||
AppDomain.CurrentDomain.AssemblyResolve -= LoadAssemblyResolve; | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...ddin.DA.Tester/Revit/IDesignAutomation.cs → Revit.DesignApplication/IDesignAutomation.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Library</OutputType> | ||
<LangVersion>latest</LangVersion> | ||
</PropertyGroup> | ||
|
||
<!-- RevitVersion --> | ||
<PropertyGroup> | ||
<TargetFrameworks>net47;net48;net8.0-windows</TargetFrameworks> | ||
<AppendTargetFrameworkToOutputPath>true</AppendTargetFrameworkToOutputPath> | ||
<ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>None</ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch> | ||
</PropertyGroup> | ||
<Choose> | ||
<When Condition="$(TargetFramework.StartsWith('net46'))"> | ||
<PropertyGroup> | ||
<RevitVersion>2017</RevitVersion> | ||
</PropertyGroup> | ||
</When> | ||
<When Condition="$(TargetFramework.StartsWith('net47'))"> | ||
<PropertyGroup> | ||
<RevitVersion>2019</RevitVersion> | ||
</PropertyGroup> | ||
</When> | ||
<When Condition="$(TargetFramework.StartsWith('net48'))"> | ||
<PropertyGroup> | ||
<RevitVersion>2021</RevitVersion> | ||
</PropertyGroup> | ||
</When> | ||
<Otherwise> | ||
<PropertyGroup> | ||
<RevitVersion>2025</RevitVersion> | ||
</PropertyGroup> | ||
</Otherwise> | ||
</Choose> | ||
|
||
<!-- Net Core --> | ||
<PropertyGroup Condition="!$(TargetFramework.StartsWith('net4'))"> | ||
<EnableDynamicLoading>true</EnableDynamicLoading> | ||
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles> | ||
<GenerateDependencyFile>false</GenerateDependencyFile> | ||
</PropertyGroup> | ||
|
||
<!-- Release --> | ||
<PropertyGroup Condition="!$(Configuration.Contains('Debug'))"> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\$(RevitVersion)</OutputPath> | ||
<DefineConstants>REVIT$(RevitVersion)</DefineConstants> | ||
<NoWarn>MSB3052</NoWarn> | ||
<DebugType>None</DebugType> | ||
</PropertyGroup> | ||
|
||
<!-- Debug --> | ||
<PropertyGroup Condition="$(Configuration.Contains('Debug'))"> | ||
<DebugSymbols>true</DebugSymbols> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE;REVIT$(RevitVersion)</DefineConstants> | ||
<DebugType>Full</DebugType> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Autodesk.Forge.DesignAutomation.Revit" Version="$(RevitVersion).*" IncludeAssets="build; compile" PrivateAssets="All" /> | ||
<PackageReference Include="Revit_All_Main_Versions_API_x64" Version="$(RevitVersion).*" IncludeAssets="build; compile" PrivateAssets="All" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,31 @@ | ||
using Autodesk.Revit.ApplicationServices; | ||
using Autodesk.Revit.DB; | ||
using Revit.DesignApplication; | ||
using RevitAddin.DA.Tester.Services; | ||
using System; | ||
|
||
namespace RevitAddin.DA.Tester.Revit | ||
{ | ||
public class App : IExternalDBApplication | ||
public class App : DesignApplication | ||
{ | ||
IDisposable designAutomation; | ||
public ExternalDBApplicationResult OnStartup(ControlledApplication application) | ||
public override void OnStartup() | ||
{ | ||
Console.WriteLine("----------------------------------------"); | ||
Console.WriteLine($"FullName: \t{this.GetType().Assembly.FullName}"); | ||
Console.WriteLine("----------------------------------------"); | ||
Console.WriteLine($"Location: {this.GetType().Assembly.Location}"); | ||
Console.WriteLine("----------------------------------------"); | ||
Console.WriteLine($"AddInName: \t{application.ActiveAddInId?.GetAddInName()}"); | ||
Console.WriteLine($"AddInName: \t{Application.ActiveAddInId?.GetAddInName()}"); | ||
Console.WriteLine("----------------------------------------"); | ||
|
||
designAutomation = new DesignAutomationLoadVersion<DesignAutomationController>(); | ||
return ExternalDBApplicationResult.Succeeded; | ||
} | ||
|
||
public ExternalDBApplicationResult OnShutdown(ControlledApplication application) | ||
public override void OnShutdown() | ||
{ | ||
|
||
} | ||
public override bool Execute(Application application, string filePath, Document document) | ||
{ | ||
designAutomation?.Dispose(); | ||
return ExternalDBApplicationResult.Succeeded; | ||
return new DesignAutomationController().Execute(application, filePath, document); | ||
} | ||
} | ||
} |
Oops, something went wrong.