Stream(ArrayList data, ViewSheetSetting viewSheetSetting)
        {
            data.Add(new Snoop.Data.ClassSeparator(typeof(ViewSheetSetting)));

            data.Add(new Snoop.Data.Object("Available views", viewSheetSetting.AvailableViews));
            data.Add(new Snoop.Data.Object("Current view sheet set", viewSheetSetting.CurrentViewSheetSet));
        }
Beispiel #2
0
        public SheetsOSSNewSetRequest(UIApplication uiApp, String text)
        {
            MainUI       uiForm = BARevitTools.Application.thisApp.newMainUi;
            DataGridView dgv    = uiForm.sheetsOSSDataGridView;

            //Get all of the existing sheets sets by the column headers
            List <string> dtColumnsCollection = new List <string>();

            foreach (DataColumn dtColumn in uiForm.sheetsOSSDataTable.Columns)
            {
                dtColumnsCollection.Add(dtColumn.ColumnName);
            }

            //IF the sheet set does not already exist, and the user has specified a new sheet set name, continue
            if (!dtColumnsCollection.Contains(uiForm.sheetsOSSNewSetTextBox.Text) && uiForm.sheetsOSSNewSetTextBox.Text != "<New Set Name>")
            {
                RVTDocument doc = uiApp.ActiveUIDocument.Document;

                //Get the PrintManager
                PrintManager printManager = doc.PrintManager;
                //Set the PrintManager PrintRange to Select
                printManager.PrintRange = PrintRange.Select;
                //Get the PrintManager's ViewSheetSetting
                ViewSheetSetting viewSheetSetting = printManager.ViewSheetSetting;

                //Create a temporary sheet set
                Transaction t0 = new Transaction(doc, "CreateTempSheetSet");
                t0.Start();
                try
                {
                    //Save the ViewSheetSetting with the user defined name so it can be modified later
                    viewSheetSetting.SaveAs(uiForm.sheetsOSSNewSetTextBox.Text);
                    t0.Commit();

                    //Add a new DataColumn to the MainUI's DataTable with the header name of the user defined sheet set
                    DataColumn newColumn = new DataColumn();
                    newColumn.ColumnName = uiForm.sheetsOSSNewSetTextBox.Text;
                    newColumn.DataType   = typeof(Boolean);
                    uiForm.sheetsOSSDataTable.Columns.Add(newColumn);
                }
                catch { t0.RollBack(); }
                dgv.Update();
            }
            else if (dtColumnsCollection.Contains(uiForm.sheetsOSSNewSetTextBox.Text))
            {
                //If a sheet set already exists with the same name as the user defined name, let the user know
                MessageBox.Show("Set with specified name already exists");
            }
            else
            {
                //Let the user know if they specified a name that could not be used
                MessageBox.Show("Cannot make a set with the specified name");
            }

            dgv.Update();
            dgv.Refresh();
            //Evaluate the cells of the DataGridView and set the background color for those that are checked
            GraphicsFormatting.HighlightCellsFromDataGridView(dgv, System.Drawing.Color.GreenYellow);
        }
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Document   doc   = uidoc.Document;

            try
            {
                PrintManager pm = doc.PrintManager;

                Selection selection                     = uidoc.Selection;
                ICollection <ElementId>  ids            = selection.GetElementIds();
                FilteredElementCollector collector      = new FilteredElementCollector(doc, ids);
                ElementClassFilter       wantedElements = new ElementClassFilter(typeof(ViewSheet));
                collector.WherePasses(wantedElements);
                List <Element> printElems = collector.ToElements() as List <Element>;
                ViewSet        viewSet    = new ViewSet();
                foreach (Element e in printElems)
                {
                    ViewSheet viewSheet = e as ViewSheet;
                    viewSet.Insert(viewSheet);
                }


                pm.SelectNewPrintDriver("Microsoft Print to PDF");
                pm.PrintRange = PrintRange.Select;


                ViewSheetSetting vss = pm.ViewSheetSetting;

                vss.CurrentViewSheetSet.Views = viewSet;

                using (Transaction trans = new Transaction(doc, "Print ViewSet"))
                {
                    trans.Start();
                    string setName = "Temp";
                    vss.SaveAs(setName);
                    pm.PrintSetup.CurrentPrintSetting.PrintParameters.PageOrientation = PageOrientationType.Landscape;
                    pm.PrintSetup.CurrentPrintSetting.PrintParameters.PaperPlacement  = PaperPlacementType.Center;
                    pm.PrintSetup.CurrentPrintSetting.PrintParameters.ZoomType        = ZoomType.Zoom;
                    pm.PrintSetup.CurrentPrintSetting.PrintParameters.Zoom            = 100;

                    // pm.Apply();
                    //pm.PrintSetup.Save();

                    pm.CombinedFile = true;
                    pm.SubmitPrint();
                    //vss.Delete();
                    trans.Commit();
                }
                return(Result.Succeeded);
            }
            catch (Exception e)
            {
                message = e.Message;
                return(Result.Failed);
            }
        }
Beispiel #4
0
        private void PrintViewSheet(ViewSheet viewSheet, string sheetSize, PrintSetting printSetting, string filePath)
        {
            // creates view set
            ViewSet viewSet = new ViewSet();
            viewSet.Insert(viewSheet);
            PrintManager printManager = this.Doc.PrintManager;
            printManager.PrintRange = PrintRange.Select;
            printManager.Apply();

            // make new view set current
            ViewSheetSetting viewSheetSetting = printManager.ViewSheetSetting;
            viewSheetSetting.CurrentViewSheetSet.Views = viewSet;

            // set printer
            printManager.SelectNewPrintDriver(this._PrinterName);
            printManager.Apply();

            // set file path
            printManager.CombinedFile = true;
            printManager.PrintToFileName = filePath;
            printManager.Apply();

            // set print setting
            this.Transaction.Start();
            PrintSetup printSetup = printManager.PrintSetup;
            printSetup.CurrentPrintSetting = printSetting;
            printManager.Apply();
            this.Transaction.Commit();

            List<Element> viewSets = new List<Element>(new FilteredElementCollector(this.Doc)
                                                       .OfClass(typeof(ViewSheetSet))
                                                       .ToElements());
            foreach (Element element in viewSets)
            {
                if (element.Name == "tempSetName")
                {
                    this.Transaction.Start();
                    this.Doc.Delete(element.Id);
                    this.Transaction.Commit();
                }
            }

            // save settings and submit print
            this.Transaction.Start();
            viewSheetSetting.SaveAs("tempSetName");
            printManager.Apply();
            printManager.SubmitPrint();
            viewSheetSetting.Delete();
            this.Transaction.Commit();
        }
