mirror of
https://github.com/jeremytammik/RevitSdkSamples.git
synced 2026-09-24 20:19:54 +00:00
replaced Revit 2020 SDK by Revit 2021 SDK
This commit is contained in:
@@ -38,10 +38,10 @@ namespace Revit.SDK.Samples.CurtainWallGrid.CS
|
||||
{
|
||||
#region Methods
|
||||
/// <summary>
|
||||
/// Convert the value get from RevitAPI to the value indicated by DisplayUnitType
|
||||
/// Convert the value get from RevitAPI to the value indicated by ForgeTypeId
|
||||
/// </summary>
|
||||
/// <param name="to">
|
||||
/// DisplayUnitType indicates unit of target value
|
||||
/// ForgeTypeId indicates unit of target value
|
||||
/// </param>
|
||||
/// <param name="value">
|
||||
/// value get from RevitAPI
|
||||
@@ -49,51 +49,65 @@ namespace Revit.SDK.Samples.CurtainWallGrid.CS
|
||||
/// <returns>
|
||||
/// Target value
|
||||
/// </returns>
|
||||
public static double CovertFromAPI(DisplayUnitType to, double value)
|
||||
public static double CovertFromAPI(ForgeTypeId to, double value)
|
||||
{
|
||||
return value *= ImperialDutRatio(to);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert a value indicated by DisplayUnitType to the value used by RevitAPI
|
||||
/// Convert a value indicated by ForgeTypeId to the value used by RevitAPI
|
||||
/// </summary>
|
||||
/// <param name="value">
|
||||
/// Value to be converted
|
||||
/// </param>
|
||||
/// <param name="from">
|
||||
/// DisplayUnitType indicates the unit of the value to be converted
|
||||
/// ForgeTypeId indicates the unit of the value to be converted
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// Target value
|
||||
/// </returns>
|
||||
public static double CovertToAPI(double value, DisplayUnitType from)
|
||||
public static double CovertToAPI(double value, ForgeTypeId from)
|
||||
{
|
||||
return value /= ImperialDutRatio(from);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get ratio between value in RevitAPI and value to display indicated by DisplayUnitType
|
||||
/// Get ratio between value in RevitAPI and value to display indicated by ForgeTypeId
|
||||
/// </summary>
|
||||
/// <param name="dut">
|
||||
/// DisplayUnitType indicates display unit type
|
||||
/// ForgeTypeId indicates display unit type
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// Ratio
|
||||
/// </returns>
|
||||
private static double ImperialDutRatio(DisplayUnitType dut)
|
||||
private static double ImperialDutRatio(ForgeTypeId unitTypeId)
|
||||
{
|
||||
switch (dut)
|
||||
{
|
||||
case DisplayUnitType.DUT_DECIMAL_FEET: return 1;
|
||||
case DisplayUnitType.DUT_FEET_FRACTIONAL_INCHES: return 1;
|
||||
case DisplayUnitType.DUT_DECIMAL_INCHES: return 12;
|
||||
case DisplayUnitType.DUT_FRACTIONAL_INCHES: return 12;
|
||||
case DisplayUnitType.DUT_METERS: return 0.3048;
|
||||
case DisplayUnitType.DUT_CENTIMETERS: return 30.48;
|
||||
case DisplayUnitType.DUT_MILLIMETERS: return 304.8;
|
||||
case DisplayUnitType.DUT_METERS_CENTIMETERS: return 0.3048;
|
||||
default: return 1;
|
||||
}
|
||||
if (unitTypeId == UnitTypeId.Feet) return 1;
|
||||
if (unitTypeId == UnitTypeId.FeetFractionalInches) return 1;
|
||||
if (unitTypeId == UnitTypeId.Inches) return 12;
|
||||
if (unitTypeId == UnitTypeId.FractionalInches) return 12;
|
||||
if (unitTypeId == UnitTypeId.Meters) return 0.3048;
|
||||
if (unitTypeId == UnitTypeId.Centimeters) return 30.48;
|
||||
if (unitTypeId == UnitTypeId.Millimeters) return 304.8;
|
||||
if (unitTypeId == UnitTypeId.MetersCentimeters) return 0.3048;
|
||||
return 1;
|
||||
}
|
||||
|
||||
public static string GetUnitLabel(ForgeTypeId unitTypeId)
|
||||
{
|
||||
Dictionary<ForgeTypeId, string> unitLabels = new Dictionary<ForgeTypeId, string> {
|
||||
{ UnitTypeId.Centimeters, "cm" },
|
||||
{ UnitTypeId.Feet, "'" },
|
||||
{ UnitTypeId.Inches, "\"" },
|
||||
{ UnitTypeId.FeetFractionalInches, "'" },
|
||||
{ UnitTypeId.FractionalInches, "\"" },
|
||||
{ UnitTypeId.Meters, "m" },
|
||||
{ UnitTypeId.MetersCentimeters, "m" },
|
||||
{ UnitTypeId.Millimeters, "mm" }
|
||||
};
|
||||
if (unitLabels.ContainsKey(unitTypeId))
|
||||
return unitLabels[unitTypeId];
|
||||
return string.Empty;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user