CheckoutElements Method (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: 17.0.0.0 (17.0.484.0)
Since: 2014

Syntax

C#
public static ICollection<ElementId> CheckoutElements(
	Document document,
	ICollection<ElementId> elementsToCheckout
)
Visual Basic
Public Shared Function CheckoutElements ( _
	document As Document, _
	elementsToCheckout As ICollection(Of ElementId) _
) As ICollection(Of ElementId)
Visual C++
public:
static ICollection<ElementId^>^ CheckoutElements(
	Document^ document, 
	ICollection<ElementId^>^ elementsToCheckout
)

Parameters

document
Type: Autodesk.Revit.DB Document
The document containing the elements.
elementsToCheckout
Type: System.Collections.Generic ICollection ElementId
The ids of the elements to attempt to check out.

Return Value

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.

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.

Examples

Copy C#
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);
}
Copy VB.NET
Private Sub CheckoutAllRooms(doc As Document)
    Dim collector As New FilteredElementCollector(doc)
    Dim rooms As ICollection(Of ElementId) = collector.WherePasses(New RoomFilter()).ToElementIds()
    Dim checkoutelements As ICollection(Of ElementId) = WorksharingUtils.CheckoutElements(doc, rooms)
    TaskDialog.Show("Checked out elements", "Number of elements checked out: " + checkoutelements.Count)
End Sub

Exceptions

Exception Condition
Autodesk.Revit.Exceptions 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.
Autodesk.Revit.Exceptions ArgumentNullException A non-optional argument was NULL
Autodesk.Revit.Exceptions 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.
Autodesk.Revit.Exceptions CentralModelAccessDeniedException Access to the central model was denied. A possible reason is because the model was under maintenance.
Autodesk.Revit.Exceptions 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.
Autodesk.Revit.Exceptions 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.
Autodesk.Revit.Exceptions RevitServerCommunicationException The server-based central model could not be accessed because of a network communication error.
Autodesk.Revit.Exceptions RevitServerInternalException An internal error happened on the server, please contact the server administrator.

See Also