diff --git a/RvtVa3c/Command.cs b/RvtVa3c/Command.cs index 6b69d9d..6b4a141 100644 --- a/RvtVa3c/Command.cs +++ b/RvtVa3c/Command.cs @@ -54,7 +54,9 @@ public class Command : IExternalCommand /// Export a given 3D view to JSON using /// our custom exporter context. /// - public void ExportView3D( View3D view3d, string filename ) + public void ExportView3D( + View3D view3d, + string filename ) { AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve; @@ -81,11 +83,9 @@ Va3cExportContext context #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 @@ -311,89 +311,88 @@ public Result Execute( { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; - Autodesk.Revit.ApplicationServices.Application app = uiapp.Application; + 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; - } - 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; - } - } + // Check that we are in a 3D view. - // Dialog to ask the user if they want to - // choose which parameters to export or just - // export them all. + View3D view = doc.ActiveView as View3D; - 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( null == view ) + { + Util.ErrorMsg( + "You must be in a 3D view to export." ); - if( tdResult == TaskDialogResult.Yes ) - { - // Filter the properties - filterElementParameters( doc, includeT ); - _filterParameters = true; - if( ParameterFilter.status == "cancelled" ) - { - ParameterFilter.status = ""; - return Result.Cancelled; - } - } - else _filterParameters = false; + return Result.Failed; + } + // Prompt for output filename selection. - ViewOrientation3D vo = ( (View3D) doc.ActiveView ).GetOrientation(); + string filename = doc.PathName; - // Save file + if( 0 == filename.Length ) + { + filename = doc.Title; + } - filename = Path.GetFileName( filename ) + ".js"; + if( null == _output_folder_path ) + { + // Sometimes the command fails if the file is + // detached from central and not saved locally - if( SelectFile( ref _output_folder_path, - ref filename ) ) + try { - filename = Path.Combine( _output_folder_path, + _output_folder_path = Path.GetDirectoryName( filename ); + } + catch + { + TaskDialog.Show( "Folder not found", + "Please save the file and run the command again." ); + return Result.Failed; + } + } - ExportView3D( doc.ActiveView as View3D, - filename ); + filename = Path.GetFileName( filename ) + ".js"; - return Result.Succeeded; - } + if( !SelectFile( ref _output_folder_path, + ref filename ) ) + { return Result.Cancelled; } - else + + filename = Path.Combine( _output_folder_path, + filename ); + + // Ask user whether to interactively 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"; + + if( TaskDialogResult.Yes == td.Show() ) { - Util.ErrorMsg( - "You must be in a 3D view to export." ); + filterElementParameters( doc, td.WasVerificationChecked() ); + if( ParameterFilter.status == "cancelled" ) + { + ParameterFilter.status = ""; + return Result.Cancelled; + } } - return Result.Failed; + + // Save file. + + ExportView3D( doc.ActiveView as View3D, + filename ); + + return Result.Succeeded; } } }