FabricationPart Slope Bug
Description
The Slope parameter for FabricationPart is incorrectly assigned SpecTypeId.Slope instead of SpecTypeId.PipingSlope. This affects parameter.AsValueString() when the Common:Slope and Piping:Slope have different settings in Project Units. This snippet shows how to get correct value string.
Code
C#using Autodesk.Revit.DB;
public static bool TryReadFabricationSlopeByBuiltInParameter(
FabricationPart part,
out double rawSlope,
out string formattedSlope)
{
// Lookup by the BuiltInParameter for Fabrication Slope.
return TryReadFabricationSlope(
part,
part.get_Parameter(BuiltInParameter.FABRICATION_SLOPE_PARAM),
out rawSlope,
out formattedSlope);
}
public static bool TryReadFabricationSlopeByParameterTypeId(
FabricationPart part,
out double rawSlope,
out string formattedSlope)
{
// Lookup by the ForgeTypeId for Fabrication Slope. Revit 2022 and later.
return TryReadFabricationSlope(
part,
part.GetParameter(ParameterTypeId.FabricationSlopeParam),
out rawSlope,
out formattedSlope);
}
private static bool TryReadFabricationSlope(
FabricationPart part,
Parameter? parameter,
out double rawSlope,
out string formattedSlope)
{
rawSlope = 0.0;
formattedSlope = string.Empty;
if (parameter == null
|| parameter.StorageType != StorageType.Double
|| !parameter.HasValue)
{
return false;
}
double value = parameter.AsDouble();
if (double.IsNaN(value) || double.IsInfinity(value))
return false;
rawSlope = value;
/* Revit reports this parameter with the Common Slope spec.
This selects PipiingSlope display units;
it does not change the raw parameter value. */
formattedSlope = UnitFormatUtils.Format(
part.Document.GetUnits(),
SpecTypeId.PipingSlope,
value,
true);
return true;
}