From 8b28dace25ab3d89e02ffe983aa4b1ef673770d8 Mon Sep 17 00:00:00 2001 From: Jeremy Tammik Date: Wed, 4 Mar 2015 23:22:23 +0100 Subject: [PATCH] checked and edited anapujol's filter parameter ui merged pull request #7 --- RvtVa3c/Command.cs | 640 +++++++++++++++-------------- RvtVa3c/Properties/AssemblyInfo.cs | 5 +- RvtVa3c/Util.cs | 542 ++++++++++++------------ 3 files changed, 599 insertions(+), 588 deletions(-) diff --git a/RvtVa3c/Command.cs b/RvtVa3c/Command.cs index 675dce8..6b69d9d 100644 --- a/RvtVa3c/Command.cs +++ b/RvtVa3c/Command.cs @@ -1,10 +1,11 @@ #region Namespaces using System; -using System.Windows.Interop; using System.Collections.Generic; using System.Diagnostics; -using System.IO; using System.Drawing; +using System.IO; +using System.Linq; +using System.Windows.Interop; using Autodesk.Revit.ApplicationServices; using Autodesk.Revit.Attributes; using Autodesk.Revit.DB; @@ -13,381 +14,386 @@ using System.Windows.Forms; using SaveFileDialog = System.Windows.Forms.SaveFileDialog; using DialogResult = System.Windows.Forms.DialogResult; -using System.Linq; - - - -#endregion +#endregion // Namespaces namespace RvtVa3c { - [Transaction(TransactionMode.Manual)] - public class Command : IExternalCommand + [Transaction( TransactionMode.Manual )] + public class Command : IExternalCommand + { + /// + /// Custom assembly resolver to find our support + /// DLL without being forced to place our entire + /// application in a subfolder of the Revit.exe + /// directory. + /// + System.Reflection.Assembly + CurrentDomain_AssemblyResolve( + object sender, + ResolveEventArgs args ) { - /// - /// Custom assembly resolver to find our support - /// DLL without being forced to place our entire - /// application in a subfolder of the Revit.exe - /// directory. - /// - System.Reflection.Assembly - CurrentDomain_AssemblyResolve( - object sender, - ResolveEventArgs args) - { - if (args.Name.Contains("Newtonsoft")) - { - string filename = Path.GetDirectoryName( - System.Reflection.Assembly - .GetExecutingAssembly().Location); + if( args.Name.Contains( "Newtonsoft" ) ) + { + string filename = Path.GetDirectoryName( + System.Reflection.Assembly + .GetExecutingAssembly().Location ); - filename = Path.Combine(filename, - "Newtonsoft.Json.dll"); + filename = Path.Combine( filename, + "Newtonsoft.Json.dll" ); - if (File.Exists(filename)) - { - return System.Reflection.Assembly - .LoadFrom(filename); - } - } - return null; + if( File.Exists( filename ) ) + { + return System.Reflection.Assembly + .LoadFrom( filename ); } + } + return null; + } - /// - /// Export a given 3D view to JSON using - /// our custom exporter context. - /// - public void ExportView3D(View3D view3d, string filename) - { - AppDomain.CurrentDomain.AssemblyResolve - += CurrentDomain_AssemblyResolve; + /// + /// Export a given 3D view to JSON using + /// our custom exporter context. + /// + public void ExportView3D( View3D view3d, string filename ) + { + AppDomain.CurrentDomain.AssemblyResolve + += CurrentDomain_AssemblyResolve; - Document doc = view3d.Document; + Document doc = view3d.Document; - Va3cExportContext context - = new Va3cExportContext(doc, filename); + Va3cExportContext context + = new Va3cExportContext( doc, filename ); - CustomExporter exporter = new CustomExporter( - doc, context); + CustomExporter exporter = new CustomExporter( + doc, context ); - // Note: Excluding faces just suppresses the - // OnFaceBegin calls, not the actual processing - // of face tessellation. Meshes of the faces - // will still be received by the context. + // Note: Excluding faces just suppresses the + // OnFaceBegin calls, not the actual processing + // of face tessellation. Meshes of the faces + // will still be received by the context. - exporter.IncludeFaces = false; + exporter.IncludeFaces = false; - exporter.ShouldStopOnError = false; + exporter.ShouldStopOnError = false; - exporter.Export(view3d); - } + exporter.Export( view3d ); + } + #region UI to Filter Parameters + public static ParameterFilter _filter; + public static bool _filterParameters = false; + public static TabControl _tabControl; + public static Dictionary> _parameterDictionary; + public static Dictionary> _toExportDictionary; + public static bool includeT = false; + + /// + /// Function to filter the parameters of the objects in the scene + /// + /// Revit Document + /// Include Type Parameters in the filter dialog + public void filterElementParameters( Document doc, bool includeType ) + { + _parameterDictionary = new Dictionary>(); + _toExportDictionary = new Dictionary>(); - public static ParameterFilter _filter; - public static bool _filterParameters = false; - public static TabControl _tabControl; - public static Dictionary> _parameterDictionary; - public static Dictionary> _toExportDictionary; - public static bool includeT = false; + FilteredElementCollector collector = new FilteredElementCollector( doc, doc.ActiveView.Id ); - /// - /// Function to filter the parameters of the objects in the scene - /// - /// Revit Document - /// Include Type Parameters in the filter dialog - public void filterElementParameters(Document doc,bool includeType) - { - _parameterDictionary = new Dictionary>(); - _toExportDictionary = new Dictionary>(); + // Create a dictionary with all the properties for each category. - FilteredElementCollector collector = new FilteredElementCollector(doc, doc.ActiveView.Id); + foreach( var fi in collector ) + { - // create a dictionary with all the properties for each category - foreach (var fi in collector) - { + string category = fi.Category.Name; - string category = fi.Category.Name; + if( category != "Title Blocks" && category != "Generic Annotations" && category != "Detail Items" && category != "Cameras" ) + { + IList parameters = fi.GetOrderedParameters(); + List parameterNames = new List(); - if (category!= "Title Blocks" && category!="Generic Annotations" && category != "Detail Items" && category!= "Cameras") - { - IList parameters = fi.GetOrderedParameters(); - List parameterNames = new List(); + foreach( Parameter p in parameters ) + { + string pName = p.Definition.Name; + string tempVal = ""; - foreach (Parameter p in parameters) + if( StorageType.String == p.StorageType ) + { + tempVal = p.AsString(); + } + else + { + tempVal = p.AsValueString(); + } + if( !string.IsNullOrEmpty( tempVal ) ) + { + if( _parameterDictionary.ContainsKey( category ) ) + { + if( !_parameterDictionary[category].Contains( pName ) ) + { + _parameterDictionary[category].Add( pName ); + } + } + else + { + parameterNames.Add( pName ); + } + } + } + if( parameterNames.Count > 0 ) + { + _parameterDictionary.Add( category, parameterNames ); + } + if( includeType ) + { + ElementId idType = fi.GetTypeId(); + + if( ElementId.InvalidElementId != idType ) + { + Element typ = doc.GetElement( idType ); + parameters = typ.GetOrderedParameters(); + List parameterTypes = new List(); + foreach( Parameter p in parameters ) + { + string pName = "Type " + p.Definition.Name; + string tempVal = ""; + if( !_parameterDictionary[category].Contains( pName ) ) + { + if( StorageType.String == p.StorageType ) + { + tempVal = p.AsString(); + } + else + { + tempVal = p.AsValueString(); + } + + if( !string.IsNullOrEmpty( tempVal ) ) + { + if( _parameterDictionary.ContainsKey( category ) ) { - string pName = p.Definition.Name; - string tempVal = ""; - - if (StorageType.String == p.StorageType) - { - tempVal = p.AsString(); - } - else - { - tempVal = p.AsValueString(); - } - if (!string.IsNullOrEmpty(tempVal)) - { - if (_parameterDictionary.ContainsKey(category)) - { - if (!_parameterDictionary[category].Contains(pName)) - { - _parameterDictionary[category].Add(pName); - } - } - else - { - parameterNames.Add(pName); - } - } + if( !_parameterDictionary[category].Contains( pName ) ) + { + _parameterDictionary[category].Add( pName ); + } } - if (parameterNames.Count > 0) + else { - _parameterDictionary.Add(category, parameterNames); + parameterTypes.Add( pName ); } - if (includeType) - { - ElementId idType = fi.GetTypeId(); - - if (ElementId.InvalidElementId != idType) - { - Element typ = doc.GetElement(idType); - parameters = typ.GetOrderedParameters(); - List parameterTypes = new List(); - foreach (Parameter p in parameters) - { - string pName = "Type " + p.Definition.Name; - string tempVal = ""; - if (!_parameterDictionary[category].Contains(pName)) - { - if (StorageType.String == p.StorageType) - { - tempVal = p.AsString(); - } - else - { - tempVal = p.AsValueString(); - } - - if (!string.IsNullOrEmpty(tempVal)) - { - if (_parameterDictionary.ContainsKey(category)) - { - if (!_parameterDictionary[category].Contains(pName)) - { - _parameterDictionary[category].Add(pName); - } - } - else - { - parameterTypes.Add(pName); - } - } - } - } - if (parameterTypes.Count > 0) - { - _parameterDictionary[category].AddRange(parameterTypes); - } - } - - } + } } + } + if( parameterTypes.Count > 0 ) + { + _parameterDictionary[category].AddRange( parameterTypes ); + } } - //CREATE FILTER UI - _filter = new ParameterFilter(); + } + } + } + + // Create filter UI. + + _filter = new ParameterFilter(); + + _tabControl = new TabControl(); + _tabControl.Size = new System.Drawing.Size( 600, 375 ); + _tabControl.Location = new System.Drawing.Point( 0, 55 ); + _tabControl.Anchor = ( (System.Windows.Forms.AnchorStyles) ( ( ( ( System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom ) + | System.Windows.Forms.AnchorStyles.Left ) + | System.Windows.Forms.AnchorStyles.Right ) ) ); + + int j = 8; + + // Populate the parameters as a checkbox in each tab + foreach( string c in _parameterDictionary.Keys ) + { + //Create a checklist + CheckedListBox checkList = new CheckedListBox(); + + //set the properties of the checklist + checkList.Anchor = ( (System.Windows.Forms.AnchorStyles) ( ( System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right ) ) ); + checkList.FormattingEnabled = true; + checkList.HorizontalScrollbar = true; + checkList.Items.AddRange( _parameterDictionary[c].ToArray() ); + checkList.MultiColumn = true; + checkList.Size = new System.Drawing.Size( 560, 360 ); + checkList.ColumnWidth = 200; + checkList.CheckOnClick = true; + checkList.TabIndex = j; + j++; + + for( int i = 0; i <= ( checkList.Items.Count - 1 ); i++ ) + { + checkList.SetItemCheckState( i, CheckState.Checked ); + } - _tabControl = new TabControl(); - _tabControl.Size = new System.Drawing.Size(600, 375); - _tabControl.Location = new System.Drawing.Point(0, 55); - _tabControl.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); + //add a tab + TabPage tab = new TabPage( c ); + tab.Name = c; - int j = 8; + //attach the checklist to the tab + tab.Controls.Add( checkList ); - // Populate the parameters as a checkbox in each tab - foreach (string c in _parameterDictionary.Keys) - { - //Create a checklist - CheckedListBox checkList = new CheckedListBox(); - - //set the properties of the checklist - checkList.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); - checkList.FormattingEnabled = true; - checkList.HorizontalScrollbar = true; - checkList.Items.AddRange(_parameterDictionary[c].ToArray()); - checkList.MultiColumn = true; - checkList.Size = new System.Drawing.Size(560, 360); - checkList.ColumnWidth = 200; - checkList.CheckOnClick = true; - checkList.TabIndex = j; - j++; - - for (int i = 0; i <= (checkList.Items.Count - 1); i++) - { - checkList.SetItemCheckState(i, CheckState.Checked); - } + // attach the tab to the tab control + _tabControl.TabPages.Add( tab ); + } - //add a tab - TabPage tab = new TabPage(c); - tab.Name = c; + // Attach the tab control to the filter form - //attach the checklist to the tab - tab.Controls.Add(checkList); + _filter.Controls.Add( _tabControl ); - // attach the tab to the tab control - _tabControl.TabPages.Add(tab); - } + // Display filter ui - // Attach the tab control to the filter form - _filter.Controls.Add(_tabControl); + _filter.ShowDialog(); - // DISPLAY FILTER UI - _filter.ShowDialog(); + // Loop thru each tab and get the parameters to export - // Loop thru each tab and get the parameters to export - foreach (TabPage tab in _tabControl.TabPages) - { - List parametersToExport = new List(); - foreach (var checkedP in ((CheckedListBox)tab.Controls[0]).CheckedItems) - { - parametersToExport.Add(checkedP.ToString()); - } - _toExportDictionary.Add(tab.Name, parametersToExport); - } + foreach( TabPage tab in _tabControl.TabPages ) + { + List parametersToExport = new List(); + foreach( var checkedP in ( (CheckedListBox) tab.Controls[0] ).CheckedItems ) + { + parametersToExport.Add( checkedP.ToString() ); } + _toExportDictionary.Add( tab.Name, parametersToExport ); + } + } + #endregion // UI to Filter Parameters + + #region SelectFile + /// + /// Store the last user selected output folder + /// in the current editing session. + /// + static string _output_folder_path = null; + + /// + /// Return true is user selects and confirms + /// output file name and folder. + /// + static bool SelectFile( + ref string folder_path, + ref string filename ) + { + SaveFileDialog dlg = new SaveFileDialog(); + dlg.Title = "Select JSON Output File"; + dlg.Filter = "JSON files|*.js"; - #region SelectFile - /// - /// Store the last user selected output folder - /// in the current editing session. - /// - static string _output_folder_path = null; - - - /// - /// Return true is user selects and confirms - /// output file name and folder. - /// - static bool SelectFile( - ref string folder_path, - ref string filename) - { - SaveFileDialog dlg = new SaveFileDialog(); - - dlg.Title = "Select JSON Output File"; - dlg.Filter = "JSON files|*.js"; + if( null != folder_path + && 0 < folder_path.Length ) + { + dlg.InitialDirectory = folder_path; + } - if (null != folder_path - && 0 < folder_path.Length) - { - dlg.InitialDirectory = folder_path; - } + dlg.FileName = filename; - dlg.FileName = filename; + bool rc = DialogResult.OK == dlg.ShowDialog(); - bool rc = DialogResult.OK == dlg.ShowDialog(); + if( rc ) + { + filename = Path.Combine( dlg.InitialDirectory, + dlg.FileName ); - if (rc) - { - filename = Path.Combine(dlg.InitialDirectory, - dlg.FileName); + folder_path = Path.GetDirectoryName( + filename ); + } + return rc; + } + #endregion // SelectFile - folder_path = Path.GetDirectoryName( - filename); - } - return rc; + public Result Execute( + ExternalCommandData commandData, + ref string message, + ElementSet elements ) + { + UIApplication uiapp = commandData.Application; + UIDocument uidoc = uiapp.ActiveUIDocument; + Autodesk.Revit.ApplicationServices.Application app = uiapp.Application; + Document doc = uidoc.Document; + + if( doc.ActiveView is View3D ) + { + string filename = doc.PathName; + if( 0 == filename.Length ) + { + filename = doc.Title; } - #endregion // SelectFile - - public Result Execute( - ExternalCommandData commandData, - ref string message, - ElementSet elements) + if( null == _output_folder_path ) { - UIApplication uiapp = commandData.Application; - UIDocument uidoc = uiapp.ActiveUIDocument; - Autodesk.Revit.ApplicationServices.Application app = uiapp.Application; - Document doc = uidoc.Document; + // Sometimes the command fails if the file is + // detached from central and not saved locally + + try + { + _output_folder_path = Path.GetDirectoryName( + filename ); + } + catch + { + TaskDialog.Show( "Folder not found", + "Please save the file and run the command again." ); + return Result.Failed; + } + } - + // Dialog to ask the user if they want to + // choose which parameters to export or just + // export them all. - if (doc.ActiveView is View3D) - { - string filename = doc.PathName; - if (0 == filename.Length) - { - filename = doc.Title; - } - if (null == _output_folder_path) - { - //sometimes the command fails if the file is detached from central and not saved locally - try - { - _output_folder_path = Path.GetDirectoryName( - filename); - } - catch - { - TaskDialog.Show("Folder not found", "Please, save the file and run the command again"); - return Result.Failed; - } - } + TaskDialog td = new TaskDialog( "Ask user to filter parameters" ); + td.Title = "Filter parameters"; + td.CommonButtons = TaskDialogCommonButtons.No | TaskDialogCommonButtons.Yes; + td.MainInstruction = "Do you want to filter the parameters of the objects to be exported?"; + td.MainContent = "Click Yes and you will be able to select parameters for each category in the next window"; + td.AllowCancellation = true; + td.VerificationText = "Check this to include type properties"; + TaskDialogResult tdResult = td.Show(); - //Dialog to ask the user if they want to choose which parameters to export or just export them all - TaskDialog td = new TaskDialog("Ask user to filter parameters"); - td.Title = "Filter parameters"; - td.CommonButtons = TaskDialogCommonButtons.No | TaskDialogCommonButtons.Yes; - td.MainInstruction = "Do you want to filter the parameters of the objects to be exported?"; - td.MainContent = "Click Yes and you will be able to select parameters for each category in the next window"; - td.AllowCancellation = true; - td.VerificationText = "Check this to include type properties"; - TaskDialogResult tdResult = td.Show(); + if( td.WasVerificationChecked() ) includeT = true; + else includeT = false; - if (td.WasVerificationChecked()) includeT = true; - else includeT = false; + if( tdResult == TaskDialogResult.Yes ) + { + // Filter the properties + filterElementParameters( doc, includeT ); + _filterParameters = true; + if( ParameterFilter.status == "cancelled" ) + { + ParameterFilter.status = ""; + return Result.Cancelled; + } + } + else _filterParameters = false; - if (tdResult == TaskDialogResult.Yes) - { - // Filter the properties - filterElementParameters(doc, includeT); - _filterParameters = true; - if (ParameterFilter.status == "cancelled") - { - ParameterFilter.status = ""; - return Result.Cancelled; - } - } - else _filterParameters = false; + ViewOrientation3D vo = ( (View3D) doc.ActiveView ).GetOrientation(); - ViewOrientation3D vo = ((View3D)doc.ActiveView).GetOrientation(); + // Save file - // Save file - filename = Path.GetFileName(filename) + ".js"; + filename = Path.GetFileName( filename ) + ".js"; - if (SelectFile(ref _output_folder_path, - ref filename)) - { - filename = Path.Combine(_output_folder_path, - filename); + if( SelectFile( ref _output_folder_path, + ref filename ) ) + { + filename = Path.Combine( _output_folder_path, + filename ); - ExportView3D(doc.ActiveView as View3D, - filename); + ExportView3D( doc.ActiveView as View3D, + filename ); - return Result.Succeeded; - } - return Result.Cancelled; - } - else - { - Util.ErrorMsg( - "You must be in a 3D view to export."); - } - return Result.Failed; + return Result.Succeeded; } + return Result.Cancelled; + } + else + { + Util.ErrorMsg( + "You must be in a 3D view to export." ); + } + return Result.Failed; } + } } diff --git a/RvtVa3c/Properties/AssemblyInfo.cs b/RvtVa3c/Properties/AssemblyInfo.cs index 364d47b..242b455 100644 --- a/RvtVa3c/Properties/AssemblyInfo.cs +++ b/RvtVa3c/Properties/AssemblyInfo.cs @@ -46,6 +46,7 @@ // 2014-11-24 2015.0.0.27 skip elements with null category // 2014-11-25 2015.0.0.28 skip elements with null category in OnElementEnd as well // 2015-02-15 2015.0.0.29 incremented copyright year +// 2015-03-04 2015.0.0.30 integrated anapujol's UI to filter parameters, cf. description in https://github.com/va3c/RvtVa3c/pull/6 // -[assembly: AssemblyVersion( "2015.0.0.29" )] -[assembly: AssemblyFileVersion( "2015.0.0.29" )] +[assembly: AssemblyVersion( "2015.0.0.30" )] +[assembly: AssemblyFileVersion( "2015.0.0.30" )] diff --git a/RvtVa3c/Util.cs b/RvtVa3c/Util.cs index 5aebba0..13ba604 100644 --- a/RvtVa3c/Util.cs +++ b/RvtVa3c/Util.cs @@ -1,319 +1,323 @@ #region Namespaces using System; -using Autodesk.Revit.UI; using System.Collections.Generic; using System.Diagnostics; +using Autodesk.Revit.UI; using Autodesk.Revit.DB; using WinForms = System.Windows.Forms; #endregion // Namespaces namespace RvtVa3c { - class Util + class Util + { + const string _caption = "vA3C"; + + /// + /// Display an error message to the user. + /// + public static void ErrorMsg( string msg ) { - const string _caption = "vA3C"; + Debug.WriteLine( msg ); + WinForms.MessageBox.Show( msg, + _caption, + WinForms.MessageBoxButtons.OK, + WinForms.MessageBoxIcon.Error ); + } - /// - /// Display an error message to the user. - /// - public static void ErrorMsg(string msg) - { - Debug.WriteLine(msg); - WinForms.MessageBox.Show(msg, - _caption, - WinForms.MessageBoxButtons.OK, - WinForms.MessageBoxIcon.Error); - } + /// + /// Return a string for a real number + /// formatted to two decimal places. + /// + public static string RealString( double a ) + { + return a.ToString( "0.##" ); + } - /// - /// Return a string for a real number - /// formatted to two decimal places. - /// - public static string RealString(double a) - { - return a.ToString("0.##"); - } + /// + /// Return a string for an XYZ point + /// or vector with its coordinates + /// formatted to two decimal places. + /// + public static string PointString( XYZ p ) + { + return string.Format( "({0},{1},{2})", + RealString( p.X ), + RealString( p.Y ), + RealString( p.Z ) ); + } - /// - /// Return a string for an XYZ point - /// or vector with its coordinates - /// formatted to two decimal places. - /// - public static string PointString(XYZ p) - { - return string.Format("({0},{1},{2})", - RealString(p.X), - RealString(p.Y), - RealString(p.Z)); - } + /// + /// Return an integer value for a Revit Color. + /// + public static int ColorToInt( Color color ) + { + return ( (int) color.Red ) << 16 + | ( (int) color.Green ) << 8 + | (int) color.Blue; + } - /// - /// Return an integer value for a Revit Color. - /// - public static int ColorToInt(Color color) - { - return ((int)color.Red) << 16 - | ((int)color.Green) << 8 - | (int)color.Blue; - } + /// + /// Extract a true or false value from the given + /// string, accepting yes/no, Y/N, true/false, T/F + /// and 1/0. We are extremely tolerant, i.e., any + /// value starting with one of the characters y, n, + /// t or f is also accepted. Return false if no + /// valid Boolean value can be extracted. + /// + public static bool GetTrueOrFalse( + string s, + out bool val ) + { + val = false; + + if( s.Equals( Boolean.TrueString, + StringComparison.OrdinalIgnoreCase ) ) + { + val = true; + return true; + } + if( s.Equals( Boolean.FalseString, + StringComparison.OrdinalIgnoreCase ) ) + { + return true; + } + if( s.Equals( "1" ) ) + { + val = true; + return true; + } + if( s.Equals( "0" ) ) + { + return true; + } + s = s.ToLower(); + + if( 't' == s[0] || 'y' == s[0] ) + { + val = true; + return true; + } + if( 'f' == s[0] || 'n' == s[0] ) + { + return true; + } + return false; + } - /// - /// Extract a true or false value from the given - /// string, accepting yes/no, Y/N, true/false, T/F - /// and 1/0. We are extremely tolerant, i.e., any - /// value starting with one of the characters y, n, - /// t or f is also accepted. Return false if no - /// valid Boolean value can be extracted. - /// - public static bool GetTrueOrFalse( - string s, - out bool val) - { - val = false; + /// + /// Return a string describing the given element: + /// .NET type name, + /// category name, + /// family and symbol name for a family instance, + /// element id and element name. + /// + public static string ElementDescription( + Element e ) + { + if( null == e ) + { + return ""; + } - if (s.Equals(Boolean.TrueString, - StringComparison.OrdinalIgnoreCase)) - { - val = true; - return true; - } - if (s.Equals(Boolean.FalseString, - StringComparison.OrdinalIgnoreCase)) - { - return true; - } - if (s.Equals("1")) - { - val = true; - return true; - } - if (s.Equals("0")) - { - return true; - } - s = s.ToLower(); + // For a wall, the element name equals the + // wall type name, which is equivalent to the + // family name ... - if ('t' == s[0] || 'y' == s[0]) - { - val = true; - return true; - } - if ('f' == s[0] || 'n' == s[0]) - { - return true; - } - return false; - } + FamilyInstance fi = e as FamilyInstance; - /// - /// Return a string describing the given element: - /// .NET type name, - /// category name, - /// family and symbol name for a family instance, - /// element id and element name. - /// - public static string ElementDescription( - Element e) - { - if (null == e) - { - return ""; - } + string typeName = e.GetType().Name; - // For a wall, the element name equals the - // wall type name, which is equivalent to the - // family name ... + string categoryName = ( null == e.Category ) + ? string.Empty + : e.Category.Name + " "; - FamilyInstance fi = e as FamilyInstance; + string familyName = ( null == fi ) + ? string.Empty + : fi.Symbol.Family.Name + " "; - string typeName = e.GetType().Name; + string symbolName = ( null == fi + || e.Name.Equals( fi.Symbol.Name ) ) + ? string.Empty + : fi.Symbol.Name + " "; - string categoryName = (null == e.Category) - ? string.Empty - : e.Category.Name + " "; + return string.Format( "{0} {1}{2}{3}<{4} {5}>", + typeName, categoryName, familyName, + symbolName, e.Id.IntegerValue, e.Name ); + } - string familyName = (null == fi) - ? string.Empty - : fi.Symbol.Family.Name + " "; + /// + /// Return a dictionary of all the given + /// element parameter names and values. + /// + public static Dictionary + GetElementProperties( + Element e, + bool includeType ) + { + IList parameters + = e.GetOrderedParameters(); - string symbolName = (null == fi - || e.Name.Equals(fi.Symbol.Name)) - ? string.Empty - : fi.Symbol.Name + " "; + Dictionary a + = new Dictionary( + parameters.Count ); - return string.Format("{0} {1}{2}{3}<{4} {5}>", - typeName, categoryName, familyName, - symbolName, e.Id.IntegerValue, e.Name); - } - /// - /// Return a dictionary of all the given - /// element parameter names and values. - /// - public static Dictionary - GetElementProperties( - Element e, - bool includeType) - { - IList parameters - = e.GetOrderedParameters(); - Dictionary a - = new Dictionary( - parameters.Count); + string key; + string val; - string key; - string val; + foreach( Parameter p in parameters ) + { + key = p.Definition.Name; + if( !a.ContainsKey( key ) ) + { + if( StorageType.String == p.StorageType ) + { + val = p.AsString(); + } + else + { + val = p.AsValueString(); + } + + if( !string.IsNullOrEmpty( val ) ) + { + a.Add( key, val ); + } + } + } + if( includeType ) + { + ElementId idType = e.GetTypeId(); - foreach (Parameter p in parameters) + if( ElementId.InvalidElementId != idType ) + { + Document doc = e.Document; + Element typ = doc.GetElement( idType ); + parameters = typ.GetOrderedParameters(); + foreach( Parameter p in parameters ) + { + key = "Type " + p.Definition.Name; + + if( !a.ContainsKey( key ) ) { - key = p.Definition.Name; - - if (!a.ContainsKey(key)) - { - if (StorageType.String == p.StorageType) - { - val = p.AsString(); - } - else - { - val = p.AsValueString(); - } - - if (!string.IsNullOrEmpty(val)) - { - a.Add(key, val); - } - } + if( StorageType.String == p.StorageType ) + { + val = p.AsString(); + } + else + { + val = p.AsValueString(); + } + + if( !string.IsNullOrEmpty( val ) ) + { + a.Add( key, val ); + } } + } + } + } + return a; + } - if (includeType) - { - ElementId idType = e.GetTypeId(); - if (ElementId.InvalidElementId != idType) - { - Document doc = e.Document; - Element typ = doc.GetElement(idType); - parameters = typ.GetOrderedParameters(); - foreach (Parameter p in parameters) - { - key = "Type " + p.Definition.Name; - - if (!a.ContainsKey(key)) - { - if (StorageType.String == p.StorageType) - { - val = p.AsString(); - } - else - { - val = p.AsValueString(); - } - - if (!string.IsNullOrEmpty(val)) - { - a.Add(key, val); - } - } - } - } + /// + /// Return a dictionary of all the given + /// element parameter names and values. + /// + public static Dictionary + GetElementFilteredProperties( + Element e, + bool includeType ) + { + IList parameters + = e.GetOrderedParameters(); + + Dictionary a + = new Dictionary( + parameters.Count ); + + string key; + string val; + string cat = e.Category.Name; + + // Make sure that the file has a tab for that category. + + if( Command._toExportDictionary.ContainsKey( cat ) ) + { + foreach( Parameter p in parameters ) + { + key = p.Definition.Name; + + // Check whether the property has been checked. + + if( Command._toExportDictionary[cat].Contains( key ) ) + { + if( !a.ContainsKey( key ) ) + { + if( StorageType.String == p.StorageType ) + { + val = p.AsString(); + } + else + { + val = p.AsValueString(); + } + + if( !string.IsNullOrEmpty( val ) ) + { + a.Add( key, val ); + } } - return a; + } } - - /// - /// Return a dictionary of all the given - /// element parameter names and values. - /// - public static Dictionary - GetElementFilteredProperties( - Element e, - bool includeType) + if( includeType ) { - IList parameters - = e.GetOrderedParameters(); - - Dictionary a - = new Dictionary( - parameters.Count); - - string key; - string val; - string cat = e.Category.Name; - //making sure that the file has a tab for that category - if (Command._toExportDictionary.ContainsKey(cat)) + ElementId idType = e.GetTypeId(); + + if( ElementId.InvalidElementId != idType ) + { + Document doc = e.Document; + Element typ = doc.GetElement( idType ); + parameters = typ.GetOrderedParameters(); + + foreach( Parameter p in parameters ) { - foreach (Parameter p in parameters) - { - key = p.Definition.Name; - - //checking if the property has been checked - if (Command._toExportDictionary[cat].Contains(key)) - { - if (!a.ContainsKey(key)) - { - if (StorageType.String == p.StorageType) - { - val = p.AsString(); - } - else - { - val = p.AsValueString(); - } - - if (!string.IsNullOrEmpty(val)) - { - a.Add(key, val); - } - } - } - } + key = "Type " + p.Definition.Name; + + // Check whether the property has been checked. - if (includeType) + if( Command._toExportDictionary[cat].Contains( key ) ) + { + if( !a.ContainsKey( key ) ) { - ElementId idType = e.GetTypeId(); - - if (ElementId.InvalidElementId != idType) - { - Document doc = e.Document; - Element typ = doc.GetElement(idType); - parameters = typ.GetOrderedParameters(); - - foreach (Parameter p in parameters) - { - key = "Type " + p.Definition.Name; - - //checking if the property has been checked - if (Command._toExportDictionary[cat].Contains(key)) - { - if (!a.ContainsKey(key)) - { - if (StorageType.String == p.StorageType) - { - val = p.AsString(); - } - else - { - val = p.AsValueString(); - } - - if (!string.IsNullOrEmpty(val)) - { - a.Add(key, val); - } - } - } - } - } + if( StorageType.String == p.StorageType ) + { + val = p.AsString(); + } + else + { + val = p.AsValueString(); + } + + if( !string.IsNullOrEmpty( val ) ) + { + a.Add( key, val ); + } } + } } - return a; + } } + } + return a; } + } }