WorksharingUtils.CheckoutElements(Document, ICollection.ElementId.)
Obtains ownership for the current user of as many specified elements as possible.
Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 25.0.0.0 (25.0.0.0)
Syntax
public static ICollection<ElementId> CheckoutElements( Document document, ICollection<ElementId> elementsToCheckout)Parameters
document Document
The document containing the elements.
elementsToCheckoutICollection. ElementId.
The ids of the elements to attempt to check out.
Return Value
ICollection. ElementId.
The ids of all specified elements that are now owned (but possibly out of date), including all that were owned prior to the function call.
Exceptions
Exception
Condition
ArgumentException
document is not a workshared document. -or- document is not a primary document, it is a linked document. -or- One or more elements in elementsToCheckout do not exist in the document. -or- Saving is not allowed in the current application mode.
ArgumentNullException
A non-optional argument was null
CentralFileCommunicationException
Editing permissions for the file-based central model could not be accessed for write, e.g. the network is down, central is missing, or central is read-only.
CentralModelAccessDeniedException
Access to the central model was denied. A possible reason is because the model was under maintenance.
CentralModelContentionException
Editing permissions for the central model are locked and the last attempt to lock was canceled. -or- The central model is being accessed by another client.
CentralModelException
An error has occurred while checking out worksets or elements. -or- The central model is overwritten by other user. -or- The central model is missing. -or- An internal error happened on the central model, please contact the server administrator.
CentralModelVersionArchivedException
Last central version merged into the local model has been archived in the central model. This exception could only be thrown from cloud models.
RevitServerCommunicationException
The server-based central model could not be accessed because of a network communication error.
RevitServerInternalException
An internal error happened on the server, please contact the server administrator.
Remarks
For best performance, checkout all elements in one big call, rather than many small calls.
Revit may check out additional elements that are needed to check out the elements you requested. For example, if you request an element that is in a group, Revit will check out the entire group.
When there comes a contention error when locking the central model, this API would wait and retry endlessly until getting the lock of the central model.
Example
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);}