首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >R脚本:通过BIM360将元数据伪造到PowerBi

R脚本:通过BIM360将元数据伪造到PowerBi
EN

Stack Overflow用户
提问于 2020-10-08 03:27:08
回答 1查看 200关注 0票数 1

目前我在BIM360上有revit文件,我正在尝试将元数据放到PowerBi中。我遇到了关于如何做的代码,但我有一些问题,也许有人可以回答他们。目前看来,正在拉取的元数据来自模型属性,我需要从图纸属性中提取元数据。下面的代码显示了正在拉取的字段:

代码语言:javascript
复制
#######################################################################
## This R script is a sample code that demonstrate how to extract documents' data from a BIM 360 Docs project using Autodesk Forge APIs.
#####################################################################

# Define Forge App Client ID and Secret, BIM 360 Account ID, and Project ID
App_Client_ID <- ""
App_Client_Secret <- ""
BIM360_Account_ID <- ""
BIM360Docs_Project_ID <- ""


#Load libraries required for the R script
library(httr)
library(jsonlite)


#Define a function that loops through BIM 360 Docs folder structure to build a document list 
Parse_Folder <- function(folder_id, folder_name){
  Get_Folder_Content_URL <- paste("https://developer.api.autodesk.com/data/v1/projects/b.",
                                  BIM360Docs_Project_ID,
                                  "/folders/",
                                  folder_id,
                                  "/contents", sep="")
  Get_Folder_Content_Request <- GET(Get_Folder_Content_URL, add_headers("Authorization" = Access_Token))
  Get_Folder_Content_Data <- jsonlite::fromJSON(content(Get_Folder_Content_Request, "text", "application/json", "UTF-8"))
  Folder_Content_Files <- flatten(data.frame(Get_Folder_Content_Data["included"]))
  
  if (nrow(Folder_Content_Files) != 0){
    Folder_Content_Files$document.location <- rep(folder_name, nrow(Folder_Content_Files))
    Folder_Content_Files_SelectedColumns <- as.data.frame(Folder_Content_Files[, c("document.location",
                                                                                   "included.attributes.displayName",
                                                                                   "included.attributes.createUserName",
                                                                                   "included.attributes.createUserId",
                                                                                   "included.attributes.lastModifiedUserName",
                                                                                   "included.attributes.lastModifiedUserId",
                                                                                   "included.attributes.versionNumber",
                                                                                   "included.attributes.fileType",
                                                                                   "included.attributes.extension.type",
                                                                                   "included.attributes.createTime",
                                                                                   "included.attributes.lastModifiedTime",
                                                                                   
    )])
    
    BIM360Docs_Document_List <- rbind(BIM360Docs_Document_List, Folder_Content_Files_SelectedColumns)
    assign("BIM360Docs_Document_List", BIM360Docs_Document_List, envir = .GlobalEnv)
  }
  
  Folder_Content_Data <- flatten(data.frame(Get_Folder_Content_Data["data"]))
  if (nrow(Folder_Content_Data) != 0){
    for(i in 1:nrow(Folder_Content_Data)){
      if(Folder_Content_Data[i,"data.type"]=="folders"){
        tryCatch({
          Parse_Folder(Folder_Content_Data[i,"data.id"], paste(folder_name, "/", Folder_Content_Data[i,"data.attributes.displayName"], sep=""))
        }, error=function(e){})
      }
    }
  }
}


#Use Forge Authentication API to get access token
App_Authenticate <- POST("https://developer.api.autodesk.com/authentication/v1/authenticate",
                         add_headers("Content-Type" = "application/x-www-form-urlencoded"),
                         body=I(list(client_id = App_Client_ID,
                                     client_secret = App_Client_Secret,
                                     grant_type = "client_credentials",
                                     "scope" = "data:read")),
                         encode = "form")
Access_Token <- paste("Bearer", content(App_Authenticate)$access_token,  sep=" ")


#Use Forge Data Managment API to Access Top Folders in the project
Get_Top_Folders_URL <- paste("https://developer.api.autodesk.com/project/v1/hubs/b.",
                             BIM360_Account_ID,
                             "/projects/b.",
                             BIM360Docs_Project_ID,
                             "/topFolders", sep="")
Get_Top_Folders_Request <- GET(Get_Top_Folders_URL, add_headers("Authorization" = Access_Token))
Get_Top_Folders_Data <- jsonlite::fromJSON(content(Get_Top_Folders_Request, "text", "application/json", "UTF-8"))
TopFolders_Content <- flatten(data.frame(Get_Top_Folders_Data))
BIM360Docs_Document_List <- data.frame(Date=as.Date(character()), File=character(), User=character(), stringsAsFactors=FALSE) 

