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

如何使用Python从Autodesk BIM360/ACC下载文件?求示例代码

从Autodesk BIM360/ACC平台下载文件的Python示例代码

以下是实现从Autodesk BIM360/ACC平台下载指定文件夹中Revit文件的Python代码片段,核心逻辑是遍历选中的文件夹,筛选出其中的.rvt文件并执行下载:

def download_selected_files(self):
    """启动从选中文件夹下载指定文件的流程"""
    headers = {'Authorization': f'Bearer {self.token}'}
    for folder_id, checkbox in self.folder_checkboxes.items():
        if checkbox.isChecked():
            self.download_files_from_folder(self.project_id, folder_id, headers)

def download_files_from_folder(self, project_id, folder_id, headers):
    """下载指定文件夹中的所有Revit文件"""
    url = f"https://developer.api.autodesk.com/data/v1/projects/{project_id}/folders/{folder_id}/contents"
    response = requests.get(url, headers=headers)
    response.raise_for_status()  # 请求失败时抛出异常
    folder_data = response.json()

    # 如果'included'不在'data'的子项中,将其存到循环外部
    included_data = folder_data.get('included', [])  # 当'included'不存在时使用安全默认值(空列表)

    for item in folder_data['data']:
        if 'displayName' in item['attributes']:
            file_name = item['attributes']['displayName']
            if file_name.endswith('.rvt'):
                # 根据文件项的关联关系匹配对应的'included'数据
                storage_id = item['relationships']['storage']['data']['id']
                file_url = next((inc['attributes']['url'] for inc in included_data if inc['id'] == storage_id), None)
                if file_url:
                    self.download_file(file_url, file_name, headers)
                else:
                    print(f"未找到文件{file_name}的存储URL")

代码说明

  • download_selected_files:遍历已勾选的文件夹,触发对应文件夹的文件下载流程
  • download_files_from_folder:调用Autodesk Data API获取文件夹内容,筛选出Revit文件(.rvt后缀),通过关联的存储ID获取下载链接,最终调用download_file方法完成文件下载(该方法需自行实现,逻辑为通过HTTP请求将文件保存到本地)

内容的提问来源于stack exchange,提问作者vijaya adigopula

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.24 11:17:28