From 36e327ae81411c0491c0f160d2bdb97f599f4755 Mon Sep 17 00:00:00 2001 From: Jeremy Tammik Date: Fri, 1 Nov 2013 14:41:23 +0100 Subject: [PATCH] implemented Display Unit Type Abbreviation command CmdDutAbbreviation to test the display unit type abbreviation array --- BcSamples.txt | 8 ++ .../BuildingCoder/BuildingCoder.csproj | 1 + .../BuildingCoder/CmdDutAbbreviation.cs | 90 +++++++++++++++++++ .../BuildingCoder/Properties/AssemblyInfo.cs | 4 +- BuildingCoder/BuildingCoder/Util.cs | 75 +++++++++++++--- 5 files changed, 165 insertions(+), 13 deletions(-) create mode 100644 BuildingCoder/BuildingCoder/CmdDutAbbreviation.cs diff --git a/BcSamples.txt b/BcSamples.txt index 9203fecf..6bdf73fa 100644 --- a/BcSamples.txt +++ b/BcSamples.txt @@ -897,3 +897,11 @@ LargeImage: Image: C:\a\lib\revit\2014\bc\BuildingCoder\BuildingCoder\bin\Debug\BuildingCoder.dll BuildingCoder.CmdExportSolidToSat # version 2014.0.104.0 + +ADN Bc A-M +Display Unit Type Abbreviation +Test the display unit type abbreviation array +LargeImage: +Image: +C:\a\lib\revit\2014\bc\BuildingCoder\BuildingCoder\bin\Debug\BuildingCoder.dll +BuildingCoder.CmdDutAbbreviation # version 2014.0.105.0 diff --git a/BuildingCoder/BuildingCoder/BuildingCoder.csproj b/BuildingCoder/BuildingCoder/BuildingCoder.csproj index 8efde639..760b7ce5 100644 --- a/BuildingCoder/BuildingCoder/BuildingCoder.csproj +++ b/BuildingCoder/BuildingCoder/BuildingCoder.csproj @@ -108,6 +108,7 @@ + diff --git a/BuildingCoder/BuildingCoder/CmdDutAbbreviation.cs b/BuildingCoder/BuildingCoder/CmdDutAbbreviation.cs new file mode 100644 index 00000000..9307c40a --- /dev/null +++ b/BuildingCoder/BuildingCoder/CmdDutAbbreviation.cs @@ -0,0 +1,90 @@ +#region Header +// +// CmdDutAbbreviation.cs - Test the display unit type abbreviation array +// +// Copyright (C) 2013 by Jeremy Tammik, Autodesk Inc. All rights reserved. +// +#endregion // Header + +#region Namespaces +using System; +//using System.Collections.Generic; +//using System.IO; +using System.Linq; +using Autodesk.Revit.ApplicationServices; +using Autodesk.Revit.Attributes; +using Autodesk.Revit.DB; +using Autodesk.Revit.UI; +using System.Diagnostics; +//using Autodesk.Revit.UI.Selection; +#endregion // Namespaces + +namespace BuildingCoder +{ + [Transaction( TransactionMode.ReadOnly )] + class CmdDutAbbreviation : IExternalCommand + { + const string _s = "unexpected display unit type enumeration sequence"; + + + public Result Execute( + ExternalCommandData commandData, + ref string message, + ElementSet elements ) + { + Debug.Assert( 0 == (int) DisplayUnitType.DUT_METERS, _s ); + Debug.Assert( 1 == (int) DisplayUnitType.DUT_CENTIMETERS, _s ); + Debug.Assert( 2 == (int) DisplayUnitType.DUT_MILLIMETERS, _s ); + Debug.Assert( 3 == (int) DisplayUnitType.DUT_DECIMAL_FEET, _s ); + Debug.Assert( 4 == (int) DisplayUnitType.DUT_FEET_FRACTIONAL_INCHES, _s ); + Debug.Assert( 5 == (int) DisplayUnitType.DUT_FRACTIONAL_INCHES, _s ); + Debug.Assert( 6 == (int) DisplayUnitType.DUT_DECIMAL_INCHES, _s ); + Debug.Assert( 7 == (int) DisplayUnitType.DUT_ACRES, _s ); + Debug.Assert( 8 == (int) DisplayUnitType.DUT_HECTARES, _s ); + Debug.Assert( 9 == (int) DisplayUnitType.DUT_METERS_CENTIMETERS, _s ); + Debug.Assert( 10 == (int) DisplayUnitType.DUT_CUBIC_YARDS, _s ); + Debug.Assert( 11 == (int) DisplayUnitType.DUT_SQUARE_FEET, _s ); + Debug.Assert( 12 == (int) DisplayUnitType.DUT_SQUARE_METERS, _s ); + Debug.Assert( 13 == (int) DisplayUnitType.DUT_CUBIC_FEET, _s ); + Debug.Assert( 14 == (int) DisplayUnitType.DUT_CUBIC_METERS, _s ); + Debug.Assert( 15 == (int) DisplayUnitType.DUT_DECIMAL_DEGREES, _s ); + Debug.Assert( 16 == (int) DisplayUnitType.DUT_DEGREES_AND_MINUTES, _s ); + Debug.Assert( 17 == (int) DisplayUnitType.DUT_GENERAL, _s ); + Debug.Assert( 18 == (int) DisplayUnitType.DUT_FIXED, _s ); + Debug.Assert( 19 == (int) DisplayUnitType.DUT_PERCENTAGE, _s ); + Debug.Assert( 20 == (int) DisplayUnitType.DUT_SQUARE_INCHES, _s ); + Debug.Assert( 21 == (int) DisplayUnitType.DUT_SQUARE_CENTIMETERS, _s ); + Debug.Assert( 22 == (int) DisplayUnitType.DUT_SQUARE_MILLIMETERS, _s ); + Debug.Assert( 23 == (int) DisplayUnitType.DUT_CUBIC_INCHES, _s ); + Debug.Assert( 24 == (int) DisplayUnitType.DUT_CUBIC_CENTIMETERS, _s ); + Debug.Assert( 25 == (int) DisplayUnitType.DUT_CUBIC_MILLIMETERS, _s ); + Debug.Assert( 26 == (int) DisplayUnitType.DUT_LITERS, _s ); + + DisplayUnitType n + = DisplayUnitType.DUT_GALLONS_US; + + Debug.Print( "Here is a list of the first {0} " + + "display unit types with The Building Coder " + + "abbreviation and the valid unit symbols:\n", + (int) n ); + + for( DisplayUnitType i = DisplayUnitType.DUT_METERS; + i < n; ++i ) + { + Debug.Print( "{0,6} {1} valid unit symbols: {2}", + Util.DisplayUnitTypeAbbreviation[(int)i], + LabelUtils.GetLabelFor( i ), + //UnitFormatUtils.Format( UnitType. ??? + //UnitUtils.ConvertFromInternalUnits( 1, i ), + string.Join( ", ", FormatOptions + .GetValidUnitSymbols( i ) + .Select( + u => Util.UnitSymbolTypeString( u ) ) ), + + i ); + + } + return Result.Succeeded; + } + } +} diff --git a/BuildingCoder/BuildingCoder/Properties/AssemblyInfo.cs b/BuildingCoder/BuildingCoder/Properties/AssemblyInfo.cs index 34798009..de07a7a4 100644 --- a/BuildingCoder/BuildingCoder/Properties/AssemblyInfo.cs +++ b/BuildingCoder/BuildingCoder/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ // // You can specify all the values or you can default the Revision and Build Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion( "2014.0.104.2" )] -[assembly: AssemblyFileVersion( "2014.0.104.2" )] +[assembly: AssemblyVersion( "2014.0.105.0" )] +[assembly: AssemblyFileVersion( "2014.0.105.0" )] diff --git a/BuildingCoder/BuildingCoder/Util.cs b/BuildingCoder/BuildingCoder/Util.cs index b2936158..1c67271b 100644 --- a/BuildingCoder/BuildingCoder/Util.cs +++ b/BuildingCoder/BuildingCoder/Util.cs @@ -302,6 +302,40 @@ public static double CubicFootToCubicMeter( double volume ) { return volume * _convertCubicFootToCubicMeter; } + + /// + /// Hard coded abbreviations for the first 26 + /// DisplayUnitType enumeration values. + /// + public static string[] DisplayUnitTypeAbbreviation = new string[] { + "m", // DUT_METERS = 0, + "cm", // DUT_CENTIMETERS = 1, + "mm", // DUT_MILLIMETERS = 2, + "ft", // DUT_DECIMAL_FEET = 3, + "N/A", // DUT_FEET_FRACTIONAL_INCHES = 4, + "N/A", // DUT_FRACTIONAL_INCHES = 5, + "in", // DUT_DECIMAL_INCHES = 6, + "ac", // DUT_ACRES = 7, + "ha", // DUT_HECTARES = 8, + "N/A", // DUT_METERS_CENTIMETERS = 9, + "y^3", // DUT_CUBIC_YARDS = 10, + "ft^2", // DUT_SQUARE_FEET = 11, + "m^2", // DUT_SQUARE_METERS = 12, + "ft^3", // DUT_CUBIC_FEET = 13, + "m^3", // DUT_CUBIC_METERS = 14, + "deg", // DUT_DECIMAL_DEGREES = 15, + "N/A", // DUT_DEGREES_AND_MINUTES = 16, + "N/A", // DUT_GENERAL = 17, + "N/A", // DUT_FIXED = 18, + "%", // DUT_PERCENTAGE = 19, + "in^2", // DUT_SQUARE_INCHES = 20, + "cm^2", // DUT_SQUARE_CENTIMETERS = 21, + "mm^2", // DUT_SQUARE_MILLIMETERS = 22, + "in^3", // DUT_CUBIC_INCHES = 23, + "cm^3", // DUT_CUBIC_CENTIMETERS = 24, + "mm^3", // DUT_CUBIC_MILLIMETERS = 25, + "l" // DUT_LITERS = 26, + }; #endregion // Unit Handling #region Formatting @@ -502,6 +536,25 @@ public static string CurveTessellateString( return "curve tessellation " + PointArrayString( curve.Tessellate() ); } + + /// + /// Convert a UnitSymbolType enumeration value + /// to a brief human readable abbreviation string. + /// + public static string UnitSymbolTypeString( + UnitSymbolType u ) + { + string s = u.ToString(); + + Debug.Assert( s.StartsWith( "UST_" ), + "expected UnitSymbolType enumeration value to beging with UST_" ); + + s = s.Substring( 4 ) + .Replace( "_SUP_", "^" ) + .ToLower(); + + return s; + } #endregion // Formatting #region Display a message @@ -543,7 +596,7 @@ public static void ErrorMsg( string msg ) /// family and symbol name for a family instance, /// element id and element name. /// - public static string ElementDescription( + public static string ElementDescription( Element e ) { if( null == e ) @@ -567,13 +620,13 @@ public static string ElementDescription( ? string.Empty : fi.Symbol.Family.Name + " "; - string symbolName = ( null == fi + string symbolName = ( null == fi || e.Name.Equals( fi.Symbol.Name ) ) ? string.Empty : fi.Symbol.Name + " "; return string.Format( "{0} {1}{2}{3}<{4} {5}>", - typeName, categoryName, familyName, + typeName, categoryName, familyName, symbolName, e.Id.IntegerValue, e.Name ); } #endregion // Display a message @@ -636,9 +689,9 @@ public static Element GetSingleSelectedElement( Element e = null; SelElementSet set = doc.Selection.Elements; - if ( 1 == set.Size ) + if( 1 == set.Size ) { - foreach ( Element e2 in set ) + foreach( Element e2 in set ) { e = e2; } @@ -883,7 +936,7 @@ public static List GetPolygon( if( 0 < n ) { Debug.Assert( pts[0] - .IsAlmostEqualTo( polygon[n-1] ), + .IsAlmostEqualTo( polygon[n - 1] ), "expected last edge end point to " + "equal next edge start point" ); @@ -906,22 +959,22 @@ public static List GetPolygon( public static class JtFamilyParameterExtensionMethods { - public static bool IsShared( + public static bool IsShared( this FamilyParameter familyParameter ) { MethodInfo mi = familyParameter .GetType() - .GetMethod( "getParameter", - BindingFlags.Instance + .GetMethod( "getParameter", + BindingFlags.Instance | BindingFlags.NonPublic ); if( null == mi ) { - throw new InvalidOperationException( + throw new InvalidOperationException( "Could not find getParameter method" ); } - var parameter = mi.Invoke( familyParameter, + var parameter = mi.Invoke( familyParameter, new object[] { } ) as Parameter; return parameter.IsShared;