Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Revit Plugin With C# - Some Problems

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
jason.teagle
1819 Views, 6 Replies

Revit Plugin With C# - Some Problems

I'm trying to follow the tutorial for writing a Revit plugin located at http://usa.autodesk.com/adsk/servlet/index?siteID=123112&id=16849339

 

I'm using Revit 2013 as a trial version - not sure if that affects the user of plugins? 

 

The installer installed the 64-bit version of Revit (I appeared to have no choice, but that's not a problem as such). 

 

The version of Visual C# Express 2010 installed appears to also be a 64-bit version - Dependency Walker shows the DLLs as 64-bit, so the EXe must be as well. 

 

When I try to compile the sample given, I get warnings about architecture mismatch between the Revit DLLs and the build of my project. There appear to only be the 64-bit versions of the DLLs (makes sense, 64-bit Revit installed) and in Express you can't change the target architecture. 

 

How can I resolve this problem? 

 

If I try to load Revit and see if it recognises the DLL anyway (having put the correct path to the DLL I built into the manifest file which is stored under ProgramData/Autodesk/Revit/2013 as a .addin file as instructed, External Tools shows nothing. 

 

Any way I can find out whether it couldn't see any manifests (wrong location?), or whether it tried the DLL and fell over (mismatch in architecture)? 

 

Any other suggestions to get this working? 

 

Thanks in advance. 

 

6 REPLIES 6
Message 2 of 7

Hi Teagle,

 

The warning about the architecture should not be a problem. A typicaly .NET application is compiled with "Any CPU" mode but the RevitAPI and RevitAPIUI assemblies you reference from the Revit installed locations are targeted to the x64 platforms (if the installed revit version is 64 bit). So the compiler issues a warning about the mis-match. At runtime, Revit will resolve the dependent assemblies (API and APIUI) properly.

 

You could try a couple of things:

 

1) Try putting the .addin file in %appdata%\Autodesk\Revit\2013

2) Use the Process Monitor (http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx) tool to determine where Revit is looking for your application.

 

Hope this helps.

 

Best Regards,

Gopinath

 

 

Message 3 of 7

Thank you for this. In the end I was able to download a trial of Visual Studio 2010 Ultimate, which allowed me to change the target build to x64, to remove the warnings. Good to know that they wouldn't have caused a problem in the end, but that does suggest that if we want to target 32-bit and 64-bit Revit installations, then we are going to need separate C# projects with each having the correct references. This seems a bit of a maintenance issue?

 

One thing I found later was that the path you specify in the manifest file can't have spaces. I haven't tried the filespec enclosed in quotes yet (anyone know if that would work?), but for getting up and running I simply copied the DLL to a spaceless filespec.

 

Another thing I found was that if the Revit drawing you have loaded is in conceptual (or possibly shaded, can't remember) view, it doesn't acknowledge the plugin; quite by chance I later tried a drawing in wireframe mode and then it showed the plugin successfully. (I was using the default drawings in Revit, rather than the one from that tutorial, my own fault.)

 

I couldn't see anything in the manifest file that suggested wireframe only - is there something in there that only allows the plugin to show in certain drawing modes? I may well find ot the answer as I progress more through tutorials but I just wondered as I was here.

 

Thank you for your help.

 

Message 4 of 7

>> that does suggest that if we want to target 32-bit and 64-bit Revit installations, then we are going to need separate C# projects with each having the correct references. This seems a bit of a maintenance issue?

 

Gopinath: Not really. Unfortunately there is no clean answer for this. RevitAPI and RevitAPIUI are .NET assemblies and if they were pure CLR assemblies, the architecture would not matter. But Revit (like many other desktop applications) is essentially an unmanaged application exposing a .NET (managed) API. This means the Revit API assemblies have dependencies on unmanaged modules inside Revit Install. Depending on how carefully the API has been architected, you might be able to get away with referencing API assemblies targetted to one architecture and use your application on another. However, API keeps evolving and there is no guarantee that APIs will stay platform agnostic. Having said that, at least in terms of source code, you should be able to maintain a single source base for 32 and 64 bit platforms.

 

>> I haven't tried the filespec enclosed in quotes yet (anyone know if that would work?)

 

Gopinath: I have not found explicit documentation on this but double quotes should work. Please let us know if it does not.

 

>> is there something in there that only allows the plugin to show in certain drawing modes?

 

Gopinath: Yes, external commands are disabled in some contexts. Here is an explanation:

 

http://thebuildingcoder.typepad.com/blog/2009/06/rfa-version-grey-commands-family-context-and-rdb-li...

 

 

Hope this helps.

 

Best Regards,

Gopinath

 

 

 

Message 5 of 7

Thank you for some great information. I will push forwards with learing how to use Revit, how to manipulate objects, and what can be accomplished with plugins.

 

One last question:

 

Are plugins the only way to access Revit objects and functionality, or are there other mechanisms? In AutoCAD we would create ObjectARX DBX / ARX (for internally-sourced) or C# modules (for externally-controlled) that provided multiple commands in various groups and hierarchies, implementing our own menus (and possibly ribbon entries) to present the available functionality to the user. Thus, the modules could be loaded automatically at start-up through the user's profile, and they would have access to our complete range of functionality.

 

Is there some similar mechanism in Revit, whereby we could provide access to many related functions? We could obviously have one plugin per function but it wouldn't be a very coherent solution. Learing plugins is good, but I would hate to become skilled in them and find they aren't the most suitable method for our needs!

 

 

Message 6 of 7

Revit applications can use two architectures. Both are plugins. A external command Architecture and an external Application architecture:

 

http://wikihelp.autodesk.com/Revit/enu/2013/Help/00006-API_Developer's_Guide/0001-Introduc1/0018-Add...

 

http://wikihelp.autodesk.com/Revit/enu/2013/Help/00006-API_Developer's_Guide/0001-Introduc1/0018-Add...

 

Inside the same plugin, you can define multiple external commands. 

 

You cannot have a stand alone application to control Revit if that is what you are asking. I think you should allow yourself some time to understand the basics and go through the tutorials before deciding how to architect your application. Of course, you can always post a question here if you are confused.

 

Best Regards,

Gopinath

Message 7 of 7

The external application is the kind of thing I was hoping for.

 

Thank you for all your help, I will now go away and continue reading the tutorials.

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community