-
-
Notifications
You must be signed in to change notification settings - Fork 393
Update ADC to enable users to aquire paths for the active model #2843
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
9d7a2c6
49df4b3
3f03af6
8f660a2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
|
@@ -126,6 +126,23 @@ 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("/") | ||
if len(parts) < 2: | ||
return None | ||
file_name = parts[1] | ||
drv_local_path = op.normpath(drv_info.WorkspaceLocation) | ||
subdirs = os.walk(drv_local_path) | ||
for root, dirs, files in subdirs: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical Performance Issue: The organization name should be extractable from the ADC API or the path structure itself without filesystem traversal. Consider using If the org name is consistently in a specific directory level under 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 actionsFeedback: Rate this comment to help me improve future code reviews:
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: | ||
|
@@ -142,13 +159,28 @@ 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) | ||
if drv_info: | ||
org_name = _get_organization_name(drv_info, path) | ||
if org_name: | ||
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() | ||
|
Uh oh!
There was an error while loading. Please reload this page.