private static void OnFindGroup(GroupTypeWrapper gt) { if (gt == null) { return; } AppCommand.GroupManagerHandler.Arg1 = gt; AppCommand.GroupManagerHandler.Request.Make(GroupRequestType.FindView); AppCommand.GroupManagerEvent.Raise(); }
/// <summary> /// Handles processing of Groups being added or removed. This can be done here instead of a External Command Handler /// because the only thing that we are updating is the UI so we don't need to be in Revit context. /// </summary> /// <param name="msg">Document Changed Message object.</param> /// <param name="groups">Groups stored on the UI.</param> public void ProcessDocumentChanged(DocumentChanged msg, ObservableCollection <GroupTypeWrapper> groups) { if (msg.Deleted.Any()) { // (Konrad) Handle GroupType being deleted groups.RemoveAll(x => msg.Deleted.Contains(x.Id)); // (Konrad) Handle instances of groups being deleted foreach (var gtw in groups) { gtw.Instances.RemoveAll(x => msg.Deleted.Contains(x)); } } // (Konrad) Handle new instances of GroupType being added var addedTypes = msg.Added.Intersect(new FilteredElementCollector(Doc).OfClass(typeof(GroupType)).ToElementIds()).ToList(); if (addedTypes.Any()) { foreach (var id in addedTypes) { if (!(Doc.GetElement(id) is GroupType gt)) { continue; } var gtw = new GroupTypeWrapper(gt); groups.Add(gtw); } } // (Konrad) Handle new instances of groups being added var added = msg.Added.Intersect(new FilteredElementCollector(Doc).OfClass(typeof(Group)).ToElementIds()).ToList(); if (!added.Any()) { return; } foreach (var id in added) { if (!(Doc.GetElement(id) is Group g)) { continue; } var existing = groups.FirstOrDefault(x => x.Id == g.GroupType.Id); existing?.Instances.Add(id); } }