DevTV Add-In Templates

Here are the add-in templates prepared by my colleague Augusto Gonçalves of Autodesk Brazil for the upcoming DevTV presentations.

I really love both the implementation and the description, both are so short and sweet and yet complete!

They save you a lot of typing and clicking when setting up a new add-in, and especially help avoid all the potential errors that insist on creeping in when you set things up manually.
Support is provided for both external commands and external applications.

These are the same templates we used during DevCamp, but with several changes and improvements, especially on the add-in manifest file creation.

How to use

Installation could hardly be simpler.
No need to unzip, just save the following two files in the specified locations on your local system:

You obviously replace ‘2008’ by ‘2010’ for Visual Studio 2010.

Benefits

  • Works on all versions of VS, including Express.
  • Simple project with one ExternalApplication and one ExternalCommand, plus commonly used namespaces.
  • References to Revit assemblies (RevitAPI and RevitAPIUI) with Copy Local set to False.
  • Debug features configured and enabled (important for Express version).
  • Creates the required .addin including the

    add-in manifest ClientId
    ,
    copies it to the appropriate RevitAddins2011 user specific folder (through post-build events) and deletes it again during Clean (through after-clean event), e.g. on using Visual Studio Build > Clean Solution.
    The <Assembly> mark is initially created with the BinDebug build.

Weaknesses

  • The references path is partially hard coded, so Revit *must* be under [Program Files]AutodeskRevit Architecture 2011 (or the template requires changes).
  • As the path is hard coded, it does not work for other flavours. The workaround is create a separate template for each flavour (easy, just change the path).
  • Visual Express (only this version) creates the project at a temporary location (“as designed”), therefore the .addin file requires manual edit on the <Assembly> mark.

Example

The Visual Studio IDE will automatically detect, pick up and unpack the files when they are present in these directories, so the full functionality is available immediately after they have been placed there.
When you next create a new project, the template is presented for selection:

DevTV template in new project dialogue

The newly created project is fully populated with the Revit API references, a sample command, application, and add-in manifest file:

DevTV template project contents

It is immediately ready for compilation.
On successful compilation, the

add-in manifest

is created and copied to the proper location:

DevTV template project build output

Here is the build output in text format (copy to an editor to see the truncated lines):


------ Rebuild All started: Project: RevitNETAddin2, Configuration: Debug Any CPU ------
c:WINDOWSMicrosoft.NETFrameworkv3.5Csc.exe /noconfig /nowarn:1701,1702 /errorreport:prompt /warn:4 /define:DEBUG;TRACE /reference:"C:Program FilesAutodeskRevit Architecture 2011ProgramRevitAPI.dll" /reference:"C:Program FilesAutodeskRevit Architecture 2011ProgramRevitAPIUI.dll" /reference:"c:Program FilesReference AssembliesMicrosoftFrameworkv3.5System.Core.dll" /reference:c:WINDOWSMicrosoft.NETFrameworkv2.0.50727System.Data.dll /reference:c:WINDOWSMicrosoft.NETFrameworkv2.0.50727System.Deployment.dll /reference:c:WINDOWSMicrosoft.NETFrameworkv2.0.50727System.dll /reference:c:WINDOWSMicrosoft.NETFrameworkv2.0.50727System.Drawing.dll /reference:c:WINDOWSMicrosoft.NETFrameworkv2.0.50727System.Windows.Forms.dll /reference:c:WINDOWSMicrosoft.NETFrameworkv2.0.50727System.Xml.dll /debug+ /debug:full /filealign:512 /optimize- /out:objDebugRevitNETAddin2.dll /target:library Application.cs Commands.cs PropertiesAssemblyInfo.cs
Compile complete -- 0 errors, 0 warnings
RevitNETAddin2 -> C:adocrevitdevtvtestRevitNETAddin2RevitNETAddin2binDebugRevitNETAddin2.dll
copy "C:adocrevitdevtvtestRevitNETAddin2RevitNETAddin2RevitNETAddin2.addin" "C:Documents and SettingstammikjApplication DataAutodeskREVITAddins2011RevitNETAddin2.addin"
1 file(s) copied.
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========

On cleaning the solution, the add-in manifest file is removed again, so that Revit does not complain about the missing add-in assembly DLL.


Comments

