Migrating the Building Coder Samples to Revit 2012

This is the third migration of the The Building Coder samples, after moving from Revit 2009 to

Revit 2010
and then to

Revit 2011
.

The move from 2010 to 2011 was a tougher round with many changes.
This time around, from 2011 to 2012, it is quite easy and straightforward again.

For details on what needs modifying, as always, please refer to the Revit 2012 SDK documentation and especially the chapter ‘What’s New’ in the Revit 2012 API help file RevitAPI.chm.

I spent a couple of hours migrating The Building Coder samples.
The time is rather long because there are a large number of commands, over eighty.
It was shortened somewhat because I had some experience from previously migrating lots of other ADN sample code for the Revit API trainings

in


Jeddah
and

Verona
.

Without further ado, let me here present the new
Revit 2012 version 2012.0.87.0
of The Building Coder sample code.
For comparison purposes, here is an updated
last Revit 2011 version 2011.0.87.2.
In the latter, I already updated some administrative global stuff, so that it can be used to easily determine what the really relevant differences between the 2011 and 2012 versions are.
Actually, I also removed the regeneration attribute, so this version will not run in Revit 2011 – it is really for comparison purposes only.
I hope you are aware of the Unix

diff
,
Visual Studio

Windiff
,
and numerous other tools for comparing files and directory structures that can be used for this purpose.

One systematic difference that affects every single file in the same way is the removal of the regeneration attribute.
It was obligatory in Revit 2011, and is voluntary but useless in Revit 2012 API, since the only supported regeneration mode is now manual.

Here is the list of different files produced by Windiff after updating the regeneration attribute in both versions:


propertiesassemblyinfo.cs
cmdcollectorperformance.cs
cmdcolumnround.cs
cmddimensionwallsfindrefs.cs
cmdeditfloor.cs
cmdgetsketchelements.cs
cmdimportsinfamilies.cs
cmdlibrarypaths.cs
cmdmirror.cs
cmdnewlightingfixture.cs
cmdnewspotelevation.cs
cmdnewwalllayer.cs
cmdroomwalladjacency.cs
cmdsettagtype.cs
cmdspaceadjacency.cs
cmdtransformedcoords.cs
cmdwalllayers.cs
cmdwalllayervolumes.cs
util.cs

This is how the differences are displayed in Windiff, with deleted lines displayed in red and added ones in yellow:

Windiff displaying file differences

In the 2012 version of the code, I commented out the 2011-specific lines of code and added a ‘// 2011’ comment suffix to them.
The 2012 version of the lines are also marked, with a ‘// 2012’ comment suffix.

I suggest downloading and unpacking the two versions in two neighbouring directories and running Windiff on them yourself to examine the changes in detail.

Here is a full
log of the migration steps.

I fixed all errors and most of the warnings, but 12 still remain.
I consider these acceptable for the moment, and will leave things as they are for now.
I have tested a very few of the migrated commands.
Most are still untested in Revit 2012.

Good luck in your own porting efforts!

Version Number

I am maintaining the version numbering system introduced for Revit 2011: major.minor.build.revision.
I bumped the major revision to 2012 to make the link to Revit 2012 obvious.
I may use the minor revision to indicate intermediate updates of the Revit API, if any appear.
The build number is currently set to 87 and indicates the number of commands defined, more or less.

RvtSamples

As before, I continue to use the

RvtSamples SDK sample
to

load and launch all The Building Coder samples
,
as well as all the other ADN samples that I work with, just like I did for

Revit


2010
and

2011
.
The BcSamples.txt include file read by RvtSamples is included in the zip file and provides all the details required.
For more information, you can also refer to the RvtSamples documentation.


Comments

7 responses to “Migrating the Building Coder Samples to Revit 2012”

  1. Isidoro Avatar
    Isidoro

    I’m migrating a plugin from 2011 and 2012 and experienced problems with leveltype parameters BuiltInParameter.LEVEL_ATTR_ROOM_COMPUTATION_AUTOMATIC and BuiltInParameter.LEVEL_ATTR_ROOM_COMPUTATION_HEIGHT, that in Revit 2011 were writable, but in Revit 2012 are READONLY!!!!
    Have you experencied a similiar issue when migrating your samples? I writed a support request to ADN too, i’m waiting for the answer…
    Next code worked in Revit 2011, and fails in 2012:
    FilteredElementCollector collector = new FilteredElementCollector(App.Document);
    IList elementos = collector.OfCategory(BuiltInCategory.OST_Levels).WhereElementIsElementType().ToElements();
    foreach(Element e in elementos)
    {
    Parameter p = e.get_Parameter(BuiltInParameter.LEVEL_ATTR_ROOM_COMPUTATION_AUTOMATIC);
    p.Set(0);
    p = e.get_Parameter(BuiltInParameter.LEVEL_ATTR_ROOM_COMPUTATION_HEIGHT);
    p.Set(0);
    }

  2. Dear Isidoro,
    I created a new post to answer your question:
    http://thebuildingcoder.typepad.com/blog/2011/05/new-room-computation-parameters.html
    Cheers, Jeremy.

  3. tzavelis@hotmail.com Avatar
    tzavelis@hotmail.com

    Hello Jeremy,
    I have been trying for the last few days to figure out why my code for iterating through Type Floor or Wall does not work in Revit Structures 2012, while worked in Revit 2011. Iterating with Type FamilyInstance works!
    I am getting the following error:
    An exception of type ‘System.MissingMethodException’ occurred in ctRevitDll.dll but was not handled in user code
    Additional information: Method not found:
    ‘Autodesk.Revit.DB.CompoundStructure Autodesk.Revit.DB.HostObjAttributes.get_CompoundStructure()’.
    Am I missing a reference or namespace?
    I get the error in the following loop even though the compiler shows that Flr is loaded with Revit Floor data!
    For Each Flr As Autodesk.Revit.DB.Floor In Flrs
    Dim CreateObj As oRvtFloor = New oRvtFloor(Flr)
    Next

  4. tzavelis@hotmail.com Avatar
    tzavelis@hotmail.com

    I just found the answer to the Floor and Wall error.
    I was referencing Revit 2011 and not 2012
    Cosmas

  5. Dear Cosmas,
    Hehe :-)
    Cheers, Jeremy.

  6. nsybs86 Avatar
    nsybs86

    Hello Jeremy
    I have developed an add-in application using RevitAPI(ver 2011). unfortunately, some of the method is obsolete and can’t be used anymore in the later version. It is quite hard for me to maintain two version of code, any solution for this?
    p.s A suggestion I get is to use System.Reflection, but i just wonder is there any other way to handle two different API in single code?

  7. Dear nsybs86,
    Please think for one moment…
    If I knew an easier way, would I be describing my steps above?
    All I can suggest, really, is to use conditional compilation:
    http://en.wikipedia.org/wiki/Conditional_compilation
    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