Hi,
I’m trying to create a console application that can read data from a Revit model without having to open Revit. Compiling the code works just fine, but when I try to run it, I get a System.BadImageFormatException saying that the RevitAPI.dll module or one of its dependencies couldn’t be found. Might this be because I’m creating this as a console application rather than the standard class library we use for addins?
Here’s the code I’m using as reference:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Forms; using Autodesk.Revit.UI; using Autodesk.Revit.DB; namespace extractFromClosedRevitFile { class Program { [STAThread] static void Main(string[] args) { Autodesk.Revit.ApplicationServices.Application revitApp =
new Autodesk.Revit.ApplicationServices.Application(); OpenFileDialog ofd = new OpenFileDialog(); if (ofd.ShowDialog() == DialogResult.Cancel) { return; } Document doc = revitApp.OpenDocumentFile(ofd.FileName); Console.WriteLine(doc.Title); Console.ReadLine(); } } }
Thanks,
Travis
Solved! Go to Solution.
Solved by arnostlobel. Go to Solution.
I am sorry, Travis, you cannot do what you want to do. You cannot instantiate a Revit Application. It is an application singleton and is instantiated by a Revit initialization procedure during Revit start-up. In other words – in order for you to use the Revit API, Revit must be launched and running.
Thanks for responding so quickly Arnošt, it's unfortunate that this isn't possible but I understand.