WallCrossSection Renaming in the Revit 2022.1 API

Breaking news from the Revit development team:

WallCrossSection versus WallCrossSectionDefinition

Last week, we mentioned the unfortunate breaking change inadvertently introduced with the Revit 2022.1 API update by renaming WallCrossSection to WallCrossSectionDefinition and suggested a fix for the BuiltInParameterGroup enumeration value.

Here is the workaround suggested by the development team to also address the ForgeTypeId modification to support both versions of the API:

As you know from the Revit API discussion forum thread on Revit API 2022.1 update change WallCrossSection to WallCrossSectionDefinition, there was a breaking change introduced in Revit 2022.1:

were renamed to

respectively.

A solution for the first name change in the enum value was already suggested in the forum discussion thread:

The actual integer value can be used instead to define a constant like this:

  var PG_WALL_CROSS_SECTION = (BuiltInParameterGroup) (-5000228);

This value be used in both Revit 2022.0 and Revit 2022.1 without causing the problem.

A workaround for the second rename, the WallCrossSection property of the ForgeTypeId class, can be implemented using Reflection in all .NET languages.

Here is a sample code snippet in C#:

using System.Reflection;

. . .

  ForgeTypeId id = new ForgeTypeId();
  Type type = typeof(GroupTypeId);
  PropertyInfo propOld = type.GetProperty("WallCrossSection",
    BindingFlags.Public | BindingFlags.Static);

  if (null != propOld)
  {
    id = (ForgeTypeId) propOld.GetValue(nullnull);
  }
  else
  {
    PropertyInfo propNew = type.GetProperty("WallCrossSectionDefinition",
      BindingFlags.Public | BindingFlags.Static);
    id = (ForgeTypeId) propNew.GetValue(nullnull);
  }

Or, if you prefer a more succinct version, use this:

  Type type = typeof(GroupTypeId);

  PropertyInfo prop = type.GetProperty("WallCrossSection", 
    BindingFlags.Public | BindingFlags.Static) 
      ?? type.GetProperty("WallCrossSectionDefinition", 
        BindingFlags.Public | BindingFlags.Static);

  ForgeTypeId id = (ForgeTypeId) prop.GetValue(nullnull);

We tested it here, and it works for both Revit 2022.0 and Revit 2022.1.

Non-breaking change

Non-breaking change – © Datamation