Plug-In Migration Steps
We discussed the
migration of The Building Coder samples from
the Revit 2010 to the Revit 2011 API and noted some of the required steps there, but skipped a lot of the obvious and onerous detailed information.
Luckily, my colleague Joe Ye was more patient and precise when he migrated our Revit Structure labs and analysis link sample, and kept track of the required steps in great detail.
So, without further ado, here are Joe's Revit 2011 plug-in project migration notes:
Steps to migrate Revit 2010 code to Revit 2011
Before migrating the code, please read the What's New section in the Revit API help file RevitAPI.chm file to know what happened in the API.
Then follow below steps.
- Open the Revit code project in Visual Studio 2008.
- Remove the reference to old Revit API assembly RevitAPI.dll.
- Reference the new Revit API assemblies RevitAPI.dll and RevitAPIUI.dll, which are located in the Revit 2011 installation Program subfolder.
- Replace old namespaces with the new ones, for example:
All namespace mappings are documented in 'Revit 2011 API Namespace Remapping.xlsx' file in SDK.
- Decide what regeneration option and transaction mode are required for the external command or application classes.
This is a non-trivial decision, cf.
manual regeneration option risks and
- Add the regeneration option and transaction mode attributes, e.g.
[Transaction( TransactionMode.ReadOnly )]
[Regeneration( RegenerationOption.Manual )]
- If you have used full class names, change the namespace of the IExternalCommand or IExternalApplication interfaces, ExternalCommandData class, and Result enumeration to Autodesk.Revit.UI.
- The way to access the Application and Document instances changed.
The command data argument now returns a new UIApplication class instance.
Use the following code to access the database level application and active document objects:
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Application app = uiapp.Application;
Document doc = uidoc.Document;
In Revit 2010, there was no separation between the user interface and database level application and document objects.
The application was accessed through the ExternalCommandData.Application property, and the active document through ExternalCommandData.Application.Document.
- If the project has element iteration processes, you need to migrate these to use the new FilteredElementCollector class.
Please refer to RevitAPI.chm and Revit 2011 API developer guide.pdf for detailed information.
- Some classes were renamed. Please read the What's New section in RevitAPI.chm for detailed information, and replace the old class names with the ones.
- Creating a new ElementId instance requires an argument, unlike Revit 2010.
- The Document get_Element( ElementId ) method now takes an ElementId argument without the ref keyword, because ElementId is a class now.
- TypeFilter changed to ElementClassFilter. Creating instance change to use New ElementClassFilter
- CategoryFilter becomes ElementCategoryFilter. Other element filter class are also renamed.
- Access to the Revit Structure analytical model changed.
- The ElementId Value property changed to IntegerValue, so replace with the new property name.
- When retrieving document elements, we need to set a filter explicitly. If no filter was set at all, an exception is thrown.
- If the command is using the manual regeneration option and the code makes changes to the model, we need to explicitly create a transaction to update the model:
Transaction t = new Transaction(
doc, "Test" );
. . .
- Some other detailed items are not listed here.
Please refer to the API changes documentation for further information.
Many thanks to Joe for these detailed instructions!