Skip to content

Commit 866f1a1

Browse files
authored
Switch for .net core Desktop connector API
1 parent 994705a commit 866f1a1

File tree

1 file changed

+21
-16
lines changed
  • pyrevitlib/pyrevit/interop

1 file changed

+21
-16
lines changed

pyrevitlib/pyrevit/interop/adc.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,38 @@
1+
# coding=utf-8
12
"""Wrapping Autodesk Desktop Connector API."""
2-
#pylint: disable=bare-except,broad-except
3+
34
import os.path as op
45
from pyrevit import PyRevitException
56
from pyrevit.framework import clr, Process
67
from pyrevit.coreutils import logger
78

9+
from pyrevit import HOST_APP
810

911
mlogger = logger.get_logger(__name__)
1012

11-
1213
ADC_NAME = "Autodesk Desktop Connector"
1314
ADC_SHORTNAME = "ADC"
14-
ADC_DRIVE_SCHEMA = '{drive_name}://'
15+
ADC_DRIVE_SCHEMA = "{drive_name}://"
16+
17+
if HOST_APP.is_newer_than("2024"): # .net8 core version of the desktop connector API
18+
ADC_DEFAULT_INSTALL_PATH = (
19+
r"C:\Program Files\Autodesk\Desktop Connector\FOS\AddInProcess\Civil3DOE"
20+
)
21+
else: # .net framework version of the desktop connector API
22+
ADC_DEFAULT_INSTALL_PATH = r"C:\Program Files\Autodesk\Desktop Connector"
1523

16-
ADC_DEFAULT_INSTALL_PATH = \
17-
r'C:\Program Files\Autodesk\Desktop Connector'
18-
ADC_API_DLL = 'Autodesk.DesktopConnector.API.dll'
24+
ADC_API_DLL = "Autodesk.DesktopConnector.API.dll"
1925
ADC_API_DLL_PATH = op.join(ADC_DEFAULT_INSTALL_PATH, ADC_API_DLL)
2026

2127
API = None
2228
if op.exists(ADC_API_DLL_PATH):
2329
try:
2430
clr.AddReferenceToFileAndPath(ADC_API_DLL_PATH)
25-
import Autodesk.DesktopConnector.API as API #pylint: disable=import-error
31+
import Autodesk.DesktopConnector.API as API # pylint: disable=import-error
2632
except:
2733
pass
2834

35+
2936
def _ensure_api():
3037
if not API:
3138
raise PyRevitException("{} is not loaded".format(ADC_NAME))
@@ -66,10 +73,7 @@ def _get_drive_from_local_path(adc, local_path):
6673
def _drive_path_to_local_path(drv_info, path):
6774
drive_schema = ADC_DRIVE_SCHEMA.format(drive_name=drv_info.Name)
6875
return op.normpath(
69-
op.join(
70-
drv_info.WorkspaceLocation,
71-
path.replace(drive_schema, '')
72-
)
76+
op.join(drv_info.WorkspaceLocation, path.replace(drive_schema, ""))
7377
)
7478

7579

@@ -157,8 +161,7 @@ def is_locked(path):
157161
adc = _get_adc()
158162
item = _get_item(adc, path)
159163
lock_status = _get_item_lockstatus(adc, item)
160-
return lock_status.State == API.LockState.LockedByOther, \
161-
lock_status.LockOwner
164+
return lock_status.State == API.LockState.LockedByOther, lock_status.LockOwner
162165

163166

164167
def unlock_file(path):
@@ -178,13 +181,15 @@ def is_synced(path):
178181
# see https://github.com/pyrevitlabs/pyRevit/issues/1152
179182
# ADC version 15 changed property_id_value
180183
# see https://github.com/pyrevitlabs/pyRevit/issues/1371
181-
prop_val = _get_item_property_id_value(adc, drive, item, 'DesktopConnector.Core.LocalState')
184+
prop_val = _get_item_property_id_value(
185+
adc, drive, item, "DesktopConnector.Core.LocalState"
186+
)
182187
if prop_val is None:
183188
# version older than ADC 15
184-
prop_val = _get_item_property_id_value(adc, drive, item, 'LocalState')
189+
prop_val = _get_item_property_id_value(adc, drive, item, "LocalState")
185190
# possible values, 'Cached', 'Stale', 'Modified'
186191
# .Value is not translated
187-
return prop_val.Value == 'Cached'or prop_val.Value == 'Synced'
192+
return prop_val.Value == "Cached" or prop_val.Value == "Synced"
188193

189194

190195
def sync_file(path, force=False):

0 commit comments

Comments
 (0)