public bool Delete() { try { return(m_viewSheetSetting.Delete()); } catch (Exception ex) { PrintMgr.MyMessageBox(ex.Message); return(false); } }
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(); }
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); }