20 responses to “DevTV Add-In Templates”

  1. Zhu Xiaomeng Avatar
    Zhu Xiaomeng

    Hi, Jeremy:
    First , Thank you for your reply to the interference question. It’s so encouraging. I’m not single in the battle.
    Second , I have a new problem , How to create In-place Family Instance programly?

  2. Dear Zhu Xiaomeng,
    I am sorry to say that there is no API access to create an in-place family.
    You can however create a new family document in memory using the Application NewFamilyDocument method, populate that with the required elements, and load an instance of it into your project, all without ever saving it to disk.
    Cheers, Jeremy.

  3. Jeremy,
    I’m going to modify my old RevitIniFileEntries console routines to open the .addin file and replace the hardcoded path with the [InstallLocation] of an AddIn. This is a workaround because nobody can tell me how to use the RevitAddinUtility.dll in a console app to write the .addin file directly from within an installer. the example uses a Windows form app with buttons, which is totally useless for installations (where the RevitAddinUtility.dll needs to be used). I’ll let you know when it’s done.

  4. Dear Jim,
    Please have a look at the discussion in the comments section of
    http://thebuildingcoder.typepad.com/blog/2010/05/revitaddinutility-for-32-and-64-bit-systems.html
    From that, I get the strong impression that the RevitAddinUtility.dll can be used perfectly well from any kind of .NET application, including an installer and a console app.
    Still, if you prefer going your own way, I will be very interested to hear and see the results, and of course share them with the community if that is what you would like.
    Thank you!
    Cheers, Jeremy.

  5. Jeremy,
    I have tried using this addin template, Is it possible to use it to create .addin files as a process or is it just a reference material to show how to use it? I noticed it allows me to save the project as something else, but i can’t seem to get the newly generated addin file to run or show up when i launch revit! I wonder if I am missing something which i should know about?

  6. Dear Jenny,
    I suggest that anybody who wants to make use of these templates first learn the basics of creating and installing and launching and debugging a minimal Revit add-in by hand. You can learn the basics of the Revit API very efficiently by downloading the Revit SDK, looking at Chapter 2, Walkthroughs, and working through the DevTV recordings. All of these are available on the Revit Developer Center:
    http://www.autodesk.com/developrevit
    That will answer all your questions much more completely than I can do here.
    Please also note that I later posted my personalised updated versions of the DevTV templates:
    http://thebuildingcoder.typepad.com/blog/2010/10/revit-2011-devtv.html
    Cheers, Jeremy.

  7. alvares Avatar
    alvares

    Dear Jeremy,
    thank you very much for this template, it really helps making the process smoother.
    one problem though, i converted a while ago to Visual Studio 2010 and the template does not work with it anymore.
    i have followed the template migration guideline(http://msdn.microsoft.com/en-us/library/cc512930.aspx)
    the the VS conversion wizard can’t seem to find the “Microsoft.VsSDK.targets” files!!
    i would really appreciate your help in this matter

  8. Dear Alvares,
    I asked Augusto, who originally created these templates, and he says:
    The template should work ‘as is’, and it does.
    All you have to do is copy the .zip files from:
    My Documents\Visual Studio 2008\Templates\ProjectTemplates\Visual C#
    To:
    My Documents\Visual Studio 2010\Templates\ProjectTemplates\Visual C#
    The same obviously applies for VB.NET.
    Cheers, Jeremy.

  9. Stephen Lecompte Avatar
    Stephen Lecompte

    Jeremy,
    Thank you very much for providing the DevTV Add-In Templates. I’m still struggling just a bit with them to get them to fully work properly.
    At work we exclusively have Revit 64-bit only and when I utilize the template- I have to keep changing the paths that are default to the debugging location for Revit.exe as well as the reference locations to the RevitAPI.dll and RevitAPIUI.dll.
    when I look at the TemplateRevitCS.csproj that is a part of the .zip package, I see this as:
    $(ProgramFiles)\Autodesk\Revit Architecture 2011\Program\Revit.exe
    But whether I keep it as the above or change it to…
    C:\Program Files\Autodesk\Revit Architecture 2011\Program\Revit.exe
    The debug location still comes up as C:\Program Files (x86)\Autodesk\Revit Architecture 2011\Program\Revit.exe
    But in reality my location is:
    C:\Program Files\Autodesk\Revit Architecture 2011\Program\Revit.exe
    So once I utilize the template – then go to Project – Properties – Debug section and manually browse to that location then the project debug location is fine.
    Then I have to go to the Reference section of my solution – where I see RevitAPI and RevitAPIUI with a yellow exclamation mark and have to re-assign such as well to C:\Program Files instead of C:\Program Files (x86).
    You can also note as part of looking at the .csproj file provided – it shows:
    False
    $(ProgramFiles)\Autodesk\Revit Architecture 2011\Program\RevitAPI.dll
    False
    Which above is stating that its 32-bit via the x86. So I thought I could merely change the x86 to x64 and save the file but that didn’t work successfully either.
    Could you either re-post adjustments to the template files to get it to work with an exclusive install of 64-bit Revit? I’m just learning and do not know how to correctly edit such templates for Visual Studio?

  10. Stephen Lecompte Avatar
    Stephen Lecompte

    For some reason it was cut off but…
    but right above where RevitAPI.dll is declared it lists…
    Reference Include=”RevitAPI, Version=2011.0.0.0, Culture=neutral, processorArchitecture=x86″
    and the x86 would designate 32-bit only.

  11. Dear Stephen,
    I do not understand this second comment of yours. Do you mean to say that you found a solution? If so, what is it? If not, what are you saying, please?
    Cheers, Jeremy.

  12. Stephen Lecompte Avatar
    Stephen Lecompte

    No sorry about that – I still do not have a solution.
    I was trying to show you what was inside the TemplateRevitCS.csproj template file for Reference Include = but it got cut off because of the less than/greater.
    So I tried to remove the symbols so that the statement would appear on your blog. But please take a look at the text file and note where TemplateRevitCS.csproj has the statement of reference include =
    I’m not familiar with editing template files but perhaps Augusto could create another for one who has 64-bit Revit installed only? The point I was making that its more than just changing locations of the files but processorArchitecture would also need to be changed to 64-bit as well.

  13. Stephen Lecompte Avatar
    Stephen Lecompte

    OK, I did eventually find a solution to my problem where I do not have 32-bit Revit version installed but only 64-bit Revit.
    After downloading the winzip file above…
    1.) extract the contents
    2.) Within the .csproj file…
    a.) do a find/replace on $(ProgramFiles) and replace with C:\Program Files
    b.) find any instances where processorArchitecture=x86 and replace with processorArchitecture=x64
    3.) delete the old winzip file
    4.) finally create a new .zip that combines all the files completed.
    My initial problem was that I forgot to delete the original winzip even though I made the appropriate changes.

  14. Dear Stephen,
    Congratulations on solving this!
    Thank you very much for the explanation!
    It sounds pretty straightforward, in the end. I guess it mostly does, once you know how it goes. And of course you made it extra hard for yourself :-)
    If you would like to send me your resulting template zip file, I can add it to the post.
    Thank you!
    Cheers, Jeremy.

  15. Marcelo Bernal Avatar
    Marcelo Bernal

    Hi Jeremy,
    Do you have the template for Revit 2012?
    Can the current template be used in 2012?
    thanks
    Marcelo

  16. Dear Marcelo,
    Thank you for a very pertinent question.
    I already answered it:
    http://thebuildingcoder.typepad.com/blog/2011/04/visual-studio-add-in-wizards-for-revit-2012.html
    Cheers, Jeremy.

  17. Hi Jeremy,
    I really need your help, I am currently starting to learn Revit Architecture 2011.
    I dont have anything in my addins,
    So this could be my problem why there are a lot of missing tabs in my revit.
    i.e. There’s no “workset” and “design options” in my “visibility/graphic overrides” dialog box.
    Hope you can help me with this.

  18. Marcelo Bernal Avatar
    Marcelo Bernal

    Hi Jeremy,
    I got the 2012 template, and it seems to be working. However, after every change in my code I need to close Revit, build again my code, and re-start Revit. Although the manifest file is automatically created saving a lot of time and the cleaning function works, the re-building my code is taking too much time since I need to re-start Revit every time.
    I’m new in the Revit API environment. Do you know how to avoid re-starting revit after every change in the code? It is really time consuming.
    I have windows 7 64 bits, Revit is installed in C:\Program Files\Autodesk…… , and the addin Manager is install in C:\Program FIles (x86)\Autodesk\Add-In Manager for Autodesk Revit 2012. The previous version of the template (2011) said something about the path dependency of the template. Should I edit any path in the template? Should I save my projects always in MyDocuments\Visual Studio 2010\Projects?
    If I solve this limitation I’ll save a lot of time.
    thanks, and happy late Eastern
    Marcelo

  19. Dear Gabby,
    No, I cannot really help with that at all. It sounds to me as if you have some kind of installation or setup problem. I deal with the API and nothing but that.
    Cheers, Jeremy.

  20. Dear Marcelo,
    The behaviour you are seeing is normal, I’m afraid (snafu).
    I hope that all your questions are answered in full by this recent blog post:
    http://thebuildingcoder.typepad.com/blog/2011/05/debugging-an-add-in-without-restarting-revit.html
    Cheers, Jeremy.

Leave a Reply to Stephen LecompteCancel reply

Discover more from Autodesk Developer Blog

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

Continue reading