Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 1.4.0 #11

Merged
merged 7 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [1.4.0] / 2025-08-27
### Features
- Support Bundle multiple versions of Revit using `DesignAutomationLoadVersion`. (#7)
### Updates
- Add `DesignAutomation` and `IDesignAutomation` interface.
- Add `DesignAutomationLoadVersion` to load the right version of the addin.
- Add `AssemblyResolve` in the `DesignAutomationLoadVersion` to load dependencies in the right version.
- Use `where T : IDesignAutomation` in `DesignAutomation<T>` and `DesignAutomationLoadVersion<T>`.
- Fix `DesignAutomation` method selection by finding first method `Execute` with 3 parameters.

## [1.3.1] / 2025-06-15 - 2025-08-27
- Add `AddInId` in the output. #9
- Update `AddInId` to `AddInName` in model class.
Expand All @@ -30,6 +40,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- First Release

[vNext]: ../../compare/1.0.0...HEAD
[1.4.0]: ../../compare/1.3.1...1.4.0
[1.3.1]: ../../compare/1.3.0...1.3.1
[1.3.0]: ../../compare/1.2.0...1.3.0
[1.2.0]: ../../compare/1.1.0...1.2.0
Expand Down
Binary file modified DesignAutomationConsole/Bundle/RevitAddin.DA.Tester.bundle.zip
Binary file not shown.
14 changes: 3 additions & 11 deletions RevitAddin.DA.Tester/Revit/App.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.DB;
using DesignAutomationFramework;
using RevitAddin.DA.Tester.Services;
using System;

namespace RevitAddin.DA.Tester.Revit
{
public class App : IExternalDBApplication
{
IDisposable designAutomation;
public ExternalDBApplicationResult OnStartup(ControlledApplication application)
{
Console.WriteLine("----------------------------------------");
Expand All @@ -18,22 +18,14 @@ public ExternalDBApplicationResult OnStartup(ControlledApplication application)
Console.WriteLine($"AddInName: \t{application.ActiveAddInId?.GetAddInName()}");
Console.WriteLine("----------------------------------------");

DesignAutomationBridge.DesignAutomationReadyEvent += DesignAutomationBridge_DesignAutomationReadyEvent;
designAutomation = new DesignAutomationLoadVersion<DesignAutomationController>();
return ExternalDBApplicationResult.Succeeded;
}

public ExternalDBApplicationResult OnShutdown(ControlledApplication application)
{
DesignAutomationBridge.DesignAutomationReadyEvent -= DesignAutomationBridge_DesignAutomationReadyEvent;
designAutomation?.Dispose();
return ExternalDBApplicationResult.Succeeded;
}

private void DesignAutomationBridge_DesignAutomationReadyEvent(object sender, DesignAutomationReadyEventArgs e)
{
DesignAutomationBridge.DesignAutomationReadyEvent -= DesignAutomationBridge_DesignAutomationReadyEvent;

var data = e.DesignAutomationData;
e.Succeeded = DesignAutomationController.Execute(data.RevitApp, data.FilePath, data.RevitDoc);
}
}
}
77 changes: 77 additions & 0 deletions RevitAddin.DA.Tester/Revit/DesignAutomation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using DesignAutomationFramework;
using System;
using System.Linq;

namespace RevitAddin.DA.Tester.Revit
{
public class DesignAutomation<T> : DesignAutomation where T : IDesignAutomation
{
public DesignAutomation() : base(Activator.CreateInstance(typeof(T)))
{

}
public DesignAutomation(T instance) : base(instance)
{

}
}

public class DesignAutomation : IDisposable
{
private readonly object instance;

public DesignAutomation(Type type)
{
this.instance = Activator.CreateInstance(type);
Initialize();
}

public DesignAutomation(object instance)
{
this.instance = instance;
Initialize();
}

public virtual void Initialize()
{
Console.WriteLine($"{nameof(DesignAutomation)} Initialize: \t{instance}");
DesignAutomationBridge.DesignAutomationReadyEvent += DesignAutomationReadyEvent;
}

public void Dispose()
{
Console.WriteLine($"{nameof(DesignAutomation)} Dispose: \t{instance}");
DesignAutomationBridge.DesignAutomationReadyEvent -= DesignAutomationReadyEvent;
}

private void DesignAutomationReadyEvent(object sender, DesignAutomationReadyEventArgs e)
{
DesignAutomationBridge.DesignAutomationReadyEvent -= DesignAutomationReadyEvent;

var data = e.DesignAutomationData;

Console.WriteLine("--------------------------------------------------");
Console.WriteLine($"RevitApp: {data.RevitApp} FilePath: {data.FilePath} RevitDoc: {data.RevitDoc}");
Console.WriteLine("--------------------------------------------------");

try
{
var method = instance.GetType().GetMethods()
.Where(e => e.Name.Equals(nameof(IDesignAutomation.Execute)))
.FirstOrDefault(e => e.GetParameters().Count() == 3);

Console.WriteLine($"Invoke: {method}");

var result = method.Invoke(instance, new object[] { data.RevitApp, data.FilePath, data.RevitDoc });

if (result is bool resultBool)
e.Succeeded = resultBool;
}
catch (Exception ex)
{
Console.WriteLine($"{nameof(DesignAutomation)} Invoke Exception: \t{ex.Message}");
throw;
}
}
}
}
79 changes: 79 additions & 0 deletions RevitAddin.DA.Tester/Revit/DesignAutomationLoadVersion.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Versioning;

namespace RevitAddin.DA.Tester.Revit
{
public class DesignAutomationLoadVersion<T> : DesignAutomationLoadVersion where T : IDesignAutomation
{
public DesignAutomationLoadVersion() : base(typeof(T))
{

}
}

public class DesignAutomationLoadVersion : IDisposable
{
readonly IDisposable designAutomation;
readonly Assembly loadAssembly;

public DesignAutomationLoadVersion(Type type)
{
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($"DesignAutomationLoadVersion: \t{revitVersion} -> {revitReferenceVersion}");

for (int version = revitVersion; version > revitReferenceVersion; version--)
{
var directory = System.IO.Path.GetDirectoryName(location);
var directoryVersionRevit = System.IO.Path.Combine(directory, "..", version.ToString());
var fileName = System.IO.Path.Combine(directoryVersionRevit, System.IO.Path.GetFileName(location));

Console.WriteLine($"DesignAutomationLoadVersion Try: \t{version}");

if (File.Exists(fileName))
{
fileName = new FileInfo(fileName).FullName;
Console.WriteLine($"DesignAutomationLoadVersion File Exists: \t{fileName}");
Console.WriteLine($"DesignAutomationLoadVersion Version: \t{version}");
Console.WriteLine($"DesignAutomationLoadVersion LoadFile: \t{Path.GetFileName(fileName)}");
AppDomain.CurrentDomain.AssemblyResolve += LoadAssemblyResolve;
loadAssembly = Assembly.LoadFile(fileName);
type = loadAssembly.GetType(type.FullName);
break;
}
}

Console.WriteLine("----------------------------------------");
Console.WriteLine($"DesignAutomationLoadVersion Type: {type}");
Console.WriteLine($"DesignAutomationLoadVersion FrameworkName: \t{type.Assembly.GetCustomAttribute<TargetFrameworkAttribute>()?.FrameworkName}");
designAutomation = new DesignAutomation(type);
}

private 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 void Dispose()
{
designAutomation?.Dispose();
AppDomain.CurrentDomain.AssemblyResolve -= LoadAssemblyResolve;
}
}
}
10 changes: 10 additions & 0 deletions RevitAddin.DA.Tester/Revit/IDesignAutomation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.DB;

namespace RevitAddin.DA.Tester.Revit
{
public interface IDesignAutomation
{
bool Execute(Application application, string filePath, Document document);
}
}
3 changes: 2 additions & 1 deletion RevitAddin.DA.Tester/RevitAddin.DA.Tester.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@

<PropertyGroup>
<PackageId>RevitAddin.DA.Tester</PackageId>
<Version>1.3.1</Version>
<Version>1.4.0</Version>
<ProjectGuid>{7C324916-9F8D-43B0-B226-DA67D2504393}</ProjectGuid>
</PropertyGroup>

Expand Down Expand Up @@ -128,6 +128,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="ricaun.Revit.DB.Shape" Version="*" />
<PackageReference Include="Autodesk.Forge.DesignAutomation.Revit" Version="$(RevitVersion).*" />
</ItemGroup>

Expand Down
8 changes: 6 additions & 2 deletions RevitAddin.DA.Tester/Services/DesignAutomationController.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.DB;
using RevitAddin.DA.Tester.Models;
using RevitAddin.DA.Tester.Revit;
using System;
using System.Linq;
using System.Reflection;
using System.Runtime.Versioning;

namespace RevitAddin.DA.Tester.Services
{
public class DesignAutomationController
public class DesignAutomationController : IDesignAutomation
{
public static bool Execute(Application application, string filePath = null, Document document = null)
public bool Execute(Application application, string filePath = null, Document document = null)
{
var inputModel = new InputModel().Load();

Expand Down Expand Up @@ -39,6 +40,9 @@ public static bool Execute(Application application, string filePath = null, Docu

Console.WriteLine($"UI:\t{UI.IsValid()}");
Console.WriteLine("----------------------------------------");
Console.WriteLine($"Shape:\t{typeof(ricaun.Revit.DB.Shape.Colors).Assembly}");
Console.WriteLine($"Shape Location:\t{typeof(ricaun.Revit.DB.Shape.Colors).Assembly.Location}");
Console.WriteLine("----------------------------------------");

return true;
}
Expand Down