Exemple #1
0
        static public string FormatLengthAsString(double value)
        {
            FormatValueOptions formatValueOptions = new FormatValueOptions();

            formatValueOptions.AppendUnitSymbol = true;
            return(UnitFormatUtils.Format(IFCImportFile.TheFile.Document.GetUnits(), UnitType.UT_Length, value, true, false, formatValueOptions));
        }
Exemple #2
0
        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);
        }
Exemple #3
0
        private string FormatBoundedValue(IFCPropertyValue propertyValue)
        {
            if (IFCUnit != null)
            {
                FormatValueOptions formatValueOptions = new FormatValueOptions();
                FormatOptions      specFormatOptions  = IFCImportFile.TheFile.Document.GetUnits().GetFormatOptions(IFCUnit.Spec);
                specFormatOptions.Accuracy = 1e-8;
                if (specFormatOptions.CanSuppressTrailingZeros())
                {
                    specFormatOptions.SuppressTrailingZeros = true;
                }
                formatValueOptions.SetFormatOptions(specFormatOptions);

                // If ScaleValues is false, value is in source file units, but 'UnitFormatUtils.Format' expects
                // it in internal units and it then converts it to display units, which should be the same as
                // the source file units.
                double value = Importer.TheProcessor.ScaleValues ?
                               propertyValue.AsDouble() :
                               UnitUtils.ConvertToInternalUnits(propertyValue.AsDouble(), specFormatOptions.GetUnitTypeId());

                return(UnitFormatUtils.Format(IFCImportFile.TheFile.Document.GetUnits(), IFCUnit.Spec, value, false, formatValueOptions));
            }
            else
            {
                return(propertyValue.ValueAsString());
            }
        }
        private static FormatValueOptions MakeFormatValue(
            DisplayUnitType type, bool use_default,
            bool leading_zero, bool supress_spaces)
        {
            FormatValueOptions opts = new FormatValueOptions();
            var f_opts = opts.GetFormatOptions();

            f_opts.UseDefault           = use_default;
            f_opts.DisplayUnits         = type;
            f_opts.SuppressLeadingZeros = leading_zero;
            f_opts.SuppressSpaces       = supress_spaces;
            opts.SetFormatOptions(f_opts);
            return(opts);
        }
Exemple #5
0
        /// <summary>
        /// Convert a value into a formatted length string as displayed in Revit.
        /// </summary>
        /// <param name="value">The value, in Revit internal units.</param>
        /// <returns>The formatted string representation.</returns>
        static public string FormatLengthAsString(double value)
        {
            FormatValueOptions formatValueOptions = new FormatValueOptions();

            formatValueOptions.AppendUnitSymbol = true;
            FormatOptions lengthFormatOptions = IFCImportFile.TheFile.Document.GetUnits().GetFormatOptions(SpecTypeId.Length);

            lengthFormatOptions.Accuracy = 1e-8;
            if (lengthFormatOptions.CanSuppressTrailingZeros())
            {
                lengthFormatOptions.SuppressTrailingZeros = true;
            }
            formatValueOptions.SetFormatOptions(lengthFormatOptions);
            return(UnitFormatUtils.Format(IFCImportFile.TheFile.Document.GetUnits(), SpecTypeId.Length, value, false, formatValueOptions));
        }
Exemple #6
0
 private string FormatBoundedValue(IFCPropertyValue propertyValue)
 {
     if (IFCUnit != null)
     {
         FormatValueOptions formatValueOptions = new FormatValueOptions();
         FormatOptions      specFormatOptions  = IFCImportFile.TheFile.Document.GetUnits().GetFormatOptions(IFCUnit.Spec);
         specFormatOptions.Accuracy = 1e-8;
         if (specFormatOptions.CanSuppressTrailingZeros())
         {
             specFormatOptions.SuppressTrailingZeros = true;
         }
         formatValueOptions.SetFormatOptions(specFormatOptions);
         return(UnitFormatUtils.Format(IFCImportFile.TheFile.Document.GetUnits(), IFCUnit.Spec, propertyValue.AsDouble(), false, formatValueOptions));
     }
     else
     {
         return(propertyValue.ValueAsString());
     }
 }
 static public string FormatLengthAsString(double value)
 {
    FormatValueOptions formatValueOptions = new FormatValueOptions();
    formatValueOptions.AppendUnitSymbol = true;
    return UnitFormatUtils.Format(IFCImportFile.TheFile.Document.GetUnits(), UnitType.UT_Length, value, true, false, formatValueOptions);
 }