Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        private void Stream( ArrayList data, ViewSheetSet viewSheetSet )
        {
            data.Add( new Snoop.Data.ClassSeparator( typeof( ViewSheetSet ) ) );

              data.Add( new Snoop.Data.Enumerable( "Views", viewSheetSet.Views ) );
        }
        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();
                        }
                    }
                }
            }
        }