Quantcast
Channel: RevitNetAddinWizard & NavisworksNetAddinWizard
Viewing all articles
Browse latest Browse all 872

Revit Units .NET API: Figure out all Revit Unmodifiable Units

$
0
0

Revit .NET has provided the Units API since version 2014. In this series of posts, we explore the Revit Units .NET API a bit and provide sample code and analysis as usual.
Most of Revit Units are modifiable, but some are not. In this post, let’s figure out all those unmodifiable units.

        public static void FigureOutUnmodifiableRevitUnits(RvtDocument doc)
        {
            string info = "";
            using (StreamWriter sw = new StreamWriter(@"c:\temp\RevitUnmodifiableUnits.txt"))
            {
                sw.WriteLine("** Revit Unmodifiable Units **" + Environment.NewLine);
                Units units = doc.GetUnits();
                foreach (UnitType ut in UnitUtils.GetValidUnitTypes())
                {
                    if (!Units.IsModifiableUnitType(ut))
                    {
                        info = string.Format("{0} -- {1}", ut, LabelUtils.GetLabelFor(ut));
                        sw.WriteLine(info);

                        FormatOptions fmtOpts = units.GetFormatOptions(ut);
                        info = PrintOutRevitUnitInfo(ut, fmtOpts, "\t\t");
                        sw.WriteLine("\tFormat Options:" + Environment.NewLine + info);

                        sw.WriteLine("\tAvailable Display Units:");
                        foreach (DisplayUnitType dut in UnitUtils.GetValidDisplayUnits(ut))
                        {
                            info = string.Format("\t\t{0} -- {1}", dut, LabelUtils.GetLabelFor(dut));
                            sw.WriteLine(info);
                        }
                    }
                }
            }
        }

        public static string PrintOutRevitUnitInfo(UnitType ut, FormatOptions obj, string indent)
        {
            string msg = string.Format(indent + "{0} ({1}):" + Environment.NewLine, LabelUtils.GetLabelFor(ut), ut);

            msg += string.Format(indent + "\tAccuracy: {0}" + Environment.NewLine, obj.Accuracy);
            msg += string.Format(indent + "\tUnit display: {0} ({1})" + Environment.NewLine, LabelUtils.GetLabelFor(obj.DisplayUnits), obj.DisplayUnits);
            msg += string.Format(indent + "\tUnit symbol: {0}" + Environment.NewLine, obj.CanHaveUnitSymbol() ? string.Format("{0} ({1})", (obj.UnitSymbol == UnitSymbolType.UST_NONE ? "" : LabelUtils.GetLabelFor(obj.UnitSymbol)), obj.UnitSymbol) : "n/a");
            msg += string.Format(indent + "\tUse default: {0}" + Environment.NewLine, obj.UseDefault);
            msg += string.Format(indent + "\tUse grouping: {0}" + Environment.NewLine, obj.UseGrouping);
            msg += string.Format(indent + "\tUse digit grouping: {0}" + Environment.NewLine, obj.UseDigitGrouping);
            msg += string.Format(indent + "\tUse plus prefix: {0}" + Environment.NewLine, obj.CanUsePlusPrefix() ? obj.UsePlusPrefix.ToString() : "n/a");
            msg += string.Format(indent + "\tSuppress spaces: {0}" + Environment.NewLine, obj.CanSuppressSpaces() ? obj.SuppressSpaces.ToString() : "n/a");
            msg += string.Format(indent + "\tSuppress leading zeros: {0}" + Environment.NewLine, obj.CanSuppressLeadingZeros() ? obj.SuppressLeadingZeros.ToString() : "n/a");
            msg += string.Format(indent + "\tSuppress trailing zeros: {0}" + Environment.NewLine, obj.CanSuppressTrailingZeros() ? obj.SuppressTrailingZeros.ToString() : "n/a");

            return msg;
        }
    

RevitUnitsAPI.FigureOutUnmodifiableRevitUnits(CachedDoc);


The output may look something like the following:

** Revit Unmodifiable Units **

