Reputation: 1
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?
Upvotes: -1
Views: 130
Reputation: 1
You can try this:
ICollection<Workset> GetWorksetsCollection= GetWorksetsCollection(doc);
if (GetWorksetsCollection != null)
{
//Do your stuff here. For each workset.Name add a new ChangeWorkSetComboBox Item.
}
public static ICollection<Workset> GetWorksetsCollection(Document doc)
{
try
{
// Enumerating worksets in a document and getting basic information for each
FilteredWorksetCollector collector = new FilteredWorksetCollector(doc);
// find all user worksets
collector.OfKind(WorksetKind.UserWorkset);
IList<Workset> worksets = collector.ToWorksets();
if (worksets != null)
{
return worksets;
}
else { return null; }
}
catch (Exception e)
{
ErrorLogger.LogError("WorksetsFunctions", "GetWorksetsCollection", e);
return null;
}
}
Retrieves an ICollection
of Workset
class that you can work with like a list, with each one of their properties: Id
, IsDefaultWorkset
, IsEditable
, IsOpen
, IsVisibleByDefault
, Kind
, Name
, Owner
, UniqueId
.
Upvotes: 0
Reputation: 1
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);
Upvotes: 0