Ejemplo n.º 1
0
        private void DeleteAllViewsAndSheets(UIApplication uiApp, bool deleteViewsBool, bool deleteSheetsBool)
        {
            Document doc = uiApp.ActiveUIDocument.Document;
            string message = "";

            using (Transaction trans = new Transaction(doc, "Delete All Views and Sheets"))
            {
                trans.Start();
                List<Element> delElements = new List<Element>();
                if (deleteViewsBool == true)
                {
                    // add views
                    IList<Element> views = GetViewsToDelete(doc);
                    foreach (Element e in views)
                    {
                        delElements.Add(e);
                    }
                }
                if (deleteSheetsBool == true)
                {
                    // add sheets
                    IList<Element> sheets = GetSheetsToDelete(doc);
                    foreach (Element e in sheets)
                    {
                        delElements.Add(e);
                    }
                }

                // Delete Elements based on input delElements
                int n = delElements.Count;
                string s = "{0} of " + n.ToString() + " Sheets/Views processed...";
                string caption = "Delete All Views/Sheets";
                using (ProgressForm pf = new ProgressForm(caption, s, n))
                {
                    foreach (Element e in delElements)
                    {
                        try
                        {
                            doc.Delete(e.Id);
                        }
                        catch (Exception x)
                        {
                            message = x.Message;
                        }
                        pf.Increment();
                    }
                }
                trans.Commit();
            }
        }
        public Result Execute2(
          ExternalCommandData commandData,
          ref string message,
          ElementSet elements,
          bool delViews,
          bool delSheets)
        {
            // Get application and document objects
            UIApplication uiApp = commandData.Application;
            Document doc = uiApp.ActiveUIDocument.Document;
            UIDocument uidoc = uiApp.ActiveUIDocument;

            try
            {
                using (Transaction trans = new Transaction(doc, "UpperCase Views on Sheets."))
                {
                    // Get All Elements to delete
                    List<Element> delElements = new List<Element>();
                    if (delViews == true)
                    {
                        // add views
                        IList<Element> views = GetViewsToDelete(doc);
                        foreach (Element e in views)
                        {
                            delElements.Add(e);
                        }
                    }
                    if (delSheets == true)
                    {
                        // add sheets
                        IList<Element> sheets = GetSheetsToDelete(doc);
                        foreach (Element e in sheets)
                        {
                            delElements.Add(e);
                        }
                    }

                    // Delete Elements based on input delElements
                    int n = delElements.Count;
                    string s = "{0} of " + n.ToString() + " Sheets/Views processed...";
                    string caption = "Delete All Views/Sheets";
                    using (ProgressForm pf = new ProgressForm(caption, s, n))
                    {
                        foreach (Element e in delElements)
                        {
                            try
                            {
                                doc.Delete(e.Id);
                            }
                            catch (Exception x)
                            {
                                message = x.Message;
                            }
                            pf.Increment();
                        }
                    }
                    trans.Commit();
                }
                return Result.Succeeded;
            }
            // Catch any Exceptions and display them.
            catch (Autodesk.Revit.Exceptions.OperationCanceledException)
            {
                return Result.Cancelled;
            }
            catch (Exception x)
            {
                message = x.Message;
                return Result.Failed;
            }
        }
Ejemplo n.º 3
0
        public Result Execute2(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements,
            bool delViews,
            bool delSheets)
        {
            // Get application and document objects
            UIApplication uiApp = commandData.Application;
            Document      doc   = uiApp.ActiveUIDocument.Document;
            UIDocument    uidoc = uiApp.ActiveUIDocument;

            try
            {
                using (Transaction trans = new Transaction(doc, "UpperCase Views on Sheets."))
                {
                    // Get All Elements to delete
                    List <Element> delElements = new List <Element>();
                    if (delViews == true)
                    {
                        // add views
                        IList <Element> views = GetViewsToDelete(doc);
                        foreach (Element e in views)
                        {
                            delElements.Add(e);
                        }
                    }
                    if (delSheets == true)
                    {
                        // add sheets
                        IList <Element> sheets = GetSheetsToDelete(doc);
                        foreach (Element e in sheets)
                        {
                            delElements.Add(e);
                        }
                    }

                    // Delete Elements based on input delElements
                    int    n       = delElements.Count;
                    string s       = "{0} of " + n.ToString() + " Sheets/Views processed...";
                    string caption = "Delete All Views/Sheets";
                    using (ProgressForm pf = new ProgressForm(caption, s, n))
                    {
                        foreach (Element e in delElements)
                        {
                            try
                            {
                                doc.Delete(e.Id);
                            }
                            catch (Exception x)
                            {
                                message = x.Message;
                            }
                            pf.Increment();
                        }
                    }
                    trans.Commit();
                }
                return(Result.Succeeded);
            }
            // Catch any Exceptions and display them.
            catch (Autodesk.Revit.Exceptions.OperationCanceledException)
            {
                return(Result.Cancelled);
            }
            catch (Exception x)
            {
                message = x.Message;
                return(Result.Failed);
            }
        }