Add-in Migration to Revit 2016 and Updated Wizards

I updated my Visual Studio Revit C# and VB add-in wizards for Revit 2016.

Before presenting them, a quick important note on how to approach resolving issues that you may encounter migrating your existing add-ins:

Please Read What’s New in the Revit 2016 API!

Every major Revit API release so far enhanced the existing interfaces in various ways.

In order to optimise the developer experience, some of the improvements introduce incompatibilities; for instance, previously deprecated classes and interfaces are removed, and obsolete functionality may be marked as deprecated for removal in a future version.

Whenever you run into an issue migrating your code to newer versions of the API, the first place to look for a solution is in the What’s New section of the Revit API help file RevitAPI.chm.

This information is also published in a separate document in the Revit SDK, ‘Revit Platform API Changes and Additions.docx’.

To ensure that it is also picked up by web searches, I published it here on The Building Coder, together with the analogue information for previous releases:

<!–

Here is a typical example of how it might come in handy to provide a quick idea how to address a migration issue:

Question:
Can you confirm if the 2016 Revit API broke text vertical alignment?

There is a HorizontalAlignment property of the new TextNoteOptions when creating a text note (TextNote.Create), but there is no VerticalAlignment property.

Once the text note is created, there is a VerticalAlignment property, but it is read only.

The new API also broke the vertical alignment of the old .Create.NewTextNote method. I don’t see any way to control the vertical text alignment anymore in the 2016 version. Can you let me know if it is indeed broken or if I am just missing something?


  TextNoteOptions tno = new TextNoteOptions();
  tno.TypeId = TextTypeID;
  tno.Rotation = 0;
  tno.KeepRotatedTextReadable = false;
  tno.HorizontalAlignment = HorizontalTextAlignment.Left;
  tno.VerticalAlignment = VerticalTextAlignment.Bottom;
  TextNote tn = TextNote.Create( _
    CurrentDoc, CurrentView.Id, InsertionPoint, _
    LineWidth, "Test", tno);
  tn.VerticalAlignment = VerticalTextAlignment.Bottom;

Answer: As underlined above, the first place to look for hints on how to resolve migration problems is to search the What’s New section of the Revit API help.

In this case,

What’s New in the Revit 2016 API
provides
the following information on

TextNote and Leader API behavior and interface changes
:

  • TextElement.HorizontalAlignment – Horizontal alignment of the text content within the text box of the element.
  • TextElement.VerticalAlignment – Vertical alignment of the text content within the text box of the element.
    • Collectively, these two new properties replace TextNote.Align

–>

I hope this helps you tackle any issues you may run into migrating your add-in to the new release.

Good luck and have fun!

Revit Add-in Wizards for Revit 2016

On the other hand, if you are not migrating an existing Revit add-in, but creating a new one from scratch, the add-in wizards can be of use.

As said, I migrated my Visual Studio Revit add-in wizards to generate skeleton code for Revit 2016.

Visual Studio Revit add-in wizard for Revit 2016

The 2016 versions generate the same boilerplate snippets as the reliable old

Revit 2014

(updated)
and

Revit 2015
ones did.
Simply delete the parts that you do not need.

Since I am still using the pre-release version codenamed Copernicus, the Revit executable folder name targeted by the wizards is ‘Revit Copernicus’.

You may have to change that to something appropriate for your system, e.g. ‘Revit 2016’, ‘Revit 2016 Architecture’, etc.

Revit Add-in Wizard Customisation

It is important to understand how easy it is to modify the wizards for your own needs, and make copies with variations to support different requirements.

Here is an overview of previous explanations showing how to create your own flavours for various uses:

Revit Add-in Wizard Usage

Simply install the wizard zip files you need in the locations specified below, start up or restart Visual Studio, create a new C# or VB Revit add-in project using the wizard default settings.

<!–

Everything is set up fully automatically, so you can immediately hit F5 to perform the followng steps without changing a single thing:

compile, install and start up Revit.exe in the debugger.
–>

The wizards fulfil the following tasks for C# and VB, respectively:

  • Generate the skeleton source code, Visual Studio solution and add-in manifest.
  • On successful build, copy the add-in assembly DLL and add-in manifest to the Revit add-in folder, thus automatically installing it for Revit to pick up and load.
  • Define the add-in debugging settings to start up the Revit.exe program.

