static public string FormatToRevitUI(string valueName, double value, UnitsAssignment[] Assignments, bool appendUnitSymbol = false) { string formatedValue = value.ToString(); if (null == RevitUnits) { return(formatedValue); } foreach (UnitsAssignment ua in Assignments) { if (ua.ValueName.CompareTo(valueName) == 0) { FormatOptions fo = RevitUnits.GetFormatOptions(ua.unitType); FormatValueOptions formatValueOptions = new FormatValueOptions(); formatValueOptions.SetFormatOptions(fo); formatValueOptions.AppendUnitSymbol = appendUnitSymbol; formatedValue = UnitFormatUtils.FormatValueToString(RevitUnits, ua.unitType, value, false, false, formatValueOptions); string unitSymbol = GetUnitSymbol(valueName, Assignments); if (unitSymbol.Length > 0) { formatedValue = Regex.Replace(formatedValue, unitSymbol, ""); } break; } } return(formatedValue); }
/// <summary> /// Gets initial items for ComboBox in settings dialog. /// </summary> /// <param name="history"> /// The list containing the settings history. /// </param> /// <param name="initialValue"> /// The initial value to be add to ComboBox. /// </param> /// <returns> /// Initial numeric items for ComboBox. /// </returns> public static string[] GetInitialItemsForComboBox(List <double> history, double initialValue, Units unit, UnitType unitType) { UpdateHistory(history, initialValue); List <string> strCopyHistory = new List <string>(); foreach (double item in history) { if (double.IsNaN(item)) { continue; } strCopyHistory.Add(UnitFormatUtils.FormatValueToString(unit, unitType, item, false, false)); } return(strCopyHistory.ToArray()); }