UT_Number -- Number
    Format Options:
        Number (UT_Number):
            Accuracy: 1E-06
            Unit display: General (DUT_GENERAL)
            Unit symbol: n/a
            Use default: False
            Use grouping: False
            Use digit grouping: False
            Use plus prefix: n/a
            Suppress spaces: n/a
            Suppress leading zeros: n/a
            Suppress trailing zeros: n/a

    Available Display Units:
        DUT_GENERAL -- General
        DUT_FIXED -- Fixed
        DUT_CURRENCY -- Currency
        DUT_PERCENTAGE -- Percentage
UT_SheetLength -- Sheet Length
    Format Options:
        Sheet Length (UT_SheetLength):
            Accuracy: 0.0078125
            Unit display: Fractional inches (DUT_FRACTIONAL_INCHES)
            Unit symbol: n/a
            Use default: False
            Use grouping: False
            Use digit grouping: False
            Use plus prefix: False
            Suppress spaces: n/a
            Suppress leading zeros: n/a
            Suppress trailing zeros: n/a

    Available Display Units:
        DUT_DECIMAL_FEET -- Decimal feet
        DUT_FEET_FRACTIONAL_INCHES -- Feet and fractional inches
        DUT_DECIMAL_INCHES -- Decimal inches
        DUT_FRACTIONAL_INCHES -- Fractional inches
        DUT_METERS -- Meters
        DUT_DECIMETERS -- Decimeters
        DUT_CENTIMETERS -- Centimeters
        DUT_MILLIMETERS -- Millimeters
        DUT_METERS_CENTIMETERS -- Meters and centimeters
        DUT_SQUARE_FEET_PER_FOOT -- Square feet per foot
        DUT_SQUARE_INCHES_PER_FOOT -- Square inches per foot
        DUT_SQUARE_MILLIMETERS_PER_METER -- Square millimeters per meter
        DUT_SQUARE_CENTIMETERS_PER_METER -- Square centimeters per meter
        DUT_SQUARE_METERS_PER_METER -- Square meters per meter
UT_DecSheetLength -- Sheet Length
    Format Options:
        Sheet Length (UT_DecSheetLength):
            Accuracy: 0.0001
            Unit display: Decimal inches (DUT_DECIMAL_INCHES)
            Unit symbol:  (UST_NONE)
            Use default: False
            Use grouping: False
            Use digit grouping: False
            Use plus prefix: False
            Suppress spaces: n/a
            Suppress leading zeros: n/a
            Suppress trailing zeros: False

    Available Display Units:
        DUT_DECIMAL_FEET -- Decimal feet
        DUT_FEET_FRACTIONAL_INCHES -- Feet and fractional inches
        DUT_DECIMAL_INCHES -- Decimal inches
        DUT_FRACTIONAL_INCHES -- Fractional inches
        DUT_METERS -- Meters
        DUT_DECIMETERS -- Decimeters
        DUT_CENTIMETERS -- Centimeters
        DUT_MILLIMETERS -- Millimeters
        DUT_METERS_CENTIMETERS -- Meters and centimeters
        DUT_SQUARE_FEET_PER_FOOT -- Square feet per foot
        DUT_SQUARE_INCHES_PER_FOOT -- Square inches per foot
        DUT_SQUARE_MILLIMETERS_PER_METER -- Square millimeters per meter
        DUT_SQUARE_CENTIMETERS_PER_METER -- Square centimeters per meter
        DUT_SQUARE_METERS_PER_METER -- Square meters per meter
UT_SiteAngle -- Site Angle
    Format Options:
        Site Angle (UT_SiteAngle):
            Accuracy: 0.000277777777777778
            Unit display: Degrees minutes seconds (DUT_DEGREES_AND_MINUTES)
            Unit symbol: n/a
            Use default: False
            Use grouping: False
            Use digit grouping: False
            Use plus prefix: n/a
            Suppress spaces: n/a
            Suppress leading zeros: n/a
            Suppress trailing zeros: n/a

    Available Display Units:
        DUT_DECIMAL_DEGREES -- Decimal degrees
        DUT_DEGREES_AND_MINUTES -- Degrees minutes seconds
        DUT_RADIANS -- Radians
        DUT_GRADS -- Grads
