public void Ungroup(Document doc, UIDocument uidoc) { IList<Category> categoryToDelete = new List<Category>(); List<Group> ungroupList = new List<Group>(); //Finds the groups in the project FilteredElementCollector collector = new FilteredElementCollector(uidoc.Document).OfClass(typeof(Group)); FilteredElementIterator itr = collector.GetElementIterator(); //Gets the dictionary to lookup line getLines getlines = new getLines(path); var dictionary = getlines.DictionaryLines(); //iterators over all the groups while (itr.MoveNext()) { Element element = (Element)itr.Current; Group group = doc.GetElement(element.Id) as Group; List<ElementId> groupElements = group.GetMemberIds().ToList(); foreach (ElementId lineStyle in groupElements) { Element elements = doc.GetElement(lineStyle); CurveElement curveElement = elements as CurveElement; try { string lineStyleName = curveElement.LineStyle.Name; if (lineStyleName != null) { //compare lines to dictionary to ungroup. if (dictionary.ContainsKey(lineStyleName)) { ungroupList.Add(group); } } } catch { } } } foreach (Group group in ungroupList) { try { ungroup(doc, group); //CreateGroup(doc, uidoc); } catch { } } }
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; DeleteLinesWPF linesWPF = new DeleteLinesWPF(); var res = linesWPF.ShowDialog(); if (!(res.HasValue && res.Value)) return Result.Cancelled; //EXCEL FILE OfficeOpenXml.ExcelPackage package = new OfficeOpenXml.ExcelPackage(); using (var fs = new System.IO.FileStream(linesWPF.ExcelListPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { package.Load(fs); } string path = linesWPF.ExcelListPathTextBox.Text; //------------------ getLines getLines = new getLines(path); groups groupitems = new groups(); filledRegion fillRegions = new filledRegion(); string selectedItem = linesWPF.SelectComboBox.SelectedItem.ToString(); // ENTIRE PROJECT if (selectedItem == "Entire Project") { groupitems.Ungroup(doc, uidoc, path); getLines.StandardSOMLineStyle(doc); if (linesWPF.checkboxDeleteLines.IsChecked == true) { getLines.deleteLineStyle(doc); } if (linesWPF.checkboxFilledRegion.IsChecked == true) { fillRegions.EditFilledRegion(doc); } if (linesWPF.checkboxDeleteLinePatterns.IsChecked == true) { getLines.deleteLinePatterns(doc); } } // ACTIVE VIEW if (selectedItem == "Active View") { groupitems.UngroupActiveView(doc, uidoc, path); getLines.StandardSOMLineStylesInActiveView(doc); getLines.StandardSOMFilledStylesInActiveView(doc); fillRegions.MoveFilledReigionInActiveViews(doc); } return Result.Succeeded; }