Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 38 additions & 5 deletions pyrevitlib/pyrevit/interop/adc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# coding=utf-8
"""Wrapping Autodesk Desktop Connector API."""

import os
import os.path as op
from pyrevit import PyRevitException
from pyrevit.framework import clr, Process
Expand Down Expand Up @@ -73,9 +73,9 @@ def _get_drive_from_local_path(adc, local_path):
def _drive_path_to_local_path(drv_info, path):
drive_schema = ADC_DRIVE_SCHEMA.format(drive_name=drv_info.Name)
return op.normpath(
op.join(drv_info.WorkspaceLocation, path.replace(drive_schema, ""))
)

op.join(drv_info.WorkspaceLocation,
path.replace(drive_schema, ""))
)

def _ensure_local_path(adc, path):
drv_info = _get_drive_from_path(adc, path)
Expand Down Expand Up @@ -126,6 +126,21 @@ def _get_item_property_id_value(adc, drive, item, prop_id):
return res.Values[0]


def _get_organization_name(drv_info, path):
"""Get the organization name from the ADC path."""
drive_schema = ADC_DRIVE_SCHEMA.format(drive_name=drv_info.Name)
parts = path.replace(drive_schema, "").split('/')
file_name = parts[1]
drv_local_path = op.normpath(drv_info.WorkspaceLocation)
subdirs = os.walk(drv_local_path)
for root, dirs, files in subdirs:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Critical Performance Issue: os.walk() traverses the entire ADC workspace directory tree which can be extremely slow for large ACC/BIM360 projects with many files and folders. This will cause significant delays when called.

The organization name should be extractable from the ADC API or the path structure itself without filesystem traversal. Consider using adc.GetDrives() properties or parsing the workspace location structure directly.

If the org name is consistently in a specific directory level under WorkspaceLocation, use direct path parsing instead:

def _get_organization_name(drv_info, path):
    """Get the organization name from the ADC path."""
    drive_schema = ADC_DRIVE_SCHEMA.format(drive_name=drv_info.Name)
    # Get relative path from drive schema
    rel_path = path.replace(drive_schema, "").lstrip('/')
    # Parse to get project/folder structure
    parts = rel_path.split('/')
    if len(parts) < 2:
        return None
    
    # Build expected local path based on known ADC structure
    # This assumes organization name is first level dir in workspace
    drv_local_path = op.normpath(drv_info.WorkspaceLocation)
    subdirs = [d for d in os.listdir(drv_local_path) 
               if op.isdir(op.join(drv_local_path, d))]
    # Return first matching org directory
    if subdirs:
        return subdirs[0]
    return None
actions

Feedback: Rate this comment to help me improve future code reviews:

  • 👍 Good - Helpful and accurate
  • 👎 Poor - Wrong, unclear, or unhelpful
  • Skip if you don't have any strong opinions either way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unfortunately, there isn't a known way to parse the organization name through the API.
also there adc path extracted from the file, shows Accdocs://ProjectName/FileName.rvt. there is no way to quickly acquire organization name by deconstructing the path.
so far my only way to access is to look into the subfolders to find the target file and report the organization folder that contains the file

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sanzoghenzo any Idea here?

for f in files:
if f == file_name:
file_path = op.join(root, f)
org_name = file_path.replace(drv_local_path, "").split(os.sep)[1]
return org_name


def is_available():
"""Check if ADC service is available."""
try:
Expand All @@ -142,13 +157,31 @@ def get_drive_paths():


def get_local_path(path):
"""Convert ADC BIM360 drive path to local path."""
"""Get the Local Path of the model on ADC."""
adc = _get_adc()
drv_info = _get_drive_from_path(adc, path)
if drv_info:
return _drive_path_to_local_path(drv_info, path)


def get_model_path(path):
"""Get the Model Path of the model on ADC."""
adc = _get_adc()
drv_info = _get_drive_from_path(adc, path)
org_name = _get_organization_name(drv_info, path)
if org_name:
if drv_info:
drv_schema = ADC_DRIVE_SCHEMA.format(drive_name=drv_info.Name)
rel_path = path.replace(drv_schema, "")
return os.path.normpath(os.path.join(
drv_info.WorkspaceLocation,
org_name,
rel_path
)
)
return None


def lock_file(path):
"""Lock given file."""
adc = _get_adc()
Expand Down