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 { } } }