Accessing model information without needing to open Revit

Accessing model information without needing to open Revit

Anonymous
Not applicable
726 Views
2 Replies
Message 1 of 3

Accessing model information without needing to open Revit

Anonymous
Not applicable

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

 

0 Likes
Accepted solutions (1)
727 Views
2 Replies
Replies (2)
Message 2 of 3

arnostlobel
Alumni
Alumni
Accepted 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.

Arnošt Löbel
0 Likes
Message 3 of 3

Anonymous
Not applicable

Thanks for responding so quickly Arnošt, it's unfortunate that this isn't possible but I understand.

0 Likes