Beispiel #5
0
 public ViewSheets(Document doc)
 {
     m_doc = doc;
     m_viewSheetSetting = doc.PrintManager.ViewSheetSetting;
 }
Beispiel #6
0
        public SheetsOSSRequest(UIApplication uiApp, String text)
        {
            MainUI       uiForm = BARevitTools.Application.thisApp.newMainUi;
            RVTDocument  doc    = uiApp.ActiveUIDocument.Document;
            DataGridView dgv    = uiForm.sheetsOSSDataGridView;

            //Collect the view sheets and view sheet sets
            var viewSheets    = new FilteredElementCollector(doc).OfClass(typeof(ViewSheet)).ToElements();
            var viewSheetSets = new FilteredElementCollector(doc).OfClass(typeof(ViewSheetSet)).ToElements();
            Dictionary <string, Autodesk.Revit.DB.ViewSheet> viewSheetDict = new Dictionary <string, Autodesk.Revit.DB.ViewSheet>();
            Dictionary <string, ViewSheetSet> viewSheetSetDict             = new Dictionary <string, ViewSheetSet>();
            List <int>    viewSheetIds      = new List <int>();
            List <string> viewSheetSetNames = new List <string>();

            //Add the sheets to the dictionary and list
            foreach (ViewSheet viewSheet in viewSheets)
            {
                if (!viewSheet.IsPlaceholder)
                {
                    try
                    {
                        viewSheetDict.Add(viewSheet.Name, viewSheet);
                        viewSheetIds.Add(viewSheet.Id.IntegerValue);
                    }
                    catch { MessageBox.Show(viewSheet.IsPlaceholder.ToString()); }
                }
            }

            //Add the view sheet sets to the dictionary and list
            foreach (ViewSheetSet viewSheetSet in viewSheetSets)
            {
                viewSheetSetDict.Add(viewSheetSet.Name, viewSheetSet);
                viewSheetSetNames.Add(viewSheetSet.Name);
            }

            //Get the PrintManager and set its PrintRange to Select, then assign it the VeiwSheetSetting
            PrintManager printManager = doc.PrintManager;

            printManager.PrintRange = PrintRange.Select;
            ViewSheetSetting viewSheetSetting = printManager.ViewSheetSetting;

            //Start a transaction
            Transaction t1 = new Transaction(doc, "UpdateViewSheetSets");

            t1.Start();
            foreach (DataGridViewColumn column in dgv.Columns)
            {
                //Go through the columns, but only grab those that have an index greater than 2, which correspond to the sheet set names
                if (column.Index > 2)
                {
                    //Make a new ViewSet
                    ViewSet newViewSet = new ViewSet();
                    viewSheetSetting.CurrentViewSheetSet.Views = newViewSet;

                    //Foreach row, if the column has a checked checkbox, insert the sheet from the dictionary matching the sheet number into the ViewSet
                    foreach (DataGridViewRow row in dgv.Rows)
                    {
                        if (row.Cells[column.Index].Value.ToString() == "True")
                        {
                            newViewSet.Insert(viewSheetDict[row.Cells[1].Value.ToString()]);
                        }
                    }

                    //If the viewSheetSetNames contains the column name, indicating the SheetSet already exists, delete it, then save a new one with the same name
                    if (viewSheetSetNames.Contains(column.Name))
                    {
                        ElementId vssId = viewSheetSetDict[column.Name].Id;
                        doc.Delete(vssId);
                        viewSheetSetting.SaveAs(column.Name);
                    }
                    else
                    {
                        //If the SheetSet does not already exist, just save it
                        viewSheetSetting.SaveAs(column.Name);
                    }
                }
            }
            t1.Commit();
            //Re-invoke the creation of the MainUI's controls for the OSS tool so the table updates with new data from the previous run
            uiForm.SheetsOSSButton_Click(null, null);
        }
