public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication app = commandData.Application; UIDocument uidoc = app.ActiveUIDocument; Document doc = uidoc.Document; // Get all Group Types of Model Family: FilteredElementCollector modelGroupTypes = new FilteredElementCollector(doc); modelGroupTypes.OfClass(typeof(GroupType)); modelGroupTypes.OfCategory(BuiltInCategory.OST_IOSModelGroups); if (0 == modelGroupTypes.Count()) { message = "No model group types found in model."; return(Result.Failed); } FilteredElementCollector groups; groups = new FilteredElementCollector(doc); groups.OfClass(typeof(Group)); foreach (Group g in groups) { // Offer simple message box to swap the type // (one-by-one, stop if user confirms the change) foreach (GroupType gt in modelGroupTypes) { string msg = "Swap OLD Type=" + g.GroupType.Name + " with NEW Type=" + gt.Name + " for Group Id=" + g.Id.IntegerValue.ToString() + "?"; TaskDialogResult r = LabUtils.QuestionCancelMsg(msg); switch (r) { case TaskDialogResult.Yes: g.GroupType = gt; LabUtils.InfoMsg("Group type successfully swapped."); return(Result.Succeeded); case TaskDialogResult.Cancel: LabUtils.InfoMsg("Command cancelled."); return(Result.Cancelled); // else continue... } } } /* * // * // cannot modify group members after creation: * // * Element e = null; * ElementArray els = new ElementArray(); * els.Append( e ); * Group g = new Group(); * g.Members = els; // Property or indexer 'Autodesk.Revit.Elements.Group.Members' cannot be assigned to -- it is read only * Element e2 = null; * els.Append( e2 ); * g.Members = els; */ return(Result.Succeeded); }