public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { IWin32Window revit_window = new JtWindowHandle( ComponentManager.ApplicationWindow); UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Document doc = uidoc.Document; if (doc.IsFamilyDocument) { TaskDialog.Show("Not a Revit RVT Project", "This command requires an active Revit RVT file."); return(Result.Failed); } if (!(doc.ActiveView is ViewSheet)) { TaskDialog.Show("Current View is not a Sheet", "This command requires an active sheet view."); return(Result.Failed); } IList <ElementId> ids = Revision.GetAllRevisionIds(doc); int n = ids.Count; List <RevisionData> revision_data = new List <RevisionData>(n); foreach (ElementId id in ids) { Revision r = doc.GetElement(id) as Revision; revision_data.Add(new RevisionData(r)); } DisplayRevisionData(revision_data, revit_window); return(Result.Succeeded); }
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); }