- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm trying to retrieve empty worksets but the count method of collection of elements in a particular workset is not giving correct results. Not sure where I'm going wrong. Below is my code:
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; Document doc = uiapp.ActiveUIDocument.Document; FilteredElementCollector fec = new FilteredElementCollector(doc); FilteredWorksetCollector fwc = new FilteredWorksetCollector(doc); fwc.OfKind(WorksetKind.UserWorkset); //WorksetTable wt = doc.GetWorksetTable(); try { string msg = ""; int count = 0; Transaction t = new Transaction(doc); t.Start("Check Empty Worksets"); foreach (Workset w in fwc) { ElementWorksetFilter ewf = new ElementWorksetFilter(w.Id, false); ICollection elemIds = fec.WherePasses(ewf).ToElementIds(); int foundElems = elemIds.Count; //int foundElems = TaskDialog.Show("Elements:", w.Name + ": " + foundElems.ToString()); // Workset wSet = wt.GetWorkset(w.UniqueId); if(foundElems == 0) { count++; msg += count.ToString() + ". " + w.Name + "\n"; } } if (count == 0) msg = "None"; TaskDialog.Show("Empty Worksets: ", msg); t.Commit(); t.Dispose(); } catch(Exception e) { TaskDialog.Show("Error", e.ToString()); } return Result.Succeeded; }
Solved! Go to Solution.