WorksharingUtils Class

A static class that contains utility functions related to worksharing.
Inheritance Hierarchy
SystemObject
  Autodesk.Revit.DBWorksharingUtils

Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 25.0.0.0 (25.0.0.0)
Syntax
public class WorksharingUtils : IDisposable

The WorksharingUtils type exposes the following members.

Properties
 NameDescription
Public propertyIsValidObject Specifies whether the .NET object represents a valid Revit entity.
Top
Methods
 NameDescription
Public methodStatic memberCode exampleCheckoutElements(Document, ICollectionElementId) Obtains ownership for the current user of as many specified elements as possible.
Public methodStatic memberCheckoutElements(Document, ISetElementId, TransactWithCentralOptions) Obtains ownership for the current user of as many specified elements as possible.
Public methodStatic memberCode exampleCheckoutWorksets(Document, ICollectionWorksetId) Obtains ownership for the current user of as many specified worksets as possible.
Public methodStatic memberCheckoutWorksets(Document, ISetWorksetId, TransactWithCentralOptions) Obtains ownership for the current user of as many specified worksets as possible.
Public methodStatic memberCreateNewLocal Takes a path to a central model and copies the model into a new local file for the current user.
Public methodDisposeReleases all resources used by the WorksharingUtils
Public methodEqualsDetermines whether the specified object is equal to the current object.
(Inherited from Object)
Public methodStatic memberGetCheckoutStatus(Document, ElementId) Gets the ownership status of an element.
Public methodStatic memberGetCheckoutStatus(Document, ElementId, String) Gets the ownership status and outputs the owner of an element.
Public methodGetHashCodeServes as the default hash function.
(Inherited from Object)
Public methodStatic memberCode exampleGetModelUpdatesStatus Gets the status of a single element in the central model.
Public methodGetTypeGets the Type of the current instance.
(Inherited from Object)
Public methodStatic memberGetUserWorksetInfo Gets information about user worksets in a workshared model file, without fully opening the file.
Public methodStatic memberGetWorksharingTooltipInfo Gets worksharing information about an element to display in an in-canvas tooltip.
Public methodStatic memberRelinquishOwnership Relinquishes ownership by the current user of as many specified elements and worksets as possible, and grants element ownership requested by other users on a first-come, first-served basis.
Public methodToStringReturns a string that represents the current object.
(Inherited from Object)
Top
Remarks

Return values from inquiries about the worksharing status of elements or worksets rely on local caching of information from the central model so it is possible that the information is out of date. 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. To make an immediate attempt to edit elements, use [!:CheckoutElements()] and check the return status, then confirm if the elements are up to date.

In addition, information about the current user may not be reliable while Revit is in the middle of an editing transaction. For example, if you move an unowned wall from an unowned workset to a workset you own, then before you explicitly or Revit automatically checks out the wall for you, GetCheckoutStatus() might erroneously tell you CheckoutStatus.OwnedByCurrentUser because although the official (as seen in central and by other users) owner is no one, locally it looks like you already own it since it belongs to a workset you own.

For operations that interact with central (as opposed to use only cached values), Revit might opportunistically refresh some editing permissions or check the status of editing requests.

Some useful definitions to keep in mind follow:

  • The owner of a workset: the user who has the Workset checked out; this could be nobody (the empty string).
  • The borrower of an element: the user who has explicitly checked out ("borrowed") the Element; this could be nobody.
  • The owner of an element: If element is borrowed (i.e. explicitly checked out), then the element's owner is the borrower, otherwise it is the owner or the workset containing the element.

Example
public void GetElementWorksharingInfo(Document doc, Element elem)
{
    String message = String.Empty;
    message += "Element Id: " + elem.Id;

    // 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, elem.Id);
    message += ("\nUpdate status : " + updateStatus.ToString());

    // Checkout Status of the element
    CheckoutStatus checkoutStatus = WorksharingUtils.GetCheckoutStatus(doc, elem.Id);
    message += ("\nCheckout status : " + checkoutStatus.ToString());

    // Getting WorksharingTooltipInfo of a given element Id
    WorksharingTooltipInfo tooltipInfo = WorksharingUtils.GetWorksharingTooltipInfo(doc, elem.Id);
    message += ("\nCreator : " + tooltipInfo.Creator);
    message += ("\nCurrent Owner : " + tooltipInfo.Owner);
    message += ("\nLast Changed by : " + tooltipInfo.LastChangedBy);

    Autodesk.Revit.UI.TaskDialog.Show("GetElementWorksharingInfo", message);
}
See Also