Worksets are a way to divide a set of elements in the Revit document into subsets for worksharing. There may be one or many worksets in a document.
The document contains a WorksetTable which is a table containing references to all the worksets contained in that document. There is one WorksetTable for each document. There will be at least one default workset in the table, even if worksharing has not been enabled in the document. The Document.IsWorkshared property can be used to determine if worksharing has been enabled in the document.
Code Region: Get Active Workset |
public Workset GetActiveWorkset(Document doc) { // Get the workset table from the document WorksetTable worksetTable = doc.GetWorksetTable(); // Get the Id of the active workset WorksetId activeId = worksetTable.GetActiveWorksetId(); // Find the workset with that Id Workset workset = worksetTable.GetWorkset(activeId); return workset; } |
Code Region: Filtering Worksets |
public void GetWorksetsInfo(Document doc) { String message = String.Empty; // 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(); // get information for each workset int count = 3; // show info for 3 worksets only foreach (Workset workset in worksets) { message += "Workset : " + workset.Name; message += "\nUnique Id : " + workset.UniqueId; message += "\nOwner : " + workset.Owner; message += "\nKind : " + workset.Kind; message += "\nIs default : " + workset.IsDefaultWorkset; message += "\nIs editable : " + workset.IsEditable; message += "\nIs open : " + workset.IsOpen; message += "\nIs visible by default : " + workset.IsVisibleByDefault; TaskDialog.Show("GetWorksetsInfo", message); if (0 == --count) break; } } |
As shown in the previous example, the Workset class provides many properties to get information about a given workset, such as the owner and whether or not the workset is editable.