UT_ForceScale -- Force Scale
    Format Options:
        Force Scale (UT_ForceScale):
            Accuracy: 0.1
            Unit display: Feet per kip (DUT_FEET_PER_KIP)
            Unit symbol: ft/kip (UST_FT_PER_KIP)
            Use default: False
            Use grouping: False
            Use digit grouping: False
            Use plus prefix: n/a
            Suppress spaces: n/a
            Suppress leading zeros: n/a
            Suppress trailing zeros: False

    Available Display Units:
        DUT_METERS_PER_KILONEWTON -- Meters per kilonewton
        DUT_FEET_PER_KIP -- Feet per kip
UT_LinearForceScale -- Linear Force Scale
    Format Options:
        Linear Force Scale (UT_LinearForceScale):
            Accuracy: 0.1
            Unit display: Square feet per kip (DUT_SQUARE_FEET_PER_KIP)
            Unit symbol: ft²/kip (UST_FT_SUP_2_PER_KIP)
            Use default: False
            Use grouping: False
            Use digit grouping: False
            Use plus prefix: n/a
            Suppress spaces: n/a
            Suppress leading zeros: n/a
            Suppress trailing zeros: False

    Available Display Units:
        DUT_SQUARE_METERS_PER_KILONEWTON -- Square meters per kilonewton
        DUT_SQUARE_FEET_PER_KIP -- Square feet per kip
        DUT_CUBIC_FEET_PER_MINUTE_TON_OF_REFRIGERATION -- Cubic meters per minute tons of refrigeration
        DUT_LITERS_PER_SECOND_KILOWATTS -- Liters per second kilowatts
UT_AreaForceScale -- Area Force Scale
    Format Options:
        Area Force Scale (UT_AreaForceScale):
            Accuracy: 0.1
            Unit display: Cubic feet per kip (DUT_CUBIC_FEET_PER_KIP)
            Unit symbol: ft³/kip (UST_FT_SUP_3_PER_KIP)
            Use default: False
            Use grouping: False
            Use digit grouping: False
            Use plus prefix: n/a
            Suppress spaces: n/a
            Suppress leading zeros: n/a
            Suppress trailing zeros: False

    Available Display Units:
        DUT_CUBIC_METERS_PER_KILONEWTON -- Cubic meters per kilonewton
        DUT_CUBIC_FEET_PER_KIP -- Cubic feet per kip
UT_MomentScale -- Moment Scale
    Format Options:
        Moment Scale (UT_MomentScale):
            Accuracy: 0.1
            Unit display: Inverse kips (DUT_INV_KIPS)
            Unit symbol: 1/kip (UST_INV_KIP)
            Use default: False
            Use grouping: False
            Use digit grouping: False
            Use plus prefix: n/a
            Suppress spaces: n/a
            Suppress leading zeros: n/a
            Suppress trailing zeros: False

    Available Display Units:
        DUT_INV_KILONEWTONS -- Inverse kilonewtons
        DUT_INV_KIPS -- Inverse kips
UT_LinearMomentScale -- Linear Moment Scale
    Format Options:
        Linear Moment Scale (UT_LinearMomentScale):
            Accuracy: 0.1
            Unit display: Feet per kip (DUT_FEET_PER_KIP)
            Unit symbol: ft/kip (UST_FT_PER_KIP)
            Use default: False
            Use grouping: False
            Use digit grouping: False
            Use plus prefix: n/a
            Suppress spaces: n/a
            Suppress leading zeros: n/a
            Suppress trailing zeros: False

    Available Display Units:
        DUT_METERS_PER_KILONEWTON -- Meters per kilonewton
        DUT_FEET_PER_KIP -- Feet per kip

Revit Addin Wizard (RevitAddinWizard) provides various wizards, coders and widgets to help program Revit addins. It can be downloaded from the Download link at the bottom of the blog index page.


Viewing all articles
Browse latest Browse all 872

Trending Articles