Skip to content

adc

Wrapping Autodesk Desktop Connector API.

Attributes

mlogger = logger.get_logger(__name__) module-attribute

ADC_NAME = 'Autodesk Desktop Connector' module-attribute

ADC_SHORTNAME = 'ADC' module-attribute

ADC_DRIVE_SCHEMA = '{drive_name}://' module-attribute

ADC_DEFAULT_INSTALL_PATH = 'C:\\Program Files\\Autodesk\\Desktop Connector' module-attribute

ADC_API_DLL = 'Autodesk.DesktopConnector.API.dll' module-attribute

ADC_API_DLL_PATH = op.join(ADC_DEFAULT_INSTALL_PATH, ADC_API_DLL) module-attribute

Classes

Functions

is_available()

Check if ADC service is available.

Source code in pyrevitlib/pyrevit/interop/adc.py
def is_available():
    """Check if ADC service is available."""
    try:
        _get_adc().Discover()
        return True
    except Exception:
        return False

get_drive_paths()

Get dict of local paths for ADC drives.

Source code in pyrevitlib/pyrevit/interop/adc.py
def get_drive_paths():
    """Get dict of local paths for ADC drives."""
    adc = _get_adc()
    return {x.Name: x.WorkspaceLocation for x in _get_drives_info(adc)}

get_local_path(path)

Convert ADC BIM360 drive path to local path.

Source code in pyrevitlib/pyrevit/interop/adc.py
def get_local_path(path):
    """Convert ADC BIM360 drive path to local path."""
    adc = _get_adc()
    drv_info = _get_drive_from_path(adc, path)
    if drv_info:
        return _drive_path_to_local_path(drv_info, path)

lock_file(path)

Lock given file.

Source code in pyrevitlib/pyrevit/interop/adc.py
def lock_file(path):
    """Lock given file."""
    adc = _get_adc()
    item = _get_item(adc, path)
    adc.LockFile(item.Id)

is_locked(path)

Check if file is locked.

Source code in pyrevitlib/pyrevit/interop/adc.py
def is_locked(path):
    """Check if file is locked."""
    adc = _get_adc()
    item = _get_item(adc, path)
    lock_status = _get_item_lockstatus(adc, item)
    return lock_status.State == API.LockState.LockedByOther, \
        lock_status.LockOwner

unlock_file(path)

Unlock given file.

Source code in pyrevitlib/pyrevit/interop/adc.py
def unlock_file(path):
    """Unlock given file."""
    adc = _get_adc()
    item = _get_item(adc, path)
    adc.UnlockFile(item.Id)

is_synced(path)

Check if file is synchronized.

Source code in pyrevitlib/pyrevit/interop/adc.py
def is_synced(path):
    """Check if file is synchronized."""
    adc = _get_adc()
    item = _get_item(adc, path)
    drive = _get_item_drive(adc, item)
    # ADC uses translated property names so
    # check status property by its type "LocalState"
    # see https://github.com/pyrevitlabs/pyRevit/issues/1152
    # ADC version 15 changed property_id_value
    # see https://github.com/pyrevitlabs/pyRevit/issues/1371
    prop_val = _get_item_property_id_value(adc, drive, item, 'DesktopConnector.Core.LocalState')
    if prop_val is None:
        # version older than ADC 15
        prop_val = _get_item_property_id_value(adc, drive, item, 'LocalState')
    # possible values, 'Cached', 'Stale', 'Modified'
    # .Value is not translated
    return prop_val.Value == 'Cached'or prop_val.Value == 'Synced'

sync_file(path, force=False)

Force ADC to sync given file to latest version.

Source code in pyrevitlib/pyrevit/interop/adc.py
def sync_file(path, force=False):
    """Force ADC to sync given file to latest version."""
    if not force and is_synced(path):
        return
    adc = _get_adc()
    item = _get_item(adc, path)
    # make sure path is local
    local_path = _ensure_local_path(adc, path)
    for proc_id in _get_all_processids():
        adc.FileClosedWithinRunningProcess(proc_id, local_path)
    adc.SyncFiles([item.Id])