RevitAddinUtility x32/x64

by Guy Robinson 20. May 2010 15:12

Jeremy nicely summed up the issues with the RevitAddUtility.dll . I thought I’d document my solution which uses interfaces to solve the issue. The problem is the loader exception fires before your application can catch it. By using interfaces you can utilise the appropriate assemblies which maintaining a single main application and no file copying.

Depending on which platform you run it on, the console app should utilise the correct assembly. In this example it just prints the names of any revit applications installed.

Here’s the console code for reference.

var assemDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var current = AppDomain.CurrentDomain;
IAddInFactory addinFactory;
try
{
    // assume 64bit is more common now
    var addInAssemName = AssemblyName.GetAssemblyName(Path.Combine(assemDir, @"Redbolts.AddIn.AddIn64Factory.dll")).FullName;
    addinFactory = (IAddInFactory)current.CreateInstanceAndUnwrap(addInAssemName,
        "Redbolts.AddIn.AddIn64Factory.AddInFactory", 
        false, BindingFlags.Default, null, null , null, null, null);
    Console.WriteLine("Successfully loaded 64bit OS version of RevitAddInUtility");
}
catch (Exception ex)
{
    addinFactory = (IAddInFactory)current.CreateInstanceFromAndUnwrap(Path.Combine(assemDir, @"OS32\Redbolts.AddIn.AddIn32Factory.dll"),
        "Redbolts.AddIn.AddIn32Factory.AddInFactory",
        false, BindingFlags.Default, null, null, null, null, null);
    Console.WriteLine("Successfully loaded 32bit OS version of RevitAddInUtility");
}
 
 
if (addinFactory!= null)
{
    Console.WriteLine(addinFactory.RevitInstalledApplications.Count());
    foreach (string revitInstalledApplication in addinFactory.RevitInstalledApplications)
    {
        Console.WriteLine(revitInstalledApplication);
    }
}
Console.ReadLine();

And here’s the example app (VS2010 solution) ExampleAddInConsole.zip (44.82 kb) enjoy!!

Comments are closed

About the Author

A .NET software Developer providing custom applications and commands for architecture firms exclusively working with Autodesk Revit and integration with any associated applications. All from a little place north of Whitianga, New Zealand.

Page List

Disclaimer

I'm self employed so the opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway☺

© Copyright2008

Creative Commons License
Blog content is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.

With the following exception. All code snippets, application and libraries are licensed under a a Apache License Version 2.0

Autodesk Revit®

Autodesk: Revit is a product that is wholly owned by Autodesk. Any reference to Revit,Revit API, Revit Architecture, Revit MEP or Revit Structure on this site is made acknowledging this ownership. Refer to Autodesk's own web site and product pages for specific trademark and copyright information. Autodesk represents a great many products and every attempt will be made to respect their ownership whenever one of these other products is mentioned on this site.