Namespace:
Autodesk.Revit.DB
Assembly:
RevitAPI
(in RevitAPI.dll) Version: 17.0.0.0 (17.0.484.0)
Since:
2012
Syntax
C# |
---|
|
Visual Basic |
---|
|
Visual C++ |
---|
|
Parameters
- document
-
Type:
Autodesk.Revit.DB
Document
The document containing the element.
- elementId
-
Type:
Autodesk.Revit.DB
ElementId
The id of the element.
Return Value
The status of the element in the local session versus the central model.Remarks
This method returns a locally cached value which may not be up to date with the current state of the element in the central. Because of this, the return value is suitable for reporting to an interactive user (e.g. via a mechanism similar to Worksharing display mode), but cannot be considered a reliable indication of whether the element can be immediately edited by the application. Also, the return value may not be dependable in the middle of a local transaction. See the remarks on WorksharingUtils for more details.
For performance reasons, the model is not validated to be workshared, and the element id is also not validated; the element will not be expanded.
Examples
public static bool AttemptToCheckoutInAdvance(Element element)
{
Document doc = element.Document;
String categoryName = element.Category.Name;
// Checkout attempt
ICollection<ElementId> checkedOutIds = WorksharingUtils.CheckoutElements(doc, new ElementId[] { element.Id });
// Confirm checkout
bool checkedOutSuccessfully = checkedOutIds.Contains(element.Id);
if (!checkedOutSuccessfully)
{
TaskDialog.Show("Element is not checked out", "Cannot edit the " + categoryName + " element - " +
"it was not checked out successfully and may be checked out to another.");
return false;
}
// If element is updated in central or deleted in central, it is not editable
ModelUpdatesStatus updatesStatus = WorksharingUtils.GetModelUpdatesStatus(doc, element.Id);
if (updatesStatus == ModelUpdatesStatus.DeletedInCentral || updatesStatus == ModelUpdatesStatus.UpdatedInCentral)
{
TaskDialog.Show("Element is not up to date", "Cannot edit the " + categoryName + " element - " +
"it is not up to date with central, but it is checked out.");
return false;
}
return true;
}
Public Shared Function AttemptToCheckoutInAdvance(element As Element) As Boolean
Dim doc As Document = element.Document
Dim categoryName As [String] = element.Category.Name
' Checkout attempt
Dim checkedOutIds As ICollection(Of ElementId) = WorksharingUtils.CheckoutElements(doc, New ElementId() {element.Id})
' Confirm checkout
Dim checkedOutSuccessfully As Boolean = checkedOutIds.Contains(element.Id)
If Not checkedOutSuccessfully Then
TaskDialog.Show("Element is not checked out", "Cannot edit the " + categoryName + " element - " + "it was not checked out successfully and may be checked out to another.")
Return False
End If
' If element is updated in central or deleted in central, it is not editable
Dim updatesStatus As ModelUpdatesStatus = WorksharingUtils.GetModelUpdatesStatus(doc, element.Id)
If updatesStatus = ModelUpdatesStatus.DeletedInCentral OrElse updatesStatus = ModelUpdatesStatus.UpdatedInCentral Then
TaskDialog.Show("Element is not up to date", "Cannot edit the " + categoryName + " element - " + "it is not up to date with central, but it is checked out.")
Return False
End If
Return True
End Function
Exceptions
Exception | Condition |
---|---|
Autodesk.Revit.Exceptions ArgumentNullException | A non-optional argument was NULL |