Esempio n. 1
0
 public OptionsViewModel(Manager exportManager, SCexportViewModel exportManagerViewModel)
 {
     this.exportManager          = exportManager;
     this.exportManagerViewModel = exportManagerViewModel;
     fileNamingSchemes           = new BindableCollection <string>();
     foreach (var s in exportManager.FileNameTypes)
     {
         FileNamingSchemes.Add(s.Name);
     }
     selectedFileNamingScheme = exportManager.FileNameScheme.Name;
 }
Esempio n. 2
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            if (commandData == null)
            {
                return(Result.Failed);
            }

            if (!System.IO.Directory.Exists(Constants.DefaultExportDirectory))
            {
                System.IO.Directory.CreateDirectory(Constants.DefaultExportDirectory);
            }

            if (string.IsNullOrEmpty(FileUtilities.GetCentralFileName(commandData.Application.ActiveUIDocument.Document)))
            {
                WindowManager.ShowMessageBox("FAIL", "Please save the file before continuing");
                return(Result.Failed);
            }

            var uidoc = commandData.Application.ActiveUIDocument;

            if (uidoc == null)
            {
                return(Result.Failed);
            }

            var views = new List <ViewSheet>();

            if (uidoc.Document.ActiveView.ViewType == ViewType.ProjectBrowser)
            {
                var s = uidoc.Selection.GetElementIds();
                foreach (var id in s)
                {
                    var projectBrowserView = uidoc.Document.GetElement(id);
                    if (projectBrowserView is View)
                    {
                        var v = (View)projectBrowserView;
                        if (v.ViewType == ViewType.ProjectBrowser)
                        {
                            continue;
                        }
                        if (v is ViewSheet)
                        {
                            views.Add((ViewSheet)v);
                            continue;
                        }
                    }
                }
            }

            // Deselect all elements before continuing so they don't appear incorrectly
            uidoc.Selection.SetElementIds(new List <ElementId>());

            var manager = new Manager(uidoc);
            var log     = new ExportLog();

            if (views == null)
            {
                views = new List <ViewSheet>();
            }
            var vm = new ViewModels.SCexportViewModel(manager, views);
            var wm = WindowManager;

            wm.ShowDialog(vm, null, ViewModels.SCexportViewModel.DefaultWindowSettings);

            if (vm.CloseStatus != ViewModels.SCexportViewModel.CloseMode.Exit)
            {
                string exportType = string.Empty;

                switch (vm.CloseStatus)
                {
                case ViewModels.SCexportViewModel.CloseMode.Export:
                    exportType = "Exporting";
                    break;

                case ViewModels.SCexportViewModel.CloseMode.Print:
                case ViewModels.SCexportViewModel.CloseMode.PrintA3:
                case ViewModels.SCexportViewModel.CloseMode.PrintA2:
                    exportType = "Printing";
                    break;
                }

                var progressVm = new ViewModels.ProgressMonitorViewModel
                {
                    MaximumValue = vm.SelectedSheets.Count,
                    Value        = 0
                };

                log.Clear();
                log.Start(exportType + " Started.");

                WindowManager.ShowWindow(progressVm, null, ViewModels.ProgressMonitorViewModel.DefaultWindowSettings);

                if (manager.SaveHistory)
                {
                    RecentExport.Save(manager, vm.SelectedSheets);
                }

                foreach (var sheet in vm.SelectedSheets)
                {
                    progressVm.ProgressSummary += @" --> " + exportType + @" " + sheet.FullExportName + "...";

                    switch (vm.CloseStatus)
                    {
                    case ViewModels.SCexportViewModel.CloseMode.Export:
                        manager.ExportSheet(sheet, log);
                        break;

                    case ViewModels.SCexportViewModel.CloseMode.Print:
                        manager.Print(sheet, manager.PrinterNameLargeFormat, 1, log);
                        break;

                    case ViewModels.SCexportViewModel.CloseMode.PrintA3:
                        manager.Print(sheet, manager.PrinterNameA3, 3, log);
                        break;

                    case ViewModels.SCexportViewModel.CloseMode.PrintA2:
                        manager.Print(sheet, manager.PrinterNameLargeFormat, 2, log);
                        break;

                    default:
                        return(Result.Succeeded);
                    }

                    progressVm.Value++;
                    string niceTime = string.Format(
                        System.Globalization.CultureInfo.CurrentCulture,
                        "OK  [ time {0:hh\\.mm\\:ss}  total {1:hh\\.mm\\:ss}  ~remaining {2:hh\\.mm\\:ss}]",
                        log.LastItemElapsedTime,
                        log.TimeSinceStart,
                        System.TimeSpan.FromTicks(log.TimeSinceStart.Ticks / progressVm.Value * (progressVm.MaximumValue - progressVm.Value)));
                    progressVm.ProgressSummary += niceTime + System.Environment.NewLine;

                    if (progressVm.CancelPressed)
                    {
                        break;
                    }
                }

                log.Stop("Finished");
                progressVm.Stop(log);
                progressVm.ProcessComplete = true;
            }

            if (manager.ShowExportLog || log.Errors > 0)
            {
                var exportLogViewModel = new ViewModels.ExportLogViewModel(log);
                WindowManager.ShowDialog(exportLogViewModel, null, ViewModels.ExportLogViewModel.DefaultWindowSettings);
            }

            return(Result.Succeeded);
        }