public Result Execute(
            ExternalCommandData InCommandData,                          // contains reference to Application and View
            ref string OutCommandMessage,                               // error message to display in the failure dialog when the command returns "Failed"
            ElementSet OutElements                                      // set of problem elements to display in the failure dialog when the command returns "Failed"
            )
        {
            Autodesk.Revit.ApplicationServices.Application Application = InCommandData.Application.Application;

            if (string.Compare(Application.VersionNumber, "2018", StringComparison.Ordinal) == 0 && string.Compare(Application.SubVersionNumber, "2018.3", StringComparison.Ordinal) < 0)
            {
                string Message = string.Format("The running Revit is not supported.\nYou must use Revit 2018.3 or further updates to export.");
                MessageBox.Show(Message, DIALOG_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(Result.Cancelled);
            }

            if (!CustomExporter.IsRenderingSupported())
            {
                string Message = "3D view rendering is not supported in the running Revit.";
                MessageBox.Show(Message, DIALOG_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(Result.Cancelled);
            }

            UIDocument UIDoc = InCommandData.Application.ActiveUIDocument;

            if (UIDoc == null)
            {
                string Message = "You must be in a document to export.";
                MessageBox.Show(Message, DIALOG_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(Result.Cancelled);
            }

            return(OnExecute(InCommandData, ref OutCommandMessage, OutElements));
        }
示例#2
0
        bool IExportControl.Run()
        {
            var filePath = txtTargetPath.Text;

            if (string.IsNullOrEmpty(filePath))
            {
                ShowMessageBox(Strings.MessageSelectOutputPathFirst);
                return(false);
            }

#if !R2014
            if (CustomExporter.IsRenderingSupported() == false &&
                ShowConfirmBox(Strings.ExportWillFailBecauseMaterialLib) == false)
            {
                return(false);
            }
#endif

            if (File.Exists(filePath) &&
                ShowConfirmBox(Strings.OutputFileExistedWarning) == false)
            {
                return(false);
            }

            var homePath = InnerApp.GetHomePath();
            if (InnerApp.CheckHomeFolder(homePath) == false &&
                ShowConfirmBox(Strings.HomeFolderIsInvalid) == false)
            {
                return(false);
            }

            var visualStyle = cbVisualStyle.SelectedItem as VisualStyleInfo;
            if (visualStyle != null)
            {
                foreach (var p in visualStyle.Features)
                {
                    _Features.FirstOrDefault(x => x.Type == p.Key)?.ChangeSelected(_Features, p.Value);
                }
            }

            var levelOfDetail = (cbLevelOfDetail.SelectedItem as ComboItemInfo) ?? _LevelOfDetailDefault;


            #region 更新界面选项到 _Features

            void SetFeature(FeatureType featureType, bool selected)
            {
                _Features.FirstOrDefault(x => x.Type == featureType)?.ChangeSelected(_Features, selected);
            }

            SetFeature(FeatureType.Export2DViewAll, rb2DViewsAll.Checked);
            SetFeature(FeatureType.Export2DViewOnlySheet, rb2DViewsOnlySheet.Checked);

            SetFeature(FeatureType.GenerateThumbnail, cbGenerateThumbnail.Checked);
            //SetFeature(FeatureType.GenerateElementData, cbGeneratePropDbJson.Checked);
            SetFeature(FeatureType.GenerateModelsDb, cbGeneratePropDbSqlite.Checked);
            SetFeature(FeatureType.GenerateLeaflet, cbGenerateLeaflet.Checked);
            SetFeature(FeatureType.GenerateDwgDrawing, cbGenerateDwg.Checked);

            SetFeature(FeatureType.ExportGrids, cbIncludeGrids.Checked);
            SetFeature(FeatureType.ExportRooms, cbIncludeRooms.Checked);

            SetFeature(FeatureType.ExcludeProperties, cbExcludeElementProperties.Checked);
            SetFeature(FeatureType.ExcludeLines, cbExcludeLines.Checked);
            SetFeature(FeatureType.ExcludePoints, cbExcludeModelPoints.Checked);
            SetFeature(FeatureType.OnlySelected, cbExcludeUnselectedElements.Checked);

            SetFeature(FeatureType.ConsolidateGroup, cbConsolidateArrayGroup.Checked);
            SetFeature(FeatureType.ConsolidateAssembly, cbConsolidateAssembly.Checked);

            SetFeature(FeatureType.UseLevelCategory, rbGroupByLevelDefault.Checked);
            SetFeature(FeatureType.UseNwLevelCategory, rbGroupByLevelNavisworks.Checked);
            SetFeature(FeatureType.UseBoundLevelCategory, rbGroupByLevelBoundingBox.Checked);

            SetFeature(FeatureType.UseCurrentViewport, cbUseCurrentViewport.Checked);

            #endregion

            var isCanncelled = false;
            using (var session = LicenseConfig.Create())
            {
                if (session.IsValid == false)
                {
                    LicenseConfig.ShowDialog(session, ParentForm);
                    return(false);
                }

                #region 保存设置

                var config = _LocalConfig;
                config.Features       = _Features.Where(x => x.Selected).Select(x => x.Type).ToList();
                config.LastTargetPath = txtTargetPath.Text;
                config.VisualStyle    = visualStyle?.Key;
                config.LevelOfDetail  = levelOfDetail?.Value ?? -1;
                _Config.Save();

                #endregion

                var sw = Stopwatch.StartNew();
                try
                {
                    var setting = new ExportSetting();
                    setting.LevelOfDetail      = config.LevelOfDetail;
                    setting.ExportType         = ExportType.Zip;
                    setting.OutputPath         = config.LastTargetPath;
                    setting.Features           = _Features.Where(x => x.Selected && x.Enabled).Select(x => x.Type).ToList();
                    setting.SelectedElementIds = _ElementIds?.Where(x => x.Value).Select(x => x.Key).ToList();
                    setting.Selected2DViewIds  = rb2DViewCustom.Checked ? _ViewIds : null;
                    setting.Oem = LicenseConfig.GetOemInfo(homePath);

                    var hasSuccess = false;
                    using (var progress = new ProgressExHelper(this.ParentForm, Strings.MessageExporting))
                    {
                        var cancellationToken = progress.GetCancellationToken();

#if !DEBUG
                        //在有些 Revit 会遇到时不时无法转换的问题,循环多次重试, 应该可以成功
                        for (var i = 0; i < 5; i++)
                        {
                            try
                            {
                                StartExport(_UIDocument, _View, setting, progress.GetProgressCallback(), cancellationToken);
                                hasSuccess = true;
                                break;
                            }
                            catch (Autodesk.Revit.Exceptions.ExternalApplicationException)
                            {
                                Application.DoEvents();
                            }
                            catch (IOException ex)
                            {
                                ShowMessageBox("文件保存失败: " + ex.Message);
                                hasSuccess = true;
                                break;
                            }
                        }
#endif

                        //如果之前多次重试仍然没有成功, 这里再试一次,如果再失败就会给出稍后重试的提示
                        if (hasSuccess == false)
                        {
                            StartExport(_UIDocument, _View, setting, progress.GetProgressCallback(), cancellationToken);
                        }

                        isCanncelled = cancellationToken.IsCancellationRequested;
                    }

                    sw.Stop();
                    var ts = sw.Elapsed;
                    ExportDuration = new TimeSpan(ts.Days, ts.Hours, ts.Minutes, ts.Seconds); //去掉毫秒部分

                    Debug.WriteLine(Strings.MessageOperationSuccessAndElapsedTime, ExportDuration);

                    if (isCanncelled == false)
                    {
                        {
                            ShowMessageBox(string.Format(Strings.MessageExportSuccess, ExportDuration));
                        }
                    }
                }
                catch (IOException ex)
                {
                    sw.Stop();
                    Debug.WriteLine(Strings.MessageOperationFailureAndElapsedTime, sw.Elapsed);

                    ShowMessageBox(string.Format(Strings.MessageFileSaveFailure, ex.Message));
                }
                catch (Autodesk.Revit.Exceptions.ExternalApplicationException)
                {
                    sw.Stop();
                    Debug.WriteLine(Strings.MessageOperationFailureAndElapsedTime, sw.Elapsed);

                    ShowMessageBox(Strings.MessageOperationFailureAndTryLater);
                }
                catch (Exception ex)
                {
                    sw.Stop();
                    Debug.WriteLine(Strings.MessageOperationFailureAndElapsedTime, sw.Elapsed);

                    ShowMessageBox(ex.ToString());
                }
            }

            return(isCanncelled == false);
        }
示例#3
0
        bool IExportControl.Run()
        {
            var siteInfo = GetSiteInfo();

            if (siteInfo == null)
            {
                ShowMessageBox(Strings.SiteLocationInvalid);
                return(false);
            }

            var filePath = txtTargetPath.Text;

            if (string.IsNullOrEmpty(filePath))
            {
                ShowMessageBox(Strings.MessageSelectOutputPathFirst);
                return(false);
            }

#if !R2014
            if (CustomExporter.IsRenderingSupported() == false &&
                ShowConfirmBox(Strings.ExportWillFailBecauseMaterialLib) == false)
            {
                return(false);
            }
#endif

            if (File.Exists(filePath) &&
                ShowConfirmBox(Strings.OutputFileExistedWarning) == false)
            {
                return(false);
            }

            var homePath = InnerApp.GetHomePath();
            if (InnerApp.CheckHomeFolder(homePath) == false &&
                ShowConfirmBox(Strings.HomeFolderIsInvalid) == false)
            {
                return(false);
            }

            var visualStyle = cbVisualStyle.SelectedItem as VisualStyleInfo;
            if (visualStyle != null)
            {
                foreach (var p in visualStyle.Features)
                {
                    _Features.FirstOrDefault(x => x.Type == p.Key)?.ChangeSelected(_Features, p.Value);
                }
            }

            var levelOfDetail = (cbLevelOfDetail.SelectedItem as ComboItemInfo) ?? _LevelOfDetailDefault;

            #region 更新界面选项到 _Features

            void SetFeature(FeatureType featureType, bool selected)
            {
                _Features.FirstOrDefault(x => x.Type == featureType)?.ChangeSelected(_Features, selected);
            }

            //SetFeature(FeatureType.ExportGrids, cbIncludeGrids.Checked);

            SetFeature(FeatureType.ExcludeLines, cbExcludeLines.Checked);
            SetFeature(FeatureType.ExcludePoints, cbExcludeModelPoints.Checked);
            SetFeature(FeatureType.OnlySelected, cbExcludeUnselectedElements.Checked);

            SetFeature(FeatureType.UseGoogleDraco, cbUseDraco.Checked);
            //SetFeature(FeatureType.ExtractShell, cbUseExtractShell.Checked);
            SetFeature(FeatureType.GenerateModelsDb, cbGeneratePropDbSqlite.Checked);
            SetFeature(FeatureType.ExportSvfzip, cbExportSvfzip.Checked);
            SetFeature(FeatureType.EnableQuantizedAttributes, cbEnableQuantizedAttributes.Checked);
            SetFeature(FeatureType.EnableTextureWebP, cbEnableTextureWebP.Checked);
            SetFeature(FeatureType.GenerateThumbnail, cbGenerateThumbnail.Checked);
            SetFeature(FeatureType.EnableUnlitMaterials, cbEnableUnlitMaterials.Checked);

            SetFeature(FeatureType.EnableEmbedGeoreferencing, cbEmbedGeoreferencing.Checked);

            #endregion

            var isCancelled = false;
            using (var session = LicenseConfig.Create())
            {
                if (session.IsValid == false)
                {
                    LicenseConfig.ShowDialog(session, ParentForm);
                    return(false);
                }

                #region 保存设置

                var config = _LocalConfig;
                config.Features       = _Features.Where(x => x.Selected).Select(x => x.Type).ToList();
                config.LastTargetPath = txtTargetPath.Text;
                config.VisualStyle    = visualStyle?.Key;
                config.LevelOfDetail  = levelOfDetail?.Value ?? -1;

                if (rbModeShellMesh.Checked)
                {
                    config.Mode = 2;
                }
                else if (rbModeShellElement.Checked)
                {
                    config.Mode = 3;
                }
                else
                {
                    config.Mode = 0;
                }

                _Config.Save();

                #endregion

                var sw = Stopwatch.StartNew();
                try
                {
                    var setting = new ExportSetting();
                    setting.LevelOfDetail      = config.LevelOfDetail;
                    setting.OutputPath         = config.LastTargetPath;
                    setting.Mode               = config.Mode;
                    setting.Features           = _Features.Where(x => x.Selected && x.Enabled).Select(x => x.Type).ToList();
                    setting.SelectedElementIds = _ElementIds?.Where(x => x.Value).Select(x => x.Key).ToList();
                    setting.Site               = siteInfo;
                    setting.Oem = LicenseConfig.GetOemInfo(homePath);
                    setting.PreExportSeedFeatures = InnerApp.GetPreExportSeedFeatures(@"3DTiles");

                    var hasSuccess = false;
                    using (var progress = new ProgressExHelper(this.ParentForm, Strings.MessageExporting))
                    {
                        var cancellationToken = progress.GetCancellationToken();

#if !DEBUG
                        //在有些 Revit 会遇到时不时无法转换的问题,循环多次重试, 应该可以成功
                        for (var i = 0; i < 5; i++)
                        {
                            try
                            {
                                StartExport(_UIDocument, _View, setting, progress.GetProgressCallback(), cancellationToken);
                                hasSuccess = true;
                                break;
                            }
                            catch (Autodesk.Revit.Exceptions.ExternalApplicationException)
                            {
                                Application.DoEvents();
                            }
                            catch (IOException ex)
                            {
                                ShowMessageBox("文件保存失败: " + ex.Message);
                                hasSuccess = true;
                                break;
                            }
                        }
#endif

                        //如果之前多次重试仍然没有成功, 这里再试一次,如果再失败就会给出稍后重试的提示
                        if (hasSuccess == false)
                        {
                            StartExport(_UIDocument, _View, setting, progress.GetProgressCallback(), cancellationToken);
                        }

                        isCancelled = cancellationToken.IsCancellationRequested;
                    }

                    sw.Stop();
                    var ts = sw.Elapsed;
                    ExportDuration = new TimeSpan(ts.Days, ts.Hours, ts.Minutes, ts.Seconds); //去掉毫秒部分

                    Debug.WriteLine(Strings.MessageOperationSuccessAndElapsedTime, ExportDuration);

                    if (isCancelled == false)
                    {
                        ShowMessageBox(string.Format(Strings.MessageExportSuccess, ExportDuration));
                    }
                }
                catch (IOException ex)
                {
                    sw.Stop();
                    Debug.WriteLine(Strings.MessageOperationFailureAndElapsedTime, sw.Elapsed);

                    ShowMessageBox(string.Format(Strings.MessageFileSaveFailure, ex.Message));
                }
                catch (Autodesk.Revit.Exceptions.ExternalApplicationException)
                {
                    sw.Stop();
                    Debug.WriteLine(Strings.MessageOperationFailureAndElapsedTime, sw.Elapsed);

                    ShowMessageBox(Strings.MessageOperationFailureAndTryLater);
                }
                catch (Exception ex)
                {
                    sw.Stop();
                    Debug.WriteLine(Strings.MessageOperationFailureAndElapsedTime, sw.Elapsed);

                    ShowMessageBox(ex.ToString());
                }
            }

            return(isCancelled == false);
        }
示例#4
0
        // Implement the interface to execute the command.
        public Result Execute(
            ExternalCommandData InCommandData,                 // contains reference to Application and View
            ref string OutCommandMessage,                      // error message to display in the failure dialog when the command returns "Failed"
            ElementSet OutElements                             // set of problem elements to display in the failure dialog when the command returns "Failed"
            )
        {
            Autodesk.Revit.ApplicationServices.Application Application = InCommandData.Application.Application;

            if (string.Compare(Application.VersionNumber, "2018", StringComparison.Ordinal) == 0 && string.Compare(Application.SubVersionNumber, "2018.3", StringComparison.Ordinal) < 0)
            {
                string Message = string.Format("The running Revit is not supported.\nYou must use Revit 2018.3 or further updates to export.");
                MessageBox.Show(Message, DIALOG_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(Result.Cancelled);
            }

            if (!CustomExporter.IsRenderingSupported())
            {
                string Message = "3D view rendering is not supported in the running Revit.";
                MessageBox.Show(Message, DIALOG_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(Result.Cancelled);
            }

            UIDocument UIDoc = InCommandData.Application.ActiveUIDocument;

            if (UIDoc == null)
            {
                string Message = "You must be in a document to export.";
                MessageBox.Show(Message, DIALOG_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(Result.Cancelled);
            }

            Document Doc = UIDoc.Document;

            string DocumentPath = Doc.PathName;

            if (string.IsNullOrWhiteSpace(DocumentPath))
            {
                string message = "Your document must be saved on disk before exporting.";
                MessageBox.Show(message, DIALOG_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(Result.Cancelled);
            }

            bool ExportActiveViewOnly = true;

            // Retrieve the Unreal Datasmith export options.
            DatasmithRevitExportOptions ExportOptions = new DatasmithRevitExportOptions(Doc);

            if ((System.Windows.Forms.Control.ModifierKeys & Keys.Control) == Keys.Control)
            {
                if (ExportOptions.ShowDialog() != DialogResult.OK)
                {
                    return(Result.Cancelled);
                }
                ExportActiveViewOnly = false;
            }

            // Generate file path for each view.
            Dictionary <ElementId, string> FilePaths = new Dictionary <ElementId, string>();
            List <View3D> ViewsToExport = new List <View3D>();

            if (ExportActiveViewOnly)
            {
                View3D ActiveView = Doc.ActiveView as View3D;

                if (ActiveView == null)
                {
                    string Message = "You must be in a 3D view to export.";
                    MessageBox.Show(Message, DIALOG_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return(Result.Cancelled);
                }

                if (ActiveView.IsTemplate || !ActiveView.CanBePrinted)
                {
                    string Message = "The active 3D view cannot be exported.";
                    MessageBox.Show(Message, DIALOG_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return(Result.Cancelled);
                }

                string ViewFamilyName = ActiveView.get_Parameter(BuiltInParameter.ELEM_FAMILY_PARAM).AsValueString().Replace(" ", "");
                string FileName       = Regex.Replace($"{Path.GetFileNameWithoutExtension(DocumentPath)}-{ViewFamilyName}-{ActiveView.Name}.udatasmith", @"\s+", "_");

                SaveFileDialog Dialog = new SaveFileDialog();

                Dialog.Title            = DIALOG_CAPTION;
                Dialog.InitialDirectory = Path.GetDirectoryName(DocumentPath);
                Dialog.FileName         = FileName;
                Dialog.DefaultExt       = "udatasmith";
                Dialog.Filter           = "Unreal Datasmith|*.udatasmith";
                Dialog.CheckFileExists  = false;
                Dialog.CheckPathExists  = true;
                Dialog.AddExtension     = true;
                Dialog.OverwritePrompt  = true;

                if (Dialog.ShowDialog() != DialogResult.OK)
                {
                    return(Result.Cancelled);
                }

                string FilePath = Dialog.FileName;

                if (string.IsNullOrWhiteSpace(FilePath))
                {
                    string message = "The given Unreal Datasmith file name is blank.";
                    MessageBox.Show(message, DIALOG_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return(Result.Cancelled);
                }

                FilePaths.Add(ActiveView.Id, FilePath);
                ViewsToExport.Add(ActiveView);
            }
            else
            {
                string SavePath;
                using (var FBD = new FolderBrowserDialog())
                {
                    FBD.ShowNewFolderButton = true;
                    DialogResult result = FBD.ShowDialog();

                    if (result != DialogResult.OK || string.IsNullOrWhiteSpace(FBD.SelectedPath))
                    {
                        return(Result.Cancelled);
                    }

                    SavePath = FBD.SelectedPath;
                }

                foreach (var View in ExportOptions.Selected3DViews)
                {
                    string ViewFamilyName = View.get_Parameter(BuiltInParameter.ELEM_FAMILY_PARAM).AsValueString().Replace(" ", "");
                    string FileName       = Regex.Replace($"{Path.GetFileNameWithoutExtension(DocumentPath)}-{ViewFamilyName}-{View.Name}.udatasmith", @"\s+", "_");
                    FilePaths.Add(View.Id, Path.Combine(SavePath, FileName));
                    ViewsToExport.Add(View);
                }
            }

            // Prevent user interaction with the active 3D view to avoid the termination of the custom export,
            // without Revit providing any kind of internal or external feedback.
            EnableViewWindow(InCommandData.Application, false);

            // Create a custom export context for command Export to Unreal Datasmith.
            FDatasmithRevitExportContext ExportContext = new FDatasmithRevitExportContext(InCommandData.Application.Application, Doc, FilePaths, ExportOptions);

            // Export the active 3D View to the given Unreal Datasmith file.
            using (CustomExporter Exporter = new CustomExporter(Doc, ExportContext))
            {
                // Add a progress bar callback.
                // application.ProgressChanged += exportContext.HandleProgressChanged;

                try
                {
                    // The export process will exclude output of geometric objects such as faces and curves,
                    // but the context needs to receive the calls related to Faces or Curves to gather data.
                    // The context always receive their tessellated geometry in form of polymeshes or lines.
                    Exporter.IncludeGeometricObjects = true;

                    // The export process should stop in case an error occurs during any of the exporting methods.
                    Exporter.ShouldStopOnError = true;

                    // Initiate the export process for all 3D views.
                    foreach (var view in ViewsToExport)
                    {
#if REVIT_API_2020
                        Exporter.Export(view as Autodesk.Revit.DB.View);
#else
                        Exporter.Export(view);
#endif
                    }
                }
                catch (System.Exception exception)
                {
                    OutCommandMessage = string.Format("Cannot export the 3D view:\n\n{0}\n\n{1}", exception.Message, exception.StackTrace);
                    MessageBox.Show(OutCommandMessage, DIALOG_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(Result.Failed);
                }
                finally
                {
                    // Remove the progress bar callback.
                    // application.ProgressChanged -= exportContext.HandleProgressChanged;

                    // Restore user interaction with the active 3D view.
                    EnableViewWindow(InCommandData.Application, true);

                    if (ExportContext.GetMessages().Count > 0)
                    {
                        string Messages = string.Join($"{System.Environment.NewLine}", ExportContext.GetMessages());
                        DatasmithRevitApplication.ShowExportMessages(Messages);
                    }
                }
            }

            return(Result.Succeeded);
        }
        public void Export()
        {
#if !R2014
            if (CustomExporter.IsRenderingSupported() == false)
            {
                var message = @"检测到当前 Revit 实例对数据导出的支持存在问题, 原因可能是材质库未正确安装。 本次操作可能无法成功执行, 确定要继续吗?";
                if (MessageBox.Show(this, message, Text,
                                    MessageBoxButtons.OKCancel,
                                    MessageBoxIcon.Question,
                                    MessageBoxDefaultButton.Button2) != DialogResult.OK)
                {
                    return;
                }
            }
#endif
            var visualStyle = cbVisualStyle.SelectedItem as VisualStyleInfo;

            if (visualStyle != null)
            {
                foreach (var p in visualStyle.Features)
                {
                    _Features.FirstOrDefault(x => x.Type == p.Key)?.ChangeSelected(_Features, p.Value);
                }
            }

            var levelOfDetail = (cbLevelOfDetail.SelectedItem as ComboItemInfo) ?? _LevelOfDetailDefault;

            #region 更新界面选项到 _Features

            void SetFeature(FeatureType featureType, bool selected)
            {
                _Features.FirstOrDefault(x => x.Type == featureType)?.ChangeSelected(_Features, selected);
            }

            SetFeature(FeatureType.Export2DViewAll, rb2DViewsAll.Checked);
            SetFeature(FeatureType.Export2DViewOnlySheet, rb2DViewsOnlySheet.Checked);

            SetFeature(FeatureType.GenerateThumbnail, cbGenerateThumbnail.Checked);
            SetFeature(FeatureType.GenerateElementData, cbGeneratePropDbJson.Checked);
            SetFeature(FeatureType.GenerateModelsDb, cbGeneratePropDbSqlite.Checked);

            SetFeature(FeatureType.ExportGrids, cbIncludeGrids.Checked);
            SetFeature(FeatureType.ExportRooms, cbIncludeRooms.Checked);

            SetFeature(FeatureType.ExcludeProperties, cbExcludeElementProperties.Checked);
            SetFeature(FeatureType.ExcludeLines, cbExcludeLines.Checked);
            SetFeature(FeatureType.ExcludePoints, cbExcludeModelPoints.Checked);
            SetFeature(FeatureType.OnlySelected, cbExcludeUnselectedElements.Checked);

            SetFeature(FeatureType.ConsolidateGroup, cbConsolidateArrayGroup.Checked);
            SetFeature(FeatureType.ConsolidateAssembly, cbConsolidateAssembly.Checked);

            SetFeature(FeatureType.UseLevelCategory, rbGroupByLevelDefault.Checked);
            SetFeature(FeatureType.UseNwLevelCategory, rbGroupByLevelNavisworks.Checked);
            SetFeature(FeatureType.UseBoundLevelCategory, rbGroupByLevelBoundingBox.Checked);

            SetFeature(FeatureType.UseCurrentViewport, cbUseCurrentViewport.Checked);

            #endregion

            var isCanncelled = false;

            using (var session = App.CreateSession(Application.licenseKey))
            {
                if (session.IsValid == false)
                {
                    new Plugin_manage().ShowDialog();

                    return;
                }

                #region 保存设置

                var config = _Config.Local;
                config.Features       = _Features.Where(x => x.Selected).Select(x => x.Type).ToList();
                config.LastTargetPath = Path.Combine(TempPath, modelName + ".svfzip");
                config.VisualStyle    = visualStyle?.Key;
                config.LevelOfDetail  = levelOfDetail?.Value ?? -1;
                _Config.Save();

                #endregion

                var features = _Features.Where(x => x.Selected && x.Enabled).ToDictionary(x => x.Type, x => true);

                using (var progress = new ProgressHelper(this, Strings.MessageExporting))
                {
                    var cancellationToken = progress.GetCancellationToken();
                    StartExport(_UIDocument, _View, config, ExportType.Zip, null, features, false, progress.GetProgressCallback(), cancellationToken);
                    isCanncelled = cancellationToken.IsCancellationRequested;
                }

                if (isCanncelled == false)
                {
                    var t = new Thread(UploadFile);
                    t.IsBackground = false;
                    t.Start();

                    Enabled = false;

                    progressBar1.Value = 50;
                }
            }
        }
        public static void Export3DViewsToDatasmith(Document InDocument, string InOutputPath, List <int> InViewIds, int InTesselation = 8)
        {
            if (InDocument == null)
            {
                Console.WriteLine("Invalid document.");
                return;
            }

            Autodesk.Revit.ApplicationServices.Application App = InDocument.Application;

            if (string.Compare(App.VersionNumber, "2018", StringComparison.Ordinal) == 0 && string.Compare(App.SubVersionNumber, "2018.3", StringComparison.Ordinal) < 0)
            {
                string Message = string.Format("The running Revit is not supported.\nYou must use Revit 2018.3 or further updates to export.");
                Console.WriteLine(Message);
                return;
            }

            try
            {
                // Validate the provided path
                InOutputPath = Path.GetFullPath(InOutputPath);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return;
            }

            if (!CustomExporter.IsRenderingSupported())
            {
                string Message = "3D view rendering is not supported in the running Revit.";
                Console.WriteLine(Message);
                return;
            }

            string DocumentPath = InDocument.PathName;

            Dictionary <ElementId, string> FilePaths = new Dictionary <ElementId, string>();
            List <View3D> ExportViews = new List <View3D>();

            foreach (var Id in InViewIds)
            {
                View3D View = InDocument.GetElement(new ElementId(Id)) as View3D;
                if (View != null && !View.IsTemplate && View.CanBePrinted)
                {
                    ExportViews.Add(View);
                    // Generate file path for each view.
                    string FileName = Regex.Replace($"{View.Name}.udatasmith", @"\s+", "_");
                    FilePaths.Add(View.Id, Path.Combine(InOutputPath, FileName));
                }
            }

            // Retrieve the Unreal Datasmith export options.
            DatasmithRevitExportOptions ExportOptions = new DatasmithRevitExportOptions(InDocument);

            // Create a custom export context for command Export to Unreal Datasmith.
            FDatasmithRevitExportContext ExportContext = new FDatasmithRevitExportContext(
                App,
                InDocument,
                FilePaths,
                ExportOptions,
                null);

            // Clamp tesselation parameter to a valid range.
            ExportContext.LevelOfTessellation = Math.Min(Math.Max(InTesselation, -1), 15);

            using (CustomExporter Exporter = new CustomExporter(InDocument, ExportContext))
            {
                try
                {
                    // The export process will exclude output of geometric objects such as faces and curves,
                    // but the context needs to receive the calls related to Faces or Curves to gather data.
                    // The context always receive their tessellated geometry in form of polymeshes or lines.
                    Exporter.IncludeGeometricObjects = true;

                    // The export process should stop in case an error occurs during any of the exporting methods.
                    Exporter.ShouldStopOnError = true;

                    // Initiate the export process for all 3D views.
                    foreach (var View in ExportViews)
                    {
#if REVIT_API_2020
                        Exporter.Export(View as Autodesk.Revit.DB.View);
#else
                        Exporter.Export(View);
#endif
                    }
                }
                catch (System.Exception InException)
                {
                    string Message = string.Format("Cannot export the 3D view:\n\n{0}\n\n{1}", InException.Message, InException.StackTrace);
                    Console.WriteLine(Message);
                    return;
                }
            }
        }