Each element in the document must belong to one and only one workset. Each element has a WorksetId which identifies the unique workset to which it belongs. Additionally, given a WorksetId, it is possible to get all of the elements in the document belonging to that Workset using the ElementWorksetFilter as shown below.
Code Region: ElementWorksetFilter |
public void WorksetElements(Document doc, Workset workset) { // filter all elements that belong to the given workset FilteredElementCollector elementCollector = new FilteredElementCollector(doc); ElementWorksetFilter elementWorksetFilter = new ElementWorksetFilter(workset.Id, false); ICollection<Element> worksetElemsfounds = elementCollector.WherePasses(elementWorksetFilter).ToElements(); // how many elements were found? int elementsCount = worksetElemsfounds.Count; String message = "Element count : " + elementsCount; // Get name and/or Id of the elements that pass the given filter and show a few of them int count = 5; // show info for 5 elements only foreach (Element ele in worksetElemsfounds) { if (null != ele) { message += "\nElementId : " + ele.Id; message += ", Element Name : " + ele.Name; if (0 == --count) break; } } Autodesk.Revit.UI.TaskDialog.Show("ElementsOfWorkset", message); } |
Worksharing information such as the current owner and checkout status of an element can be obtained using the WorksharingUtils class. It is a static class that contains utility functions related to worksharing.
Code Region: WorksharingUtils |
public void GetElementWorksharingInfo(Document doc, ElementId elemId) { String message = String.Empty; message += "Element Id: " + elemId; Element elem = doc.GetElement(elemId); if(null == elem) { message += "Element does not exist"; return; } // The workset the element belongs to WorksetId worksetId = elem.WorksetId; message += ("\nWorkset Id : " + worksetId.ToString()); // Model Updates Status of the element ModelUpdatesStatus updateStatus = WorksharingUtils.GetModelUpdatesStatus(doc, elemId); message += ("\nUpdate status : " + updateStatus.ToString()); // Checkout Status of the element CheckoutStatus checkoutStatus = WorksharingUtils.GetCheckoutStatus(doc, elemId); message += ("\nCheckout status : " + checkoutStatus.ToString()); // Getting WorksharingTooltipInfo of a given element Id WorksharingTooltipInfo tooltipInfo = WorksharingUtils.GetWorksharingTooltipInfo(doc, elemId); message += ("\nCreator : " + tooltipInfo.Creator); message += ("\nCurrent Owner : " + tooltipInfo.Owner); message += ("\nLast Changed by : " + tooltipInfo.LastChangedBy); Autodesk.Revit.UI.TaskDialog.Show("GetElementWorksharingInfo", message); } |