Revit 2022: What’s up with ForgeTypeId?

If you’ve taken a look at the new Revit API or tried to update your apps to the new version, you may have seen a lot of errors about units because of API code that Autodesk deprecated in the 2022 API.

The great Extensible Storage Extension is one example of code that needs to be updated for these changes. I’ve made these updates in the Pull Request on Github and you can take a look at the changes which might help you make the changes in your own code. There are also some examples here.

Also, you can’t use a “switch” statement to check ForgeTypeId values, so the code below needed to be changed to use if/else

Also, when you use the Extensible Storage Extension, there are fields that previously required a “UnitType” to be specified like this:

        [Field(UnitType = UnitType.UT_Length)]
        public double offset { get; set; }

A reasonable guess at how to update that code would be

       [Field(SpecTypeId = SpecTypeId.PipingVelocity.TypeId)]
public double Property3 { get; set; } 

But this will give you a compilation error “An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type”. TypeId does return a string, but because it is a property and not a “const string” it can’t be used this way. You can’t read SpecTypeId properties in an attribute initializer because they aren’t constant expressions.

To solve this, use the string literal value of the

[Field(SpecTypeId = “autodesk.spec.aec.piping:velocity-2.0.0”)]
Public double Property3 { get; set; }

And you can find the string literal value with a bit of code like: TaskDialog.Show(“test”, SpecTypeId.PipingVelocity.TypeId);


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s