Skip to content

bim360

BIM360-related utilities.

Attributes

mlogger = get_logger(__name__) module-attribute

COLLAB_CACHE_PATH_FORMAT = '%LOCALAPPDATA%/Autodesk/Revit/Autodesk Revit {version}/CollaborationCache' module-attribute

Classes

CollabCacheModel(model_path)

Bases: object

Collaboration cache for a Revit project.

Source code in pyrevitlib/pyrevit/revit/bim360.py
def __init__(self, model_path):
    self.model_path = model_path
    self.model_dir = op.dirname(model_path)
    self.model_name_ex = op.basename(model_path)
    self.model_name = op.splitext(self.model_name_ex)[0]

    self.central_cache_model_path = \
        op.join(self.model_dir, 'CentralCache', self.model_name_ex)
    self.model_backup_path = \
        op.join(self.model_dir, '{}_backup'.format(self.model_name))

    try:
        finfo = files.get_file_info(self.model_path)
        self.product = finfo.RevitProduct.Name
        self.project = op.basename(finfo.CentralModelPath)
    except Exception:
        self.product = "?"
        self.project = self.model_name_ex

Attributes

model_path = model_path instance-attribute
model_dir = op.dirname(model_path) instance-attribute
model_name_ex = op.basename(model_path) instance-attribute
model_name = op.splitext(self.model_name_ex)[0] instance-attribute
central_cache_model_path = op.join(self.model_dir, 'CentralCache', self.model_name_ex) instance-attribute
model_backup_path = op.join(self.model_dir, '{}_backup'.format(self.model_name)) instance-attribute
product = finfo.RevitProduct.Name instance-attribute
project = op.basename(finfo.CentralModelPath) instance-attribute

CollabCache(cache_path)

Bases: object

Collaboration cache instance containing multiple projects.

Source code in pyrevitlib/pyrevit/revit/bim360.py
def __init__(self, cache_path):
    self.cache_path = cache_path
    self.cache_id = op.basename(cache_path)
    self.cache_models = []
    for entry in os.listdir(self.cache_path):
        if entry.lower().endswith('.rvt'):
            self.cache_models.append(
                CollabCacheModel(op.join(cache_path, entry))
                )

    self.cache_linked_models = []
    lmodels_path = op.join(self.cache_path, 'LinkedModels')
    if op.exists(lmodels_path):
        for entry in os.listdir(lmodels_path):
            if entry.lower().endswith('.rvt'):
                self.cache_linked_models.append(
                    CollabCacheModel(op.join(lmodels_path, entry))
                    )

Attributes

cache_path = cache_path instance-attribute
cache_id = op.basename(cache_path) instance-attribute
cache_models = [] instance-attribute
cache_linked_models = [] instance-attribute

Functions

get_collab_caches()

Get a list of project caches stored under collaboration cache.

Source code in pyrevitlib/pyrevit/revit/bim360.py
def get_collab_caches():
    """Get a list of project caches stored under collaboration cache."""
    collab_root = op.normpath(op.expandvars(
        COLLAB_CACHE_PATH_FORMAT.format(version=HOST_APP.version)
    ))
    mlogger.debug('cache root: %s', collab_root)
    collab_caches = []
    if op.exists(collab_root):
        for cache_root in os.listdir(collab_root):
            cache_root_path = op.join(collab_root, cache_root)
            for cache_inst in os.listdir(cache_root_path):
                cache_inst_path = op.join(cache_root_path, cache_inst)
                mlogger.debug('cache inst: %s', cache_inst_path)
                if op.isdir(cache_inst_path):
                    collab_caches.append(
                        CollabCache(cache_inst_path)
                        )
    return collab_caches

clear_model_cache(collab_cache_model)

Clear caches for given collaboration cache model.

Parameters:

Name Type Description Default
collab_cache_model CollabCacheModel

cache model to clear

required
Source code in pyrevitlib/pyrevit/revit/bim360.py
def clear_model_cache(collab_cache_model):
    """Clear caches for given collaboration cache model.

    Args:
        collab_cache_model (bim360.CollabCacheModel): cache model to clear
    """
    if isinstance(collab_cache_model, CollabCacheModel):
        cm = collab_cache_model
        mlogger.debug('Deleting %s', cm.model_path)
        try:
            if op.exists(cm.model_path):
                os.remove(cm.model_path)
        except Exception as cmdel_ex:
            mlogger.error(
                'Error deleting model cache @ %s | %s',
                cm.model_path,
                str(cmdel_ex)
                )

        mlogger.debug('Deleting %s', cm.model_backup_path)
        try:
            if op.exists(cm.model_backup_path):
                coreutils.fully_remove_dir(cm.model_backup_path)
        except Exception as cmbdel_ex:
            mlogger.error(
                'Error deleting model backup @ %s | %s',
                cm.model_backup_path,
                str(cmbdel_ex)
                )

        mlogger.debug('Deleting %s', cm.central_cache_model_path)
        try:
            if op.exists(cm.central_cache_model_path):
                os.remove(cm.central_cache_model_path)
        except Exception as ccmdel_ex:
            mlogger.error(
                'Error deleting central model cache @ %s | %s',
                cm.central_cache_model_path,
                str(ccmdel_ex)
                )