Beispiel #7
0
        private void PrintAsIs(UIDocument UIdoc, Transaction t)
        {
            Document       _doc           = UIdoc.Document;
            List <Element> titleBlockList = new FilteredElementCollector(_doc)
                                            .OfCategory(BuiltInCategory.OST_TitleBlocks).WhereElementIsNotElementType().ToList();

            List <View> sheetList = new FilteredElementCollector(_doc).OfCategory(BuiltInCategory.OST_Sheets).ToList().ConvertAll(q => { return(_doc.GetElement(q.Id) as View); });

            SortedList <string, ViewSet> viewSheetSetsList = new SortedList <string, ViewSet>(); // коллекция ключ (строка) / значение (ViewSet)

            foreach (Element element in titleBlockList)
            {
                Parameter s_number = element.get_Parameter(BuiltInParameter.SHEET_NUMBER);
                View      sheet    = sheetList.Where(v => v.get_Parameter(BuiltInParameter.SHEET_NUMBER).AsString() == s_number.AsString()).First();
                Parameter s_height = element.get_Parameter(BuiltInParameter.SHEET_HEIGHT);
                Parameter s_width  = element.get_Parameter(BuiltInParameter.SHEET_WIDTH);

                string s_complect = "";

                // получаем "комплект" из листа с тем же номером, что у titleBlock
                foreach (Element sh in sheetList)
                {
                    Parameter sheet_number = sh.get_Parameter(BuiltInParameter.SHEET_NUMBER);
                    if (sheet_number.AsString() == s_number.AsString())
                    {
                        s_complect = sh.GetParameters("Раздел проекта")[0].AsString();
                        break;
                    }
                }
                int    d_height = (int)Math.Round(304.799472 * s_height.AsDouble());
                int    d_width  = (int)Math.Round(304.799472 * s_width.AsDouble());
                string s_format = string.Format("Раздел {0}: формат {1}", s_complect, GetSheetFormat(d_height.ToString(), d_width.ToString()));

                if (viewSheetSetsList.Keys.Contains(s_format))
                {
                    ViewSet viewSet = viewSheetSetsList.Values.ElementAt(viewSheetSetsList.Keys.IndexOf(s_format));
                    viewSet.Insert(sheet);
                }
                else
                {
                    ViewSet viewSet = new ViewSet();
                    viewSet.Insert(sheet);
                    viewSheetSetsList.Add(s_format, viewSet);
                }
            }

            using (TransactionGroup tg = new TransactionGroup(_doc))
            {
                tg.Start("Sorting ViewSheets by format");
                using (Transaction tx1 = new Transaction(_doc))
                {
                    tx1.Start("Deleting existing ViewSheet Sets");
                    List <ElementId> allViewSheetSetsIds = new FilteredElementCollector(_doc).OfClass(typeof(ViewSheetSet))
                                                           .ToElementIds().ToList();
                    _doc.Delete(allViewSheetSetsIds);
                    tx1.Commit();
                }
                using (Transaction tx2 = new Transaction(_doc))
                {
                    tx2.Start("Creating new ViewSheet Sets");
                    PrintManager printManager = _doc.PrintManager;
                    printManager.PrintRange = PrintRange.Select;
                    ViewSheetSetting viewSheetSetting = printManager.ViewSheetSetting;
                    foreach (KeyValuePair <string, ViewSet> keyValuePair in viewSheetSetsList)
                    {
                        viewSheetSetting.CurrentViewSheetSet.Views = keyValuePair.Value;
                        viewSheetSetting.SaveAs(keyValuePair.Key);
                    }
                    tx2.Commit();
                }
                tg.Assimilate();
            }
        }
      Stream(ArrayList data, ViewSheetSetting viewSheetSetting)
      {
         data.Add(new Snoop.Data.ClassSeparator(typeof(ViewSheetSetting)));

         data.Add(new Snoop.Data.Object("Available views", viewSheetSetting.AvailableViews));
         data.Add(new Snoop.Data.Object("Current view sheet set", viewSheetSetting.CurrentViewSheetSet));
      }
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiApp      = commandData.Application;
            Document      currentDoc = uiApp.ActiveUIDocument.Document;

            //get the PrintManager from the current document
            PrintManager printManager = currentDoc.PrintManager;

            if (printManager.PrintRange != PrintRange.Select)
            {
                printManager.PrintRange = PrintRange.Select;
            }
            //get the ViewSheetSetting which manages the view / sheet set info of current document
            ViewSheetSetting viewSheetSetting = printManager.ViewSheetSetting;

            List <ElementId> revIDs     = Revision.GetAllRevisionIds(currentDoc).ToList();
            List <ElementId> activeRevs = new List <ElementId>();

            StringBuilder sb = new StringBuilder();

            foreach (ElementId eleid in revIDs)
            {
                Revision rev = currentDoc.GetElement(eleid) as Revision;
                if (rev.Issued == false)
                {
                    activeRevs.Add(eleid);
                }
            }

            FilteredElementCollector sheetsetcol = new FilteredElementCollector(currentDoc);
            List <Element>           viewsetlist = sheetsetcol.OfClass(typeof(ViewSheetSet)).ToList();

            foreach (Element elset in viewsetlist)
            {
                ViewSheetSet vss  = elset as ViewSheetSet;
                string       name = vss.Name;
                foreach (ElementId id in activeRevs)
                {
                    Revision rev     = currentDoc.GetElement(id) as Revision;
                    string   revname = rev.Name;
                    if (name == revname)
                    {
                        viewSheetSetting.CurrentViewSheetSet = vss;
                        viewSheetSetting.Delete();
                    }
                }
            }

            foreach (ElementId revid in activeRevs)
            {
                Revision rev     = currentDoc.GetElement(revid) as Revision;
                string   revname = rev.Name;

                FilteredElementCollector sheetCollector = new FilteredElementCollector(currentDoc);
                sheetCollector.OfCategory(BuiltInCategory.OST_Sheets);

                //create a new  ViewSet - add views to it that match the desired criteria
                ViewSet sheetset = new ViewSet();

                foreach (ViewSheet vs in sheetCollector)
                {
                    List <ElementId> revset = vs.GetAllRevisionIds().ToList();
                    if (revset.Contains(revid))
                    {
                        sheetset.Insert(vs);
                    }
                }

                viewSheetSetting.CurrentViewSheetSet.Views = sheetset;
                viewSheetSetting.SaveAs(revname);

                sb.AppendLine(revname + " Contains " + sheetset.Size + " sheets.");
            }
            string outlist = sb.ToString();

            TaskDialog.Show("View Set", outlist);
            return(Result.Succeeded);
        }
Beispiel #10
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp      = commandData.Application;
            UIDocument    uidoc      = uiapp.ActiveUIDocument;
            Application   app        = uiapp.Application;
            Document      doc        = uidoc.Document;
            View          activeView = doc.ActiveView;

            ICollection <ElementId> selectedSheetsId = uidoc.Selection.GetElementIds();

            string  viewSetName = app.Username + " Temp";
            ViewSet myViewSet   = new ViewSet();

            FilteredElementIterator elemItr = new FilteredElementCollector(doc).OfClass(typeof(ViewSheetSet)).GetElementIterator();

            elemItr.Reset();

            Element existingViewSet = null;

            while (elemItr.MoveNext())
            {
                if (elemItr.Current.Name == viewSetName)
                {
                    existingViewSet = elemItr.Current;
                }
            }

            IEnumerable <ViewSheet> sheetItr = new FilteredElementCollector(doc).OfClass(typeof(ViewSheet)).ToElements().Cast <ViewSheet>();

            foreach (ViewSheet e in sheetItr)
            {
                if (selectedSheetsId.Contains(e.Id))
                {
                    myViewSet.Insert(e);
                }
            }


            using (Transaction t = new Transaction(doc))
            {
                t.Start("Create View Set");

                //If exists, delete existing viewset
                try
                {
                    doc.Delete(existingViewSet.Id);
                }
                catch
                {
                    //if the view set does not exists, don't crash
                }

                //Create the new viewset
                PrintManager printMan = doc.PrintManager;
                printMan.PrintRange = PrintRange.Select;
                ViewSheetSetting viewSetting = printMan.ViewSheetSetting;
                viewSetting.CurrentViewSheetSet.Views = myViewSet;
                viewSetting.SaveAs(viewSetName);

                t.Commit();
            }

            //RevitCommandId id = RevitCommandId.LookupPostableCommandId(PostableCommand.SheetIssuesOrRevisions);

            //Jrn.RibbonEvent "Execute external command:CustomCtrl_%CustomCtrl_%CADtools%Publish%Batch" & vbCr & "Publish:Arup.CADtools.Revit.Commands.RevitPublishCmd"
            //vbCr = "\r"
            string name = "CustomCtrl_%CustomCtrl_%CADtools%Publish%Batch\rPublish";

            RevitCommandId id = RevitCommandId.LookupCommandId(name);

            uidoc.Application.PostCommand(id);


            return(Result.Succeeded);
        }
