You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Revit API或其他方法获取Autodesk Docs对应本地文件夹路径

解决方案:C#通过Revit API获取Autodesk Docs对应本地磁盘路径

你之前调用Directory.GetParent无法生效的原因是Autodesk Docs://属于Desktop Connector定义的虚拟协议路径,不是标准的本地文件系统路径,System.IO原生方法无法直接识别解析。以下是两种可行实现方案:

方案1:使用Revit官方原生API(推荐,适用Revit 2021及以上版本)

Revit 2021版本开始API提供了ModelPathUtils.ConvertModelPathToUserVisiblePath工具方法,专门用于将云模型路径转换为用户本地可见的文件系统路径,使用示例如下:

using Autodesk.Revit.DB;

// doc为当前已打开的云模型Document实例
ModelPath cloudModelPath = doc.GetModelPath();
string localFullPath = ModelPathUtils.ConvertModelPathToUserVisiblePath(cloudModelPath);

调用后直接返回格式为C:/Users/用户名/ACCDocs/xxx/xxx.rvt的本地路径。

方案2:读取Desktop Connector注册表映射(兼容Revit 2020及更低版本)

如果需要兼容更早的Revit版本,可以通过读取Desktop Connector的注册表映射规则,手动拼接本地路径:

  1. 从doc.PathName返回的虚拟路径中拆分出项目ID和文件相对路径
  2. 读取注册表中项目ID对应的本地同步根目录
  3. 拼接根目录与相对路径得到完整本地路径
    实现代码示例:
using Microsoft.Win32;
using System.IO;
using Autodesk.Revit.DB;

public string GetAccLocalPath(Document doc)
{
    string cloudVirtualPath = doc.PathName;
    if (!cloudVirtualPath.StartsWith("Autodesk Docs://"))
    {
        // 非云模型直接返回原路径
        return doc.PathName;
    }
    
    // 移除虚拟路径前缀
    string pathWithoutPrefix = cloudVirtualPath.Replace("Autodesk Docs://", "");
    int firstSeparatorIndex = pathWithoutPrefix.IndexOf('/');
    if (firstSeparatorIndex < 0) return string.Empty;
    
    // 拆分项目ID和文件相对路径
    string projectGuid = pathWithoutPrefix.Substring(0, firstSeparatorIndex);
    string fileRelativePath = pathWithoutPrefix.Substring(firstSeparatorIndex + 1).Replace('/', '\\');
    
    // 读取注册表获取项目本地根目录
    string regKeyPath = $@"Software\Autodesk\Desktop Connector\Folders\ACCDocs\{projectGuid}";
    using (RegistryKey regKey = Registry.CurrentUser.OpenSubKey(regKeyPath))
    {
        if (regKey == null) return string.Empty;
        string projectLocalRoot = regKey.GetValue("Path")?.ToString();
        if (string.IsNullOrEmpty(projectLocalRoot)) return string.Empty;
        
        return Path.Combine(projectLocalRoot, fileRelativePath);
    }
}

注意事项

  • 两种方案的生效前提是用户已经安装并登录Autodesk Desktop Connector,对应云项目已经完成本地同步
  • 优先使用方案1,为官方提供的标准接口,稳定性和兼容性更有保障
  • 方案2中的注册表路径可能会随Desktop Connector版本更新发生变化,使用前需对应目标版本做适配验证

内容的提问来源于stack exchange,提问作者Maycon Freitas

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.30 12:54:03