I am trying to port some legacy code to Revit 2022 and I am running into the problem that there does not seem to be a convert some of the ParameterType enum values to a ForgeTypeId
FixtureUnit and Invalid (the result for ElementId parameters) are the most pressing ones.
There does not seem to be anything Fixture or Piping related in the SpecTypeId class that may apply. PipeDimension comes closest but is not, I think, the same? (plus, it also exists separately in the ParameterType enum which makes it unlikely that it got a double meaning in Revit 2022)
According to the release documentation there should be a deprecated method in the Parameter class that can help porting ParameterType enum values to ForgeTypeId objects, but intellisense does not seem to be aware of the existence of such a method.
Solved! Go to Solution.
I am trying to port some legacy code to Revit 2022 and I am running into the problem that there does not seem to be a convert some of the ParameterType enum values to a ForgeTypeId
FixtureUnit and Invalid (the result for ElementId parameters) are the most pressing ones.
There does not seem to be anything Fixture or Piping related in the SpecTypeId class that may apply. PipeDimension comes closest but is not, I think, the same? (plus, it also exists separately in the ParameterType enum which makes it unlikely that it got a double meaning in Revit 2022)
According to the release documentation there should be a deprecated method in the Parameter class that can help porting ParameterType enum values to ForgeTypeId objects, but intellisense does not seem to be aware of the existence of such a method.
Solved! Go to Solution.
Solved by david_becroft. Go to Solution.
Quick first answer to point to existing additional resources:
You can take a look at those besides the API documentation that you already checked.
Meanwhile, I'll see whether I can dig up anything specific on fixtures...
Quick first answer to point to existing additional resources:
You can take a look at those besides the API documentation that you already checked.
Meanwhile, I'll see whether I can dig up anything specific on fixtures...
I found the second resource while trying to find out how to handle ParameterType.Text in Revit 2022. The first link I somehow overlooked. It does contain a lot of useful information that will likely come in handy in the future to correctly implement the new ForgeTypeId everywhere.
I am working on this wrapper class that hopefully will be able to handle the ParameterType changes in a transparent manner so that I do not have to put #if statements all throughout the code, but instead move everything regarding the parameter type to this class.
public class ParType { #if R2022 private readonly ForgeTypeId _ftype; public bool IsValid { get { if (null == _ftype) return false; if (SpecTypeId.String.Text == _ftype) return true; PropertyInfo[] props = typeof(SpecTypeId).GetProperties(); foreach (PropertyInfo pi in props) { if (!(pi.GetValue(null) is ForgeTypeId val)) continue; if (val.NameEquals(_ftype)) return true; } return false; } } public static readonly ParType Angle = new ParType(SpecTypeId.Angle); public static readonly ParType Area = new ParType(SpecTypeId.Area); //public static readonly ParType FixtureUnit = new ParType(SpecTypeId.FixtureUnit); public static readonly ParType Integer = new ParType(SpecTypeId.Int.Integer); //public static readonly ParType Invalid = new ParType(SpecTypeId.Invalid); public static readonly ParType Length = new ParType(SpecTypeId.Length); public static readonly ParType Number = new ParType(SpecTypeId.Number); public static readonly ParType Text = new ParType(SpecTypeId.String.Text); public static readonly ParType Volume = new ParType(SpecTypeId.Volume); public static readonly ParType YesNo = new ParType(SpecTypeId.Boolean.YesNo); public static explicit operator ForgeTypeId(ParType pt) { return pt._ftype; } public ParType(ForgeTypeId fti) { _ftype = fti; } public ParType(Definition def) { if (null == def) return; _ftype = def.GetDataType(); } #else
The part after the #else is the implementation using ParameterType for older versions of Revit.
The static values are the types that are explicitly tested in the legacy code. Thankfully I do not have to implement every possibly SpecTypeId (as that would rather defeat the point of having a wrapper and move to using ForgeTypeId).
I still need to add an IComparable<> and IEquatable<> implementation but those are trivial.
I found the second resource while trying to find out how to handle ParameterType.Text in Revit 2022. The first link I somehow overlooked. It does contain a lot of useful information that will likely come in handy in the future to correctly implement the new ForgeTypeId everywhere.
I am working on this wrapper class that hopefully will be able to handle the ParameterType changes in a transparent manner so that I do not have to put #if statements all throughout the code, but instead move everything regarding the parameter type to this class.
public class ParType { #if R2022 private readonly ForgeTypeId _ftype; public bool IsValid { get { if (null == _ftype) return false; if (SpecTypeId.String.Text == _ftype) return true; PropertyInfo[] props = typeof(SpecTypeId).GetProperties(); foreach (PropertyInfo pi in props) { if (!(pi.GetValue(null) is ForgeTypeId val)) continue; if (val.NameEquals(_ftype)) return true; } return false; } } public static readonly ParType Angle = new ParType(SpecTypeId.Angle); public static readonly ParType Area = new ParType(SpecTypeId.Area); //public static readonly ParType FixtureUnit = new ParType(SpecTypeId.FixtureUnit); public static readonly ParType Integer = new ParType(SpecTypeId.Int.Integer); //public static readonly ParType Invalid = new ParType(SpecTypeId.Invalid); public static readonly ParType Length = new ParType(SpecTypeId.Length); public static readonly ParType Number = new ParType(SpecTypeId.Number); public static readonly ParType Text = new ParType(SpecTypeId.String.Text); public static readonly ParType Volume = new ParType(SpecTypeId.Volume); public static readonly ParType YesNo = new ParType(SpecTypeId.Boolean.YesNo); public static explicit operator ForgeTypeId(ParType pt) { return pt._ftype; } public ParType(ForgeTypeId fti) { _ftype = fti; } public ParType(Definition def) { if (null == def) return; _ftype = def.GetDataType(); } #else
The part after the #else is the implementation using ParameterType for older versions of Revit.
The static values are the types that are explicitly tested in the legacy code. Thankfully I do not have to implement every possibly SpecTypeId (as that would rather defeat the point of having a wrapper and move to using ForgeTypeId).
I still need to add an IComparable<> and IEquatable<> implementation but those are trivial.
Good morning @m.de.vriesTH5VM,
According to the release documentation there should be a deprecated method in the Parameter class that can help porting ParameterType enum values to ForgeTypeId objects
These methods are SpecUtils.GetSpecTypeId(ParameterType) and SpecUtils.GetParameterType(ForgeTypeId).
FixtureUnit and Invalid (the result for ElementId parameters) are the most pressing ones.
In place of ParameterType.FixtureUnit you can use SpecTypeId.Number.
ParameterType.Invalid is equivalent to an empty, default-constructed ForgeTypeId, i.e. new ForgeTypeId().
Good morning @m.de.vriesTH5VM,
According to the release documentation there should be a deprecated method in the Parameter class that can help porting ParameterType enum values to ForgeTypeId objects
These methods are SpecUtils.GetSpecTypeId(ParameterType) and SpecUtils.GetParameterType(ForgeTypeId).
FixtureUnit and Invalid (the result for ElementId parameters) are the most pressing ones.
In place of ParameterType.FixtureUnit you can use SpecTypeId.Number.
ParameterType.Invalid is equivalent to an empty, default-constructed ForgeTypeId, i.e. new ForgeTypeId().
Can't find what you're looking for? Ask the community or share your knowledge.