Beispiel #11
0
        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;
            ViewSet  FilteredSheets = new ViewSet();

            List <Revision> revList = new List <Revision>();

            foreach (Revision revis in new FilteredElementCollector(doc).OfClass(typeof(Revision)))
            {
                revList.Add(revis);
            }
            SelectRev revMenu   = new SelectRev(revList);
            Revision  targetRev = revMenu.getRevision();

            if (revMenu.closed)
            {
                return(Result.Succeeded);
            }
            foreach (ViewSheet vs in new FilteredElementCollector(doc).OfClass(typeof(ViewSheet)).Cast <ViewSheet>())
            {
                IList <ElementId> Revisions = vs.GetAllRevisionIds();
                foreach (ElementId rev in Revisions)
                {
                    if (rev.ToString() == targetRev.Id.ToString())
                    {
                        FilteredSheets.Insert(vs);
                    }
                }
            }
            PrintManager printManager = doc.PrintManager;

            printManager.PrintRange = PrintRange.Select;
            ViewSheetSetting viewSheetSetting = printManager.ViewSheetSetting;

            viewSheetSetting.CurrentViewSheetSet.Views = FilteredSheets;
            String sheetSetName = targetRev.SequenceNumber + ": " + targetRev.Description;

            using (Transaction t = new Transaction(doc, "Creating PrintSet"))
            {
                t.Start();
                try
                {
                    viewSheetSetting.SaveAs(sheetSetName);
                }
                catch (Autodesk.Revit.Exceptions.InvalidOperationException)
                {
                    foreach (ViewSheetSet viewSheetSetToDelete in (from element
                                                                   in new FilteredElementCollector(doc)
                                                                   .OfClass(typeof(ViewSheetSet)).ToElements()
                                                                   where element.Name.Contains(sheetSetName) && element.IsValidObject
                                                                   select element as ViewSheetSet).ToList().Distinct())
                    {
                        viewSheetSetting.CurrentViewSheetSet = printManager.ViewSheetSetting.InSession;
                        viewSheetSetting.CurrentViewSheetSet = viewSheetSetToDelete as ViewSheetSet;
                        printManager.ViewSheetSetting.Delete();
                    }
                    ViewSheetSetting viewSheetSetting_alt = printManager.ViewSheetSetting;
                    viewSheetSetting_alt.CurrentViewSheetSet.Views = FilteredSheets;
                    viewSheetSetting_alt.SaveAs(sheetSetName);
                }
                t.Commit();
                TaskDialog td = new TaskDialog("Printing Revision")
                {
                    MainInstruction = sheetSetName + " - created as new print set (" + FilteredSheets.Size + " sheets)."
                                      + Environment.NewLine + "Start Print with current Settings?",
                    FooterText = doc.PrintManager.PrinterName
                };
                if (doc.PrintManager.PrinterName.Contains("\\"))
                {
                    td.FooterText = td.FooterText.Insert(td.FooterText.Length, " *!Real Print!* ").Insert(0, " *!Real Print!* ");
                }
                td.CommonButtons = TaskDialogCommonButtons.Ok | TaskDialogCommonButtons.No;
                TaskDialogResult response = td.Show();
                if ((response != TaskDialogResult.Cancel) && (response != TaskDialogResult.No))
                {
                    try
                    {
                        if (FilteredSheets.Size != 0)
                        {
                            doc.Print(FilteredSheets);
                            //if (revMenu.path != null)
                            //{
                            //set print setting to selected path

                            //Open XMl at C:\Users\(ID)\AppData\Roaming\Foxit Software\Foxit PDF Creator\Foxit Reader PDF Printer
                            //Find latest .XML
                            //Overwrite path ( folderarray 0 ++ )

                            //Implement rename
                            //TaskDialog.Show("Path", revMenu.path);
                            //}
                            //else just implement rename
                        }
                        else
                        {
                            TaskDialog.Show("Please select another Revision", "Selected Revision has not been added to any of the sheets.");
                        }
                    }
                    catch (Autodesk.Revit.Exceptions.InvalidOperationException)
                    { TaskDialog.Show("Please select another Revision", "Selected Revision has not been added to any of the sheets."); }
                }
                return(Result.Succeeded);
            }
        }
Beispiel #12
0
        public static void print(Document doc)
        {
            ViewSet myViewSet = new ViewSet();
            var     collector =
                new FilteredElementCollector(doc)
                .OfClass(typeof(ViewSheet))
                .Cast <ViewSheet>().ToList();

            foreach (ViewSheet vs in collector)
            {
                if (!vs.IsTemplate && vs.CanBePrinted &&
                    vs.ViewType == ViewType.DrawingSheet)
                {
                    myViewSet.Insert(vs);
                    using (Transaction tx = new Transaction(doc))
                    {
                        tx.Start("Transaction Name");
                        vs.Print(true);
                        tx.Commit();
                    }
                }
            }

            var printsettings = doc.GetPrintSettingIds();

            string       setName = Helper.RandomString(10);
            PrintManager pm      = doc.PrintManager;

            using (Transaction tx = new Transaction(doc))
            {
                tx.Start("Transaction Name");


                pm.SelectNewPrintDriver("Adobe PDF");

                //PaperSizeSet ps = pm.PaperSizes;
                pm.PrintRange   = PrintRange.Select;
                pm.CombinedFile = false;
                pm.PrintToFile  = true;
                pm.PrintSetup.CurrentPrintSetting.PrintParameters.RasterQuality   = RasterQualityType.Presentation;
                pm.PrintSetup.CurrentPrintSetting.PrintParameters.ColorDepth      = ColorDepthType.Color;
                pm.PrintSetup.CurrentPrintSetting.PrintParameters.ViewLinksinBlue = false;


                ViewSheetSetting viewSheetSetting = pm.ViewSheetSetting;

                // try
                // {
                // Save the current view sheet set to another view/sheet set with the specified name.
                viewSheetSetting.SaveAs(setName);
                //}
                //catch (Exception) { }
                viewSheetSetting.CurrentViewSheetSet.Views = myViewSet;
                viewSheetSetting.Save();
                pm.Apply();



                pm.PrintToFileName = FileManager.pdfout + setName + Convert.ToString(setName.GetHashCode()) + ".pdf";
                pm.SubmitPrint();
                tx.Commit();
            }

            using (Transaction tx = new Transaction(doc))
            {
                tx.Start("print Name");
                pm.SubmitPrint();
                tx.Commit();
            }
        }
