I want to display all the Worksets in a combobox. I looked at the revitapidocs website, there is a GetWorksetIds() method there. But for some reason it doesn't work in my code.
WorksetTable worksetTable = _doc.GetWorksetTable();
newChangeWorkSetComboBox.Items.Clear();
IList<WorksetId> worksetIds = worksetTable.GetWorksetIds();
foreach (WorksetId worksetId in worksetIds)
{
Workset workset = worksetTable.GetWorkset(worksetId);
if (workset != null && !string.IsNullOrEmpty(workset.Name))
{
newChangeWorkSetComboBox.Items.Add(workset.Name);
}
}
StackPanel_ChangeWorkSets.Children.Add(newChangeWorkSetComboBox);
The following error appears:
Error (active) CS1061 "WorksetTable" does not contain the definition of "GetWorksetIds", and an available extension method "GetWorksetIds" could not be found that accepts the type "WorksetTable" as the first argument (perhaps the using directive or assembly reference was omitted).
How can this method be replaced in the revit 2023?
Turns out that there is a FilteredWorksetCollector
that does an excellent job with this task.
var worksets = new FilteredWorksetCollector(_doc)
.OfKind(WorksetKind.UserWorkset)
.ToWorksets();
newChangeWorkSetComboBox.Items.Clear();
foreach (Workset workset in worksets)
{
newChangeWorkSetComboBox.Items.Add(workset.Name);
}
StackPanel_ChangeWorkSets.Children.Add(newChangeWorkSetComboBox);