Trying to access Revit COM from Console Application using C#.net

Trying to access Revit COM from Console Application using C#.net

Anonymous
Not applicable
1,871 Views
5 Replies
Message 1 of 6

Trying to access Revit COM from Console Application using C#.net

Anonymous
Not applicable

I'm writing a console application in C#.net and I was hoping to access the Revit API's by including them as references.  I can code OK (all the autocorrect works and finds the contents of the libraries), but when I run the code, it crashes saying I have a x86 or x64 issue.  I found other pages showing how to resolve this, but nothing seems to work for me (in either 32- or 64-bit configurations ) 

 

But my question isn't really how to resolve that, but rather why am I getting this error?  I'm working with all 64-bit API's, so why is there any issue?  I would think that referencing a 64-bit Revit API on a 64-bit console application would be compatible. 

 

So, can I even access the Revit COM from a console application? 

 

And, if I can access Revit, how can I get rid of this x64 x86 issue? 

0 Likes
1,872 Views
5 Replies
Replies (5)
Message 2 of 6

gopinath.taget
Alumni
Alumni

Hello,

 

Can you please give more information on the actual issue? i.e., is there an error message or exception message?

 

Revit does not have a COM API anymore so I am not sure how you are using the Revit API in an external application.

 

More details about the what you are doing with the API would help.

 

Best Regards

Gopinath

0 Likes
Message 3 of 6

Anonymous
Not applicable
Few questions come to mind: Have you tried copy local = false for both dlls? Are you running the correct .NET framework version ?
0 Likes
Message 4 of 6

Anonymous
Not applicable

I guess if there is no COM API, then that resolves the issue. Any reasons why they don't have COM access?  Seems like a terrible lack of functionality. 

 

Just to confirm, something like this isn't possible:

 

            Autodesk.Revit.ApplicationServices.Application RevitApp;
            RevitApp = (Autodesk.Revit.ApplicationServices.Application)Marshal.GetActiveObject("REVIT.Application");

 

I'm using 4.0 .net. 

 

 

0 Likes
Message 5 of 6

gopinath.taget
Alumni
Alumni

Hello,

 

There was a COM based API for Revit many releases ago but we do not have one anymore. The supported API is a .NET API and it has to run in-process inside Revit. If you could describe what you are trying to achive, I may be able to suggest some alternatives.

 

Best Regards

Gopinath

0 Likes
Message 6 of 6

Anonymous
Not applicable

There isn't much to say, since if you say COM access is impossible, then I don't have any recourse.  I'm trying to create a C# console Application.  That won't work without COM access. 

 

Strange, I can access CATIA and Rhino without issue.  This is a bummer that Revit isn't as useful in this sense.  I'd much rather code my stuff in a simple-to-use EXE, rather than have my clients try and install the crappy addin stuff into their session of Revit. 

 

Moving forward, I'll just have to recompile my code as a Revit plug-in, and access CATIA and Rhino via COM from Revit.  I assume that is doable.