Beispiel #13
0
        private void BtnCreate_Click(object sender, EventArgs e)
        {
            #region check Sheet Set Name entered?
            if (TxbSetName.Text == "")
            {
                UI.Info.Form_Info1.infoMsgMain = "Value missing";
                UI.Info.Form_Info1.infoMsgBody = "Please, enter Sheet Set Name to continue.";
                using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1())
                {
                    thisForm.ShowDialog();
                }
                return;
            }
            #endregion// check if the user entered a Set Name

            #region check if new print set name exists
            // get new sheet set name
            string sheetSetName = TxbSetName.Text;

            // collect existing view sheet sets
            List <Element> existingViewSheetSet = new FilteredElementCollector(m_doc)
                                                  .OfClass(typeof(ViewSheetSet))
                                                  .WhereElementIsNotElementType()
                                                  .ToElements()
                                                  .ToList();
            Dictionary <Element, string> existingVSSDict = new Dictionary <Element, string>();
            foreach (Element el in existingViewSheetSet)
            {
                existingVSSDict.Add(el, el.Name);
            }
            if (existingVSSDict.ContainsValue(sheetSetName))
            {
                UI.Info.Form_Info1.infoMsgMain = "Duplicated name";
                UI.Info.Form_Info1.infoMsgBody = "You have chosen a Sheet Set Name that already exists.\nPlease enter a different name.";
                using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1())
                {
                    thisForm.ShowDialog();
                }
                return;
            }
            #endregion

            #region check sheets selected?
            if (LsvSheets.CheckedItems.Count == 0)
            {
                UI.Info.Form_Info1.infoMsgMain = "Select";
                UI.Info.Form_Info1.infoMsgBody = "Please, select one or more sheets to continue.";
                using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1())
                {
                    thisForm.ShowDialog();
                }
                return;
            }
            #endregion

            #region create Sheet Set
            // collect selected sheets
            List <string>    selSheetsTxt  = new List <string>();
            List <ViewSheet> allViewSheets = Data.Helpers.GetViewSheets(m_doc);
            foreach (ListViewItem lv in LsvSheets.CheckedItems)
            {
                selSheetsTxt.Add(lv.SubItems[0].Text);
            }
            List <ViewSheet> selViewSheets = Data.Helpers.GetSelectedSheets(allViewSheets, selSheetsTxt);
            using (Transaction t = new Transaction(m_doc, "Create New Sheet Set"))
            {
                t.Start();
                PrintManager printManager = m_doc.PrintManager;
                printManager.PrintRange = PrintRange.Select;
                ViewSheetSetting existingPrintSets = printManager.ViewSheetSetting;

                // create ViewSet
                ViewSet myViewSet = new ViewSet();
                foreach (ViewSheet vs in selViewSheets)
                {
                    myViewSet.Insert(vs);
                }

                existingPrintSets.CurrentViewSheetSet.Views = myViewSet;
                existingPrintSets.SaveAs(sheetSetName);
                t.Commit();
            }
            #endregion

            #region show Results Form
            UI.Info.Form_Info1.infoMsgMain = "Results";
            UI.Info.Form_Info1.infoMsgBody = $"A new Sheet Set '{sheetSetName}' has been added to the project.";
            using (UI.Info.Form_Info1 thisForm = new Info.Form_Info1()) { thisForm.ShowDialog(); }
            #endregion

            DialogResult = DialogResult.OK;
        }
Beispiel #14
0
        public SheetsCSSFSRequest(UIApplication uiApp, String text)
        {
            MainUI      uiForm = BARevitTools.Application.thisApp.newMainUi;
            RVTDocument doc    = uiApp.ActiveUIDocument.Document;
            //From the MainUI's dictionary, get the schedule by name
            ViewSchedule schedule = uiForm.sheetsCSSFSDictionary[uiForm.sheetsCSSFSScheduleComboBox.Text];

            //Assuming the user has set the name for the sheet set, continue
            if (uiForm.sheetsCSSFSSetNameTextBox.Text != "<Sheet Set Name>" && uiForm.sheetsCSSFSSetNameTextBox.Text != "")
            {
                //Collect all sheets in the project
                var sheetCollection = new FilteredElementCollector(doc, schedule.Id).OfClass(typeof(ViewSheet)).ToElements();

                //Get the PrintManager for the project
                PrintManager printManager = doc.PrintManager;
                //Set the PrintManager PrintRange to Select
                printManager.PrintRange = PrintRange.Select;
                //Set the PrintManager ViewSheetSetting
                ViewSheetSetting viewSheetSetting = printManager.ViewSheetSetting;
                //Create a new transaction to make a temporary sheet set with the user defined name
                Transaction t0 = new Transaction(doc, "CreateTempSheetSet");
                t0.Start();
                viewSheetSetting.SaveAs(uiForm.sheetsCSSFSSetNameTextBox.Text);
                t0.Commit();
                //The temporary sheet set was needed to ensure there was a sheet set to modify

                //Collect the view sheet sets
                var viewSheetSets = new FilteredElementCollector(doc).OfClass(typeof(ViewSheetSet)).ToElements();
                Dictionary <string, ViewSheetSet> viewSheetSetDict = new Dictionary <string, ViewSheetSet>();
                List <string> viewSheetSetNames = new List <string>();

                //Add the view sheet sets to the dictionary and list
                foreach (ViewSheetSet viewSheetSet in viewSheetSets)
                {
                    viewSheetSetDict.Add(viewSheetSet.Name, viewSheetSet);
                    viewSheetSetNames.Add(viewSheetSet.Name);
                }

                //Make a new ViewSet
                Transaction t1 = new Transaction(doc, "CreateSheetSet");
                t1.Start();
                ViewSet newViewSet = new ViewSet();
                //Set the ViewSheetSetting to the current ViewSet's views
                viewSheetSetting.CurrentViewSheetSet.Views = newViewSet;
                if (sheetCollection != null)
                {
                    //For each sheet in the collection...
                    foreach (ViewSheet sheet in sheetCollection)
                    {
                        //If the sheet is not a placeholder, add it to the ViewSet
                        if (!sheet.IsPlaceholder)
                        {
                            newViewSet.Insert(sheet);
                        }
                    }
                    try
                    {
                        //If the ViewSheetSet list of names contains the user defined set...
                        if (viewSheetSetNames.Contains(uiForm.sheetsCSSFSSetNameTextBox.Text))
                        {
                            //Get the ID of the ViewSheetSet from the dictionary
                            ElementId vssId = viewSheetSetDict[uiForm.sheetsCSSFSSetNameTextBox.Text].Id;
                            //Delete that ViewSheetSet to make way for a new version. The old version was the temporary one
                            doc.Delete(vssId);
                            //Save the ViewSheetSetting as the user defined name for the sheet set
                            viewSheetSetting.SaveAs(uiForm.sheetsCSSFSSetNameTextBox.Text);
                        }
                        else
                        {
                            //If the ViewSheetSet did not already exist, save the ViewSheetSetting
                            viewSheetSetting.SaveAs(uiForm.sheetsCSSFSSetNameTextBox.Text);
                        }
                    }
                    catch
                    { MessageBox.Show("A sheet set with that name already exists"); }
                }
                t1.Commit();
            }
        }
