Visual Studio 2010 and the .NET Framework

In section 1.6 ‘Supported Programming Languages’, the developer guide “Revit 2011 API Developer Guide.pdf” in the Revit SDK clearly states that “The Revit Platform API is fully accessible by any language compatible with the Microsoft .NET Framework 3.5, such as Visual Basic .NET or Visual C#.”

In section 1.3 ‘Requirements’, it also mentions that the programming environment recommended for going through the examples is Visual Studio 2008.
That is also the environment used to create and compile all the SDK samples.

We already once mentioned the possibility of using and debugging with

Visual Studio 2010
.
Questions on this have been coming up more frequently recently.
Here is one fundamental issue in connection with use of this version, with a clear and succinct answer by Joe Ye:

Question: I am having difficulty getting my VB Revit plug-in application to run with the Revit 2011 API when using Visual Studio 2010.
Just to keep things simple, I went back through the HelloWorld tutorial just in case I was missing something.
The HelloWorld add-in shows up correctly in the external tools drop down menu during debugging, but nothing happens when it is selected.
The code does not appear to be executing.

I added the references and namespaces, and set the ‘copy local’ flag to false for the Revit API assemblies.
Still no luck.

Maybe there is some problem with the add-in manifest file, but I cannot figure it out.
I also substituted a new GUID just in case there was a duplicate, but with no luck.

Here is the VB code that I am using to test with, in HelloWorld.vb:


Imports System
Imports Autodesk.Revit.UI
Imports Autodesk.Revit.DB
 
Public Class HelloWorld
    Implements IExternalCommand
    Public Function Execute( _
      ByVal revit As ExternalCommandData, _
      ByRef message As String, _
      ByVal elements As ElementSet) _
      As Autodesk.Revit.UI.Result _
      Implements IExternalCommand.Execute
 
        TaskDialog.Show("Revit", "Hello World")
        Return Autodesk.Revit.UI.Result.Succeeded
 
    End Function
 
End Class

This is my add-in manifest file HelloWorld.addin:


<?xml version="1.0" encoding="utf-8" standalone="no"?>
<RevitAddIns>
  <AddIn Type="Command">
    <Assembly>C:...HelloWorldbinDebugHelloWorld.dll</Assembly>
    <AddInId>8983a66d-3a78-4db8-b88b-e5c92bf04644</AddInId>
    <FullClassName>HelloWorld.HelloWorld</FullClassName>
    <Text>HelloWorld</Text>
  </AddIn>
</RevitAddIns>

What can be wrong, please?
Please help.

Answer: The recommended version of Visual Studio is 2008.
Revit 2011 does not support the .NET framework 4.0, which is used by default in Visual studio 2010 to compile the plug-in.

This might be causing an issue.
Please change the compilation settings to use the .NET framework 3.5 or an earlier version and see if that works.

Response: That solved the problem.
Thanks!


Comments

7 responses to “Visual Studio 2010 and the .NET Framework”

  1. Hi Jeremy,
    Does this post meant that selecting 3.5 instead of the default 4.0 clears most issues regarding VS2010, or have other issues come up? Warm regards from Los Angeles,
    Emmanuel

  2. Benjamin Golder Avatar
    Benjamin Golder

    Any chance of demonstrating how to change the compilation settings in VS 2010 for us beginners?
    Thanks!
    Ben

  3. Hi Ben,
    Nope, not from me, yet, anyway; I am still using Visual Studio 2008 myself, the officially supported version.
    I will probably install 2010 in the very next week or two, though … maybe then :-)
    Cheers, Jeremy.

  4. morgan Avatar
    morgan

    Hi Jeremy
    I am getting the following error message every time I open Revit 2011:
    External Tools – Duplicated AddInId
    Failed to initialize the add-in “Class1” because an application already exists with this AddInId node.
    The AddInId node is a Globally Unique Identifier (GUID) used to identify the add-in application. Revit already has an application registered with the indicated GUID.
    with my addin. I think I understand what it means so to fix it I removed all addins from the relevant folder but the message won’t go away. It seems something else is starting the addin or it has never stopped but I looked for it in the process tab of task manager and could see no sign of it!
    Any help would be greatly appreciated.
    Morgan

  5. Dear Morgan,
    It is impossible for you to receive this message if you really remove all add-ins and shut down and restart Revit again.
    I therefore assume that you did not succeed in removing them all.
    Regardless of that, this message is telling you that some add-in id was duplicated. That is the GUID listed in the AddInId tag in the example above. The tag may also be named ClientId instead of AddInId.
    There are lots of ways to fix this, but they all require you to find the offending add-in manifest first.
    Depending on your operating system it should be in one of the following locations:
    For a specific user:
    For Windows XP – C:\Documents and Settings\Application Data\Autodesk\Revit\Addins\2012
    For Vista/Windows 7 – C:\Users\AppData\Roaming\Autodesk\Revit\Addins\2012
    For all users:
    For Windows XP – C:\Documents and Settings\All Users\Application Data\Autodesk\Revit\Addins\2012
    For Vista/Windows 7 – C:\ProgramData\Autodesk\Revit\Addins\2012.
    Look at the following post for more details and an explanation on how to generate a new unique id:
    http://thebuildingcoder.typepad.com/blog/2010/04/addin-manifest-and-guidize.html
    Cheers, Jeremy.

  6. Is it possible to control Revit externally from a C# written windowsForm program? I’d like to open Revit, import a SAT file, save it as an RFA, and then close everything. As you can see, it’s not an add-in! If this can be done, do you have any example code?
    Thanks very much,
    Alex
    Toronto Canada

  7. Dear Alex,
    Not directly. This can easily be achieved using a journal file, though. Please loot at this solution:
    http://thebuildingcoder.typepad.com/blog/2010/07/ifc-import-and-conversion-journal-script.html
    Happy New Year to you!
    Cheers, Jeremy.

Leave a Reply to AlexCancel reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading