Element Ownership

Element Ownership

The WorksharingUtils class can be used to modify element and workset ownership. The CheckoutElements() method obtains ownership for the current user of as many specified elements as possible, while the CheckoutWorksets() method does the same for worksets. The RelinquishOwnership() method relinquishes elements and worksets owned by the current user based on the specified RelinquishOptions.

For best performance, checkout all elements or worksets and relinquish items in one big call, rather than many small calls.

Note: When checking out an element, Revit may check out additional elements that are needed to make the requested element editable. For example, if an element is in a group, Revit will checkout the entire group.

In the following example, all rooms in the document are checked out to the current user.

Code Region: Checkout elements

void CheckoutAllRooms(Document doc)
{
    FilteredElementCollector collector = new FilteredElementCollector(doc);
    ICollection<ElementId> rooms = collector.WherePasses(new RoomFilter()).ToElementIds();
    ICollection<ElementId> checkoutelements = WorksharingUtils.CheckoutElements(doc, rooms);
    TaskDialog.Show("Checked out elements", "Number of elements checked out: " + checkoutelements.Count);
}

The next example demonstrates checking out all the view worksets.

Code Region: Checkout worksets

void CheckoutAllViewWorksets(Document doc)
{
    FilteredWorksetCollector collector = new FilteredWorksetCollector(doc);

    // find all view worksets
    collector.OfKind(WorksetKind.ViewWorkset);
    ICollection<WorksetId> viewworksets = collector.ToWorksetIds();
    ICollection<WorksetId> checkoutworksets = WorksharingUtils.CheckoutWorksets(doc, viewworksets);
    TaskDialog.Show("Checked out worksets", "Number of worksets checked out: " + checkoutworksets.Count);
}