Beispiel #15
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Document   doc   = uidoc.Document;

            Selection    selection = uidoc.Selection;
            PrintManager pm        = doc.PrintManager;

            pm.PrintRange = PrintRange.Select;
            ViewSheetSetting         vss = pm.ViewSheetSetting;
            ICollection <ElementId>  id;
            FilteredElementCollector collector;
            ElementClassFilter       wantedElements;
            PaperSizeSet             paperSize   = pm.PaperSizes;
            List <Element>           printElemes = null;


            using (Transaction trans = new Transaction(doc, "Print ViewSet"))
            {
                try
                {
                    id             = selection.GetElementIds();
                    collector      = new FilteredElementCollector(doc, id);
                    wantedElements = new ElementClassFilter(typeof(ViewSheet));
                    collector.WherePasses(wantedElements);
                    printElemes = collector.ToElements() as List <Element>;
                }
                catch (Autodesk.Revit.Exceptions.ApplicationException e)
                {
                    TaskDialog.Show("Error!", e.Message);
                    return(Result.Cancelled);
                }
                catch (Exception e)
                {
                    TaskDialog.Show("Error!", e.Message);
                }

                ViewSet viewSet = new ViewSet();

                foreach (var elem in printElemes)
                {
                    ViewSheet viewSheet = elem as ViewSheet;
                    viewSet.Insert(viewSheet);
                }

                trans.Start();

                try
                {
                    vss.CurrentViewSheetSet.Views = viewSet;
                    vss.Save();

                    pm.SelectNewPrintDriver("Microsoft Print to PDF");
                    pm.Apply();
                    //pm.PrintSetup.Save();

                    pm.PrintSetup.CurrentPrintSetting.PrintParameters.PageOrientation = PageOrientationType.Landscape;
                    pm.PrintSetup.CurrentPrintSetting.PrintParameters.PaperPlacement  = PaperPlacementType.Center;
                    pm.PrintSetup.CurrentPrintSetting.PrintParameters.ZoomType        = ZoomType.Zoom;
                    pm.PrintSetup.CurrentPrintSetting.PrintParameters.Zoom            = 100;
                    pm.CombinedFile = true;
                    //pm.PrintToFile = true;
                    //pm.PrintToFileName = @"C:\Users\Lenovo\Desktop\file.pdf";
                    pm.Apply();
                    //pm.PrintSetup.Save();
                    pm.SubmitPrint();
                }
                catch (Exception e)
                {
                    message = e.Message;
                    return(Result.Failed);
                }
                trans.Commit();
                // return Result.Succeeded;
            }

            return(Result.Succeeded);
        }
        private void Publish()
        {
            string      prop             = cbRevisions.SelectedItem.ToString();
            int         selectedSequence = RevisionSequenceNumber(prop);
            Transaction trans            = new Transaction(myRevitDoc, "Publish");

            dInfo = new DirectoryInfo(txtPrintLocation.Text);

            try
            {
                #region CreateSheetSet

                set = new ViewSet();

                foreach (ViewSheet vss in viewSheets)
                {
                    IList <ElementId> revisionIds = vss.GetAllRevisionIds();

                    foreach (ElementId i in revisionIds)
                    {
                        Element  elem = myRevitDoc.GetElement(i);
                        Revision r    = elem as Revision;

                        int    sequenceNumber = r.SequenceNumber;
                        string num            = vss.GetRevisionNumberOnSheet(i);
                        string date           = r.RevisionDate;

                        set.Insert(vss);
                    }
                }

                PrintManager print = myRevitDoc.PrintManager;
                print.PrintRange = PrintRange.Select;
                ViewSheetSetting viewSheetSetting = print.ViewSheetSetting;
                viewSheetSetting.CurrentViewSheetSet.Views = set;

                trans.Start();
                viewSheetSetting.SaveAs(prop);
                trans.Commit();

                #endregion

                // Create a file listener and wait until all the files have been printed before renaming
                w              = new FileSystemWatcher();
                w.Path         = dInfo.FullName;
                w.NotifyFilter = NotifyFilters.LastAccess
                                 | NotifyFilters.LastWrite
                                 | NotifyFilters.FileName
                                 | NotifyFilters.DirectoryName;

                w.Filter   = "*.pdf";
                w.Created += OnCreated;

                w.EnableRaisingEvents = true;

                // Print the newly created sheet set
                print.SubmitPrint();
                print.Dispose();
            }
            catch (Exception ex)
            {
                TaskDialog error = new TaskDialog("Publish");
                error.MainInstruction = "Failed to publish " + prop;
                error.MainContent     = ex.Message;
                trans.RollBack();
                error.Show();
            }
        }
        CollectEvent(object sender, CollectorEventArgs e)
        {
            // cast the sender object to the SnoopCollector we are expecting
            Collector snoopCollector = sender as Collector;

            if (snoopCollector == null)
            {
                Debug.Assert(false); // why did someone else send us the message?
                return;
            }

            // see if it is a type we are responsible for
            Color color = e.ObjToSnoop as Color;

            if (color != null)
            {
                Stream(snoopCollector.Data(), color);
                return;
            }

            LayoutRule layoutRule = e.ObjToSnoop as LayoutRule;

            if (layoutRule != null)
            {
                Stream(snoopCollector.Data(), layoutRule);
                return;
            }

            FormatOptions formatOptions = e.ObjToSnoop as FormatOptions;

            if (formatOptions != null)
            {
                Stream(snoopCollector.Data(), formatOptions);
                return;
            }

            CurtainGrid curtainGrid = e.ObjToSnoop as CurtainGrid;

            if (curtainGrid != null)
            {
                Stream(snoopCollector.Data(), curtainGrid);
                return;
            }

            CurtainCell curtainCell = e.ObjToSnoop as CurtainCell;

            if (curtainCell != null)
            {
                Stream(snoopCollector.Data(), curtainCell);
                return;
            }

            RebarHostData rebarHostData = e.ObjToSnoop as RebarHostData;

            if (rebarHostData != null)
            {
                Stream(snoopCollector.Data(), rebarHostData);
                return;
            }

            Leader leader = e.ObjToSnoop as Leader;

            if (leader != null)
            {
                Stream(snoopCollector.Data(), leader);
                return;
            }

            AreaVolumeSettings areaSettings = e.ObjToSnoop as AreaVolumeSettings;

            if (areaSettings != null)
            {
                Stream(snoopCollector.Data(), areaSettings);
                return;
            }

            ViewSheetSetting viewSheetSetting = e.ObjToSnoop as ViewSheetSetting;

            if (viewSheetSetting != null)
            {
                Stream(snoopCollector.Data(), viewSheetSetting);
                return;
            }

            Autodesk.Revit.UI.Events.DialogBoxData dlgBoxData = e.ObjToSnoop as Autodesk.Revit.UI.Events.DialogBoxData;
            if (dlgBoxData != null)
            {
                Stream(snoopCollector.Data(), dlgBoxData);
                return;
            }

            Construction construct = e.ObjToSnoop as Construction;

            if (construct != null)
            {
                Stream(snoopCollector.Data(), construct);
                return;
            }

            FamilyElementVisibility famElemVisib = e.ObjToSnoop as FamilyElementVisibility;

            if (famElemVisib != null)
            {
                Stream(snoopCollector.Data(), famElemVisib);
                return;
            }

            FamilyManager famManager = e.ObjToSnoop as FamilyManager;

            if (famManager != null)
            {
                Stream(snoopCollector.Data(), famManager);
                return;
            }

            FamilyParameter famParam = e.ObjToSnoop as FamilyParameter;

            if (famParam != null)
            {
                Stream(snoopCollector.Data(), famParam);
                return;
            }

            FamilyType famType = e.ObjToSnoop as FamilyType;

            if (famType != null)
            {
                Stream(snoopCollector.Data(), famType);
                return;
            }

            MEPSpaceConstruction mepSpaceConstuct = e.ObjToSnoop as MEPSpaceConstruction;

            if (mepSpaceConstuct != null)
            {
                Stream(snoopCollector.Data(), mepSpaceConstuct);
                return;
            }

            BuildingSiteExportOptions bldSiteExpOptions = e.ObjToSnoop as BuildingSiteExportOptions;

            if (bldSiteExpOptions != null)
            {
                Stream(snoopCollector.Data(), bldSiteExpOptions);
                return;
            }

            DGNExportOptions dgnExpOptions = e.ObjToSnoop as DGNExportOptions;

            if (dgnExpOptions != null)
            {
                Stream(snoopCollector.Data(), dgnExpOptions);
                return;
            }

            DWFExportOptions dwfExpOptions = e.ObjToSnoop as DWFExportOptions;

            if (dwfExpOptions != null)
            {
                Stream(snoopCollector.Data(), dwfExpOptions);
                return;
            }

            DWGExportOptions dwgExpOptions = e.ObjToSnoop as DWGExportOptions;

            if (dwgExpOptions != null)
            {
                Stream(snoopCollector.Data(), dwgExpOptions);
                return;
            }

            DWGImportOptions dwgImpOptions = e.ObjToSnoop as DWGImportOptions;

            if (dwgImpOptions != null)
            {
                Stream(snoopCollector.Data(), dwgImpOptions);
                return;
            }

            FBXExportOptions fbxExpOptions = e.ObjToSnoop as FBXExportOptions;

            if (fbxExpOptions != null)
            {
                Stream(snoopCollector.Data(), fbxExpOptions);
                return;
            }

            TrussMemberInfo trussInfo = e.ObjToSnoop as TrussMemberInfo;

            if (trussInfo != null)
            {
                Stream(snoopCollector.Data(), trussInfo);
                return;
            }

            VertexIndexPair vertIndPair = e.ObjToSnoop as VertexIndexPair;

            if (vertIndPair != null)
            {
                Stream(snoopCollector.Data(), vertIndPair);
                return;
            }

            PointElementReference ptElemRef = e.ObjToSnoop as PointElementReference;

            if (ptElemRef != null)
            {
                Stream(snoopCollector.Data(), ptElemRef);
                return;
            }

            Autodesk.Revit.DB.Architecture.BoundarySegment boundSeg = e.ObjToSnoop as Autodesk.Revit.DB.Architecture.BoundarySegment;
            if (boundSeg != null)
            {
                Stream(snoopCollector.Data(), boundSeg);
                return;
            }

            PointLocationOnCurve ptLocOnCurve = e.ObjToSnoop as PointLocationOnCurve;

            if (ptLocOnCurve != null)
            {
                Stream(snoopCollector.Data(), ptLocOnCurve);
                return;
            }

            Entity entity = e.ObjToSnoop as Entity;

            if (entity != null)
            {
                Stream(snoopCollector.Data(), entity);
                return;
            }

            Field field = e.ObjToSnoop as Field;

            if (field != null)
            {
                Stream(snoopCollector.Data(), field);
                return;
            }

            ExtensibleStorageField storeagefield = e.ObjToSnoop as ExtensibleStorageField;

            if (storeagefield != null)
            {
                Stream(snoopCollector.Data(), storeagefield);
                return;
            }

            IList <Autodesk.Revit.DB.BoundarySegment> boundSegs = e.ObjToSnoop as
                                                                  IList <Autodesk.Revit.DB.BoundarySegment>;

            if (boundSegs != null)
            {
                Stream(snoopCollector.Data(), boundSegs);
                return;
            }

            if (e.ObjToSnoop is KeyValuePair <String, String> )
            {
                KeyValuePair <String, String> stringspair = (KeyValuePair <String, String>)e.ObjToSnoop;
                Stream(snoopCollector.Data(), stringspair);
                return;
            }

            Schema schema = e.ObjToSnoop as Schema;

            if (schema != null)
            {
                Stream(snoopCollector.Data(), schema);
                return;
            }

            ElementId elemId = e.ObjToSnoop as ElementId;

            if (elemId != null)
            {
                Stream(snoopCollector.Data(), elemId);
                return;
            }

            PlanViewRange plvr = e.ObjToSnoop as PlanViewRange;

            if (plvr != null)
            {
                Stream(snoopCollector.Data(), plvr);
                return;
            }
            //TF
            RebarConstraintsManager rbcm = e.ObjToSnoop as RebarConstraintsManager;

            if (rbcm != null)
            {
                Stream(snoopCollector.Data(), rbcm);
                return;
            }

            RebarConstrainedHandle rbch = e.ObjToSnoop as RebarConstrainedHandle;

            if (rbch != null)
            {
                Stream(snoopCollector.Data(), rbch);
                return;
            }

            RebarConstraint rbc = e.ObjToSnoop as RebarConstraint;

            if (rbc != null)
            {
                Stream(snoopCollector.Data(), rbc);
                return;
            }

            //TFEND

            if (Utils.IsSupportedType(e.ObjToSnoop) && e.ObjToSnoop != null)
            {
                Utils.StreamWithReflection(snoopCollector.Data(), e.ObjToSnoop.GetType(), e.ObjToSnoop);
            }
        }