Therefore, right after the initial single-click add-in creation, you can immediately launch the debugger.
The add-in is compiled, Revit is started up, the add-in is loaded, you can select the new external command in the External Tools menu, launch and test it without entering one single further keystroke yourself.

The new command even executes in zero document state, although the default external command skeleton implementation throws an exception trying to access a property on the current UI document, which is null.
This is easy to fix in case you need a

zero document state external command
.
You can use this anyway to immediately check that everything is working correctly.

Download and Installation

The proper locations to install the wizards for Visual Studio to pick them up are language dependent.

Copy the zip file of your choice to the matching Visual Studio project template folder in your local file system:

Or, in other words:


$ cp /a/doc/revit/tbc/zip/Revit2016AddinWizardCs0.zip 
"/v/C/Users/tammikj/Documents/Visual Studio 
2012/Templates/ProjectTemplates/Visual C#"
$ cp /a/doc/revit/tbc/zip/Revit2016AddinWizardVb0.zip 
"/v/C/Users/tammikj/Documents/Visual Studio 
2012/Templates/ProjectTemplates/Visual Basic"

I hope you find this useful and look forward to hearing any suggestions for improvements you come up with.

Better still, implement them yourself and let us know where to pick them up :-)


Comments

18 responses to “Add-in Migration to Revit 2016 and Updated Wizards”

  1. Andrei Petre Avatar
    Andrei Petre

    Hi Jeremy,
    do you have any idea about the ResultsBuilder.dll (from Structural Toolkit for Revit 2016) being broken?
    I’m struggling to migrate one of our application to 2016 and it seems that the FEM results I’m pushing in the project are no longer available to explore (I’m using SetBarResult method, which was doing the job in 2015).
    Also, I’ve checked with the sample from the SDK and it’s no longer working, except for those results pushed with SetArbitraryResult method.
    Do you have any knowledge about this? Is there a workaround to this?
    Best regards,
    Andrei Petre

  2. Dear Andrei,
    Thank you for asking.
    I’m checking with the development team.
    Cheers, Jeremy.

  3. Dear Andrei,
    The SetBarResult method is marked as obsolete:
    http://thebuildingcoder.typepad.com/img/SetBarResult_obsolete.png
    You will have to redesign your add-in to use a newer method.
    Sorry about that.
    For any additional queries on this, I woulod suggest that you provide a reproducible case so we can explore it in more depth:
    http://thebuildingcoder.typepad.com/blog/about-the-author.html#1b
    Thank you!
    Cheers, Jeremy.

  4. Andrei Petre Avatar
    Andrei Petre

    Hi Jeremy,
    indeed is marked as obsolete the SetBarResult method that’s receiving a string as resultType, but not the one receiving LinearResultType (see in your attached image).
    As for a reproducible sample, you can use the “StoringResults” sample from Revit SDK 2016\Structural Analysis SDK, together with its revit project “ResultsInRevit.rvt”.
    You’ll notice that the same sample is working in Revit 2015, but not in 2016; in 2016 only the “Other” result are shown in Results Explorer dialog.
    Regards,
    Andrei

  5. emmanuel weyermann Avatar
    emmanuel weyermann

    Hi Andrei,
    In the SDK sample, following code is used
    ResultsPackageBuilder resultsPackageBuilder = resultsAccess.CreateResultsPackage(packageGuid, “ResultsInRevit”, UnitsSystem.Metric, ResultsPackageTypes.All);
    In this case, the results package could contains any type of results and they are classified as “others” in Results explorer
    If your results are static one, your result package must be created using ResultsPackageTypes.Static , then they will be exposed properly in Result explorer

  6. Andrei Petre Avatar
    Andrei Petre

    Hi Emmanuel,
    thank you very much!
    That did the trick.
    After, a couple of hours of late night investigations, I saw the change: the results explorer is no longer loading all the results at once, but loading them in a switch by the resultspackagetype, which is wrongfully leaving out the All type. This should be done with boolean bitwise operations.
    So, although in the previous version was not quite ok, in the current one is wrong.
    Indeed it’s always loading the arbitrary results and puts them into the Other node of the tree, but for these is not considering any LinearResultType, SurfaceResultType and more.
    Hope this will be corrected.

  7. emmanuel weyermann Avatar
    emmanuel weyermann

    Hi Andrei,
    if you don’t want to see arbitrary results flagged as other in Results Explorer, you need to create a second package for them (i.e if you would like to expose reinforcement results)
    Thanks
    Emmanuel

  8. Andrei Petre Avatar
    Andrei Petre

    Hi Emmanuel,
    I’ve realized that for pushing a different kind of results, I have to created a different package, but the current implementation is making All value from ResultsPackageType obsolete.
    Thanks and regards,
    Andrei

  9. Jack Tilley Avatar
    Jack Tilley

    Hi Jeremy,
    I am new to coding the Revit API and Starting with the 2016 edition is creating problems for me as a newcomer.
    I am trying to add a Parameter to a project by adding parameters from a shared parameter file and binding them to a category by name.
    I was using this code as a starting point point but hitting a no overload error, presumably because of changes in the API.
    http://help.autodesk.com/view/RVT/2014/ENU/?guid=GUID-C02B4263-E916-4705-A9B8-1715A526081E
    As I am a beginner using revit I am not yet comfortable using the Shared Parameter changes and would appreciate any help I can get to jump-start.
    Thank you,
    Jack

  10. Jack Tilley Avatar
    Jack Tilley

    https://github.com/jeremytammik/RevitLookup/blob/master/CS/Test/SDKSamples/FireRating/SharedParam.cs
    Apologies, Jeremy I sorted my problem out thanks to your use of the ExternalDefinitionOpitions class in this.
    Thank you,
    Jack

  11. Dear Jack,
    Thank you for letting us know and congratulations on sorting it out!
    Cheers, Jeremy.

  12. Vipul Surana Avatar
    Vipul Surana

    Hello Jeremy,
    I have to make a WPF form plug-in, where form is having a Infragistics grid that will fetch the data from Revit, how to achieve it ?
    In layman terms, when I go to External Tools, I click on the addin / plugin, and the WPF form opens with Infragistics Grid having the data of current project.
    Can you please tell me something about this ?

  13. Dear Vipul,
    Here is a description of creating and populating a .NET grid form on the fly:
    http://thebuildingcoder.typepad.com/blog/2014/06/the-revision-api-and-a-form-on-the-fly.html
    I cannot say anything at all about Infragistics, never having heard of it before.
    Cheers, Jeremy.

  14. Vipul Surana Avatar
    Vipul Surana

    Hello Jeremy,
    Thanks for the reply.
    But, here comes another problem before having a look over above url.
    I created a HelloWorld.dll and added it as plugin in Revit 2016, working successfully.
    Problem: I want to debug the code (well it’s just 2 lines for now) but Revit 2016 is opened and closed at the time I run my VS class library.
    I have given proper path name as to run external command.
    Need your inputs on this.

  15. Vipul Surana Avatar
    Vipul Surana

    Explored more of your blogs, got the answer.
    Compatibility Mode in VS 2013 did the trick.
    Heartily thanks for all of your blogs.

  16. Vipul Surana Avatar
    Vipul Surana

    Hello Jeremy,
    I didn’t understand the example completely. (http://thebuildingcoder.typepad.com/blog/2014/06/the-revision-api-and-a-form-on-the-fly.html)
    I have questions like: which file are you talking about ? there is no namespace and the filename + extension.
    I am a very layman person, just started working 4 days before on Revit 2016.
    Need to ask you how to get started with creating a solution (class library / usercontrol library / wpf application) and connect with Revit, there are no proper guidelines for this.
    Can you make a layman blog post for me and for the starters.
    I am very desperate to learn this tech.

  17. Dear Vipul,
    Thank you for your appreciation!
    I am very glad you solved it.
    Thank you for letting us know.
    Cheers, Jeremy.

  18. Dear Vipul,
    You will be very happy to hear that we have already created a full set of getting started material:
    http://thebuildingcoder.typepad.com/blog/about-the-author.html#2
    I guarantee that it covers all your needs :-)
    Cheers, Jeremy.

Leave a Reply

Discover more from Autodesk Developer Blog

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

Continue reading