I started migrating The Building Coder samples to Revit 2014. Funnily enough, on the exact same date as last year for the previous version.
The changes are very small this time around.
Furthermore, I am well prepared, since I recently intentionally eliminated all compiler warnings and deprecated calls compiling the code for Revit 2013.
First, however, a picture or three from my ski tour last weekend over Il Chapütschin (3386 m) and La Sella (3584 m) in the Swiss Engadin. Here I am on the first summit:
The panorama is grandiose:
We arrive back at the hut tired and happy:
Migrating The Building Coder Samples to Revit 2014
Back at the desk and steeped in the Revit API, Here is what I have done so far to migrate The Building Coder samples from Revit 2013 to Revit 2014:
- Update the Revit API assembly references
- Remove obsolete Collections namespace and RoomCreationData class
- TopographySurface namespace changed
- Some unit API changes
- Initial Revit 2014 version
Update the Revit API Assembly References
Every Revit add-in needs to reference the API assemblies.
They now live in the main Revit installation folder, together with Revit.exe.
In my case, this folder is "C:\Program Files\Autodesk\Revit Architecture 2014", and I am referencing the three assemblies RevitAPI, RevitAPIUI and UIFrameworkServices.
Just updating the references and recompiling generated 5 errors and 3 warnings.
Remove Obsolete Collections Namespace and RoomCreationData Class
Four of the five errors say "The type or namespace name 'Collections' does not exist in the namespace 'Autodesk.Revit' (are you missing an assembly reference?)".
To my surprise, I did indeed have several obsolete statements like this left over from previous versions:
using Autodesk.Revit.Collections;
They were actually not required at all by the Revit 2013 compilation, just left over from still older versions.
The fifth warning is similar, saying "The type or namespace name 'RoomCreationData' does not exist in the namespace 'Autodesk.Revit.Creation' (are you missing an assembly reference?)", and could also be resolved simply by removing this obsolete using statement:
using RoomCreationData = Autodesk.Revit.Creation.RoomCreationData;
Removing these erroneous using statements enables the compilation proper to execute and raises the number of problems reported to 3 errors and 108 warnings.
Just three errors! Looking good...
TopographySurface Namespace Changed
Now we hit some real errors caused by slight shifts and redefinitions in the API.
The first error is in CmdLandXml.cs:
TopographySurface surface
= doc.Create.NewTopographySurface( pts );
It says "The type or namespace name 'TopographySurface' could not be found (are you missing a using directive or an assembly reference?)".
The TopographySurface class apparently moved from one namespace to another. In Revit 2013, it lived in Autodesk.Revit.DB.
This is easily remedied by placing the cursor over the offending class name and pressing Ctrl + '.', which brings up a menu listing the fully qualified class name and offering to automatically correct the error for you:
Some Unit API Changes
The other two errors refer to units, one of the few areas seriously modified in the Revit 2014 API, and say:
- 'Autodesk.Revit.DB.Document' does not contain a definition for 'ProjectUnit' and no extension method 'ProjectUnit' accepting a first argument of type 'Autodesk.Revit.DB.Document' could be found (are you missing a using directive or an assembly reference?)
- 'Autodesk.Revit.DB.FormatOptions' does not contain a definition for 'Units' and no extension method 'Units' accepting a first argument of type 'Autodesk.Revit.DB.FormatOptions' could be found (are you missing a using directive or an assembly reference?)
They are caused by the following lines in ParameterUnitConverter.cs:
FormatOptions fo = document.ProjectUnit .get_FormatOptions( ut ); DisplayUnitType dut = fo.Units;
They are easily fixed by using the following new methods and properties:
FormatOptions fo = document.GetUnits() .GetFormatOptions( ut ); DisplayUnitType dut = fo.DisplayUnits;
We are left with zero errors and 111 warnings, which we will leave to deal with another day.
Initial Revit 2014 Version
So here is the result, the very first version 2014.0.100.2 of The Building Coder samples for Revit 2014.
To compare with the last version for Revit 2013, look at the version 2013.0.100.2 that I provided after eliminating all compiler warnings and deprecated calls.
Hi Jeremy,
In your buiding coder samples, there is a command for create a new project document. In my case, I would like to create a new project document from my own revit template.I managed to create new project document if revit template file is a separate file from dll. My problem is I want to embedded revit template file into Resource in IDE.
Posted by: abby | June 19, 2013 at 06:11
Dear Abby,
That sounds pretty cool.
However, the only method available to you is the Application NewProjectDocument method taking a filename argument.
So the only option is see for you is to extract your embedded resource to a temporary location and pass it a valid temporary filename.
Cheers, Jeremy.
Posted by: Jeremy Tammik | June 19, 2013 at 06:27
Hi Jeremy,
Thank you for your help.It's solve my problem.
Abby
Posted by: abby | June 23, 2013 at 22:43
Dear Abby,
Thank you for your update and appreciation.
Glad it helped!
Cheers, Jeremy.
Posted by: Jeremy Tammik | June 27, 2013 at 08:02
Hi Jeremy!
I'm having some troubles installing your samples.
First of all i am a nob in this Revit API, but trying to learn.
I have already installed the revit Samples that come with the SDK, and followed your instructions regarding the include statement in the end of the RVTSamples.txt, and also changed the path within the BcSamples.txt to address my BuildingCoder.dll location. I build successfully in visual studio, but when i open Revit your samples don't show up.
Can you tell me what i am doing wrong?
I also noted that the Revit Samples buttons aren't all available, do you have any idea why?
Rui Gavina
Posted by: Rui Gavina | November 12, 2013 at 07:34
Dear Rui,
I am glad hear you are learning the Revit API.
Sorry to hear about your troubles, though.
Before you try to install The Building Coder samples, you should be well acquainted with the standard Revit add-in installation process using the add-in manifest.
Please work through the getting started materials to understand that:
http://thebuildingcoder.typepad.com/blog/about-the-author.html#2
Next, install the RvtSamples SDK sample and get that up and running.
After that, enabling The Building Coder samples is a piece of cake:
http://thebuildingcoder.typepad.com/blog/2008/11/loading-the-building-coder-samples.html
It makes use of include files, which are defined using #include.
All other occurrences of the hash character # are interpreted as comments, though.
So ##include is just a comment, and therefore ignored.
Good luck!
Cheers, Jeremy.
Posted by: Jeremy Tammik | November 12, 2013 at 11:04
Is there a way to automate the process of adding (re-linking) References? Opening SDKSamples2014 all RevitAPI and RevitAPIUI references need to be re-linked to C:Program Files\Autodesk.... There are over 7300 errors... There has to be an easier way then going one by one and re-adding the references.
Matt
Posted by: Matt | January 25, 2014 at 22:24
Nevermind.
Found RevitAPIDllsPathUpdater.exe under the Samples folder.
Posted by: Matt | January 25, 2014 at 23:04
Nevermind, found RevitAPIDllsPathUpdater under the Samples folder.
Posted by: Matt | January 26, 2014 at 03:02
Dear Matt,
Please look here for more details:
http://thebuildingcoder.typepad.com/blog/2013/04/compiling-the-revit-2014-sdk.html#3
Cheers, Jeremy.
Posted by: Jeremy Tammik | January 29, 2014 at 03:30
Dear Matt,
Please look here for more details:
http://thebuildingcoder.typepad.com/blog/2013/04/compiling-the-revit-2014-sdk.html#3
Cheers, Jeremy.
Posted by: Jeremy Tammik | January 29, 2014 at 03:30