for(i in 1:nrow(TopFolders_Content)){
  TopFolderName <- TopFolders_Content[i,"data.attributes.displayName"]
  if (TopFolderName != "ProjectTb" && TopFolderName != "Photos" && TopFolderName != "Recycle Bin" ){
    tryCatch({
      Parse_Folder(TopFolders_Content[i,"data.id"], TopFolderName)
    }, error=function(e){})
  }
}

names(BIM360Docs_Document_List)[names(BIM360Docs_Document_List)=="document.location"] <- "Document Location"
names(BIM360Docs_Document_List)[names(BIM360Docs_Document_List)=="included.attributes.displayName"] <- "File Name"
names(BIM360Docs_Document_List)[names(BIM360Docs_Document_List)=="included.attributes.createUserName"] <- "Created by"
names(BIM360Docs_Document_List)[names(BIM360Docs_Document_List)=="included.attributes.createUserId"] <- "Created by (ID)"
names(BIM360Docs_Document_List)[names(BIM360Docs_Document_List)=="included.attributes.lastModifiedUserName"] <- "Updated by"
names(BIM360Docs_Document_List)[names(BIM360Docs_Document_List)=="included.attributes.lastModifiedUserId"] <- "Updated by (ID)"
names(BIM360Docs_Document_List)[names(BIM360Docs_Document_List)=="included.attributes.versionNumber"] <- "Version"
names(BIM360Docs_Document_List)[names(BIM360Docs_Document_List)=="included.attributes.fileType"] <- "File Type"
names(BIM360Docs_Document_List)[names(BIM360Docs_Document_List)=="included.attributes.extension.type"] <- "Extension Type"
names(BIM360Docs_Document_List)[names(BIM360Docs_Document_List)=="included.attributes.createTime"] <- "Created Date"
names(BIM360Docs_Document_List)[names(BIM360Docs_Document_List)=="included.attributes.lastModifiedTime"] <- "Updated Date"


# Clear Variables
rm(i, Access_Token,
   App_Client_ID,
   App_Client_Secret,
   App_Authenticate,
   BIM360_Account_ID,
   BIM360Docs_Project_ID,
   Get_Top_Folders_URL, 
   Get_Top_Folders_Request,
   Get_Top_Folders_Data,
   TopFolders_Content,
   TopFolderName,
   Parse_Folder
)

我的问题是,我是否可以使用此命令进入Revit文件并获取图纸属性?如果是这样的话,include.attribute.versionNumber中的"versionNumber“这个名字是怎么决定的?这是R脚本中的包预先确定它的方式,还是服务器端的名称显示方式?

提前谢谢你,如果我没有准备好正确的礼仪,我很抱歉。

EN

回答 1

Stack Overflow用户

发布于 2020-10-12 10:08:45

在这个R脚本中,它使用了HTTP请求端点Forge: GET Folder Contents,这是数据管理API的一次调用。下面的链接是有关此终结点的API帮助。它不支持获取文档元数据或属性。https://forge.autodesk.com/en/docs/data/v2/reference/http/projects-project_id-folders-folder_id-contents-GET/

为了获取元数据或属性,它属于另一类伪造:模型派生API:https://forge.autodesk.com/en/docs/model-derivative/v2/reference/http/urn-metadata-guid-GET/ https://forge.autodesk.com/en/docs/model-derivative/v2/reference/http/urn-metadata-guid-properties-GET/

下面的博客可能会对您理解端点有一点帮助:https://forge.autodesk.com/blog/get-all-dbid-without-enumerating-model-hierarchy

因此,这意味着您将需要在R脚本中使用上述端点的模式编写调用。

但是,请注意:

  1. 获取属性时,默认限制为20M。如果响应json大于20M,Forge默认不会返回数据,你需要输入一个查询参数forceget,APII帮助会告诉你更多。所以,你可能已经想象到,如果它是一个复杂的模型,那么属性可能是巨大的。执行R脚本需要很长时间,甚至我担心在获取文件夹内容时会出现timeout.
  2. Actually,,您使用的这个示例只是转储默认页面。一个文件夹可以包含多个项目。默认情况下,任何web服务都不会在一次调用中返回所有项,相反,我们需要指定在一个页面中可以导出多少项。在具体示例中,项目列表的最大一页数为200。换句话说,如果您检查的文件夹超过200个,则此R脚本不会告诉所有documents/sheets.
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64251007

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档