The Building Coder Samples 2017

Last night, I migrated The Building Coder samples to Revit 2017:

Flat Migration

The flat migration was trivial:

The compilation succeeded right away with zero errors and 53 warnings about obsolete API usage.

Here are the diffs for this first step.

Updated RvtSamples Include File

Next, in order to perform a first test run, I updated the RvtSamples include file, i.e., the text file BcSamples.txt read by the RvtSamples external application to load the individual external commands, simply updating the BuildingCoder.dll output build path to point to the new 2017-specific folder.

Once that was done, I was up and running in Revit 2017 – RvtSamples lists The Building Coder sample commands in the three alphabetically sorted sections prefixed with 'ADN Bc':

The Building Coder samples in Revit 2017

So that was quick and easy.

While we are at it, let's fix those 53 obsolete API usage warnings as well.

Automatic Transaction Mode is Obsolete

30 of the 53 warnings concern the obsolete automatic transaction mode:

We have know for long that it will be going away.

In fact, it was publicly announced as far back as 2012.

So this clean-up is long overdue.

Unfortunately, it will cost me some effort to rewrite these 30 commands.

That is also the reason why it is so long overdue   :-)

Later... I fixed all 30 of these external commands, reducing the count to 23 warnings about obsolete API usage.

Here are the diffs for this clean-up.

Obsolete Plane Constructors and NewPlane Methods

All three overloads of the Application.NewPlane method are obsolete:

I am using the one taking two XTZ arguments representing a normal vector and an origin, and the one taking a CurveArray argument.

All three overloads of the Plane class constructor are obsolete:

I am using the one taking two XYZ arguments representing a normal vector and an origin.

These three obsolete methods generate the following warnings:

Let's go and do what the man says...

I replaced all occurrences of the first two warnings, reducing the count to 5 warnings about obsolete API usage.

Here are the diffs for this clean-up.

Obsolete NewPlane Method Taking a CurveArray Argument

I still have three calls to the obsolete Application.NewPlane method taking a CurveArray argument, e.g., in CmdWallProfile.cs:

  CurveArray curves = creapp.NewCurveArray();

  foreachCurve curve in curveLoop2 )
  {
    curves.Append( curve.CreateTransformed( offset ) );
  }

  // Create model lines for an curve loop.

  Plane plane = creapp.NewPlane( curves ); // 2016

The suggested fix is to use the CurveLoop.GetPlane method instead.

Luckily, in this case, the variable curveLoop2 from which we extract the individual curves to add to the CurveArray collection is already a CurveLoop instance, so we can call GetPlane on it directly:

  Plane plane = curveLoop2.GetPlane(); // 2017

Unfortunately, we still need to retain and set up the CurveArray, because that is a required argument in the subsequent call to NewModelCurveArray.

Replace View.SetVisibility by SetCategoryHidden

The View.SetVisibility is replaced by SetCategoryHidden.

Here are the calls used in Revit 2016 and Revit 12017, respectively:

  view.SetVisibility( catHosts, false ); // 2016

  view.SetCategoryHidden( catHosts.Id, true ); // 2017

Use DirectShape ApplicationId and ApplicationDataId

In Revit 2016, the application and application data GUIDs for a DirectShape element were passed into the constructor.

In Revit 2017, they can be set later using the corresponding properties:

  DirectShape ds = DirectShape.CreateElement(
    doc, e.Category.Id,
    _direct_shape_appGUID,
    appDataGUID ); // 2016

  DirectShape ds = DirectShape.CreateElement(
    doc, e.Category.Id ); //2017

  ds.ApplicationId = _direct_shape_appGUID; // 2017
  ds.ApplicationDataId = appDataGUID∫∫; // 2017

All Obsolete Revit API Usage Eliminated

The final result of the migration and obsolete API clean-up is release 2017.0.127.4, compiling with zero errors and warnings.

The newest version is always available from The Building Coder samples GitHub repository master branch.