Beispiel #18
0
 public ViewSheets(Document doc)
 {
     m_doc = doc;
     m_viewSheetSetting = doc.PrintManager.ViewSheetSetting;
 }
Beispiel #19
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            string prop             = cbRevisions.SelectedItem.ToString();
            int    selectedSequence = RevisionSequenceNumber(prop);

            ViewSet set = new ViewSet();

            foreach (ViewSheet vss in viewSheets)
            {
                IList <ElementId> revisionIds = vss.GetAllRevisionIds();

                foreach (ElementId i in revisionIds)
                {
                    Element  elem = myRevitDoc.GetElement(i);
                    Revision r    = elem as Revision;

                    int    sequenceNumber = r.SequenceNumber;
                    string num            = vss.GetRevisionNumberOnSheet(i);
                    string date           = r.RevisionDate;

                    if (rbSequence.Checked)
                    {
                        if (selectedSequence == sequenceNumber)
                        {
                            set.Insert(vss);
                        }
                    }
                    else if (rbNumber.Checked)
                    {
                        if (num == prop)
                        {
                            set.Insert(vss);
                        }
                    }
                    else
                    {
                        if (date == prop)
                        {
                            set.Insert(vss);
                        }
                    }
                }
            }

            PrintManager print = myRevitDoc.PrintManager;

            print.PrintRange = PrintRange.Select;
            ViewSheetSetting viewSheetSetting = print.ViewSheetSetting;

            viewSheetSetting.CurrentViewSheetSet.Views = set;

            Transaction trans = new Transaction(myRevitDoc, "Create Sheet Set");

            trans.Start();

            try
            {
                viewSheetSetting.SaveAs(prop);
                TaskDialog dialog = new TaskDialog("Create Sheet Set");
                dialog.MainInstruction = prop + " was created successfully";
                trans.Commit();
                dialog.Show();
            }
            catch (Exception ex)
            {
                TaskDialog dialog = new TaskDialog("Create Sheet Set");
                dialog.MainInstruction = "Failed to create " + prop;
                dialog.MainContent     = ex.Message;
                trans.RollBack();
                dialog.Show();
            }
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            string SetName       = SetNameBox.Text;
            int    selectedIndex = Cbx.SelectedIndex;

            // Read each cell and find the sheet with that number
            foreach (int num in Enumerable.Range(0, nRows))
            {
                string SchedSheetNum = viewSched.GetCellText((SectionType.Body), num, selectedIndex).ToString();

                foreach (ViewSheet sheet in sheetList)
                {
                    if (SchedSheetNum == sheet.SheetNumber)
                    {
                        viewSet.Insert(sheet);
                        break;
                    }
                }
            }



            if (viewSet.Size == 0)
            {
                SetButton.IsEnabled = false; // Disable SetButton or user may crash revit
                Utils.SimpleDialog("No sheet numbers in this column", "");
                SetButton.IsEnabled = true;
            }

            else
            {
                using (Transaction transac = new Transaction(doc))
                {
                    transac.Start("Set by index");

                    // PrintManager saves the set and selects it
                    PrintManager printManager = doc.PrintManager;
                    printManager.PrintRange = PrintRange.Select;

                    ViewSheetSetting viewSheetSetting = printManager.ViewSheetSetting;
                    viewSheetSetting.CurrentViewSheetSet.Views = viewSet;

                    bool flag = false;
                    try
                    {
                        viewSheetSetting.SaveAs(SetName);
                        flag = true;
                    }

                    // Set already exists
                    catch (Autodesk.Revit.Exceptions.InvalidOperationException ex)
                    {
                        TaskDialog mainDialog = new TaskDialog("ASG");
                        mainDialog.TitleAutoPrefix = false;
                        mainDialog.MainInstruction = "Replace existing set?";
                        mainDialog.CommonButtons   = TaskDialogCommonButtons.Yes | TaskDialogCommonButtons.No;
                        TaskDialogResult res = mainDialog.Show();

                        if (res == TaskDialogResult.Yes)
                        {
                            // Delete existing set
                            FilteredElementCollector Sheet_Set_Collector = new FilteredElementCollector(doc);

                            ViewSheetSet SetToDel = Sheet_Set_Collector.OfClass(typeof(ViewSheetSet))
                                                    .Cast <ViewSheetSet>()
                                                    .Where(i => i.Name == SetName)
                                                    .FirstOrDefault();
                            doc.Delete(SetToDel.Id);

                            viewSheetSetting.SaveAs(SetName);
                            flag = true;
                        }

                        // Else cancel
                        else
                        {
                            SetButton.IsEnabled = false;
                            SetButton.IsEnabled = true;

                            flag = false;

                            transac.RollBack();
                        }
                    }
                    finally
                    {
                        if (flag)
                        {
                            Close();
                            Utils.SimpleDialog(
                                $"Created set '{SetName}' with {viewSet.Size} sheet", "");

                            transac.Commit();
                        }
                    }
                }
            }
        }