Skip to content

Conversation

tay0thman
Copy link
Contributor

@tay0thman tay0thman commented Oct 3, 2025

Added 2 functions to:
1- Get the organization name (ACC Hub).
2- Build a local path for the active model.

Description

The ADC library enables users to acquire local paths for files linked to the model, but not the active doc itself, this PR will attempt at solving it.


Checklist

Before submitting your pull request, ensure the following requirements are met:

  • Code follows the PEP 8 style guide.
  • Code has been formatted with Black using the command:
    pipenv run black {source_file_or_directory}
  • Changes are tested and verified to work as expected.

Added 2 functions to:
1- Get the organization name (ACC Hub).
2- Build a local path for the active model.
Copy link
Contributor

@devloai devloai bot left a comment

Choose a reason for hiding this comment

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

PR Summary:

This PR adds two functions to the ADC library:

  • _get_organization_name(): Extracts the ACC Hub organization name from ADC paths
  • get_model_path(): Builds a local path for the active model including the organization folder

The goal is to enable users to acquire local paths for the active document itself, not just linked files.

Review Summary:

Found 4 critical bugs that need fixing before merge:

  1. Severe performance issue using os.walk() to traverse entire workspace
  2. IndexError risk with unchecked array access
  3. Logic error calling function before validating required parameter
  4. Reversed conditional logic with nested if-statements

Also found Black formatting violations (as noted in PR checklist requirements).

The core idea is valuable but the implementation has several bugs that will cause crashes and poor performance in production.

Follow-up suggestions:

  • @devloai fix the identified issues
  • @devloai add defensive error handling and validation

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?

@tay0thman
Copy link
Contributor Author

@jmcouffin
I'm voiding this PR, as I don't want to give people an example of inefficient code, I will incorporate these functions in a separate lib so we can be assured to keep pyrevit libraries clean.
Once Autodesk give us an update on the ADC API , I may visit this topic again.

@tay0thman tay0thman closed this Oct 6, 2025
@jmcouffin
Copy link
Contributor

Noted.
Thanks Tay

@jmcouffin jmcouffin deleted the tay0thman-patch-3 branch October 6, 2025 21:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants