Skip to content

Commit

Permalink
implemented Display Unit Type Abbreviation command CmdDutAbbreviation…
Browse files Browse the repository at this point in the history
… to test the display unit type abbreviation array
  • Loading branch information
Jeremy Tammik committed Nov 1, 2013
1 parent 77fb870 commit 36e327a
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 13 deletions.
8 changes: 8 additions & 0 deletions BcSamples.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions BuildingCoder/BuildingCoder/BuildingCoder.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
<Compile Include="CmdDimensionWallsIterateFaces.cs" />
<Compile Include="CmdDisallowJoin.cs" />
<Compile Include="CmdDuplicateElements.cs" />
<Compile Include="CmdDutAbbreviation.cs" />
<Compile Include="CmdEllipticalArc.cs" />
<Compile Include="CmdExportImage.cs" />
<Compile Include="CmdExportSolidToSat.cs" />
Expand Down
90 changes: 90 additions & 0 deletions BuildingCoder/BuildingCoder/CmdDutAbbreviation.cs
Original file line number Diff line number Diff line change
@@ -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<UnitSymbolType,string>(
u => Util.UnitSymbolTypeString( u ) ) ),

i );

}
return Result.Succeeded;
}
}
}
4 changes: 2 additions & 2 deletions BuildingCoder/BuildingCoder/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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" )]
75 changes: 64 additions & 11 deletions BuildingCoder/BuildingCoder/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,40 @@ public static double CubicFootToCubicMeter( double volume )
{
return volume * _convertCubicFootToCubicMeter;
}

/// <summary>
/// Hard coded abbreviations for the first 26
/// DisplayUnitType enumeration values.
/// </summary>
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
Expand Down Expand Up @@ -502,6 +536,25 @@ public static string CurveTessellateString(
return "curve tessellation "
+ PointArrayString( curve.Tessellate() );
}

/// <summary>
/// Convert a UnitSymbolType enumeration value
/// to a brief human readable abbreviation string.
/// </summary>
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
Expand Down Expand Up @@ -543,7 +596,7 @@ public static void ErrorMsg( string msg )
/// family and symbol name for a family instance,
/// element id and element name.
/// </summary>
public static string ElementDescription(
public static string ElementDescription(
Element e )
{
if( null == e )
Expand All @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -883,7 +936,7 @@ public static List<XYZ> 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" );

Expand All @@ -906,22 +959,22 @@ public static List<XYZ> 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;
Expand Down

0 comments on commit 36e327a

Please sign in to comment.