简体   繁体   English

R 脚本:BIM360 元数据通过 Forge 到 PowerBi

[英]R scripting: BIM360 metadata to PowerBi via Forge

Currently I have revit files on BIM360 and I am trying to get the metadata into PowerBi. I ran into this code on how to do it but I have some questions that maybe someone can answer them.目前我在 BIM360 上有 revit 文件,我正在尝试将元数据放入 PowerBi。我遇到了关于如何执行此操作的代码,但我有一些问题,也许有人可以回答。 Currently it appears that the metadata being pulled is from model properties and I need to the metadata from the sheet properties.目前看来,正在提取的元数据来自 model 属性,我需要来自工作表属性的元数据。 the code below shows which fields are being pulled:下面的代码显示了哪些字段被拉取:

#######################################################################
## 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
)

My question is can I use this to get into the Revit file and get the sheet properties?我的问题是我可以使用它进入 Revit 文件并获取图纸属性吗? If so how did was the name "versionNumber" in include.attribute.versionNumber decided?如果是这样, include.attribute.versionNumber中的名称“versionNumber”是如何决定的? Is this how the package in R script predetermines it or is this how the name on the server side appears?这是 R 脚本中的 package 预先确定的方式还是服务器端名称的显示方式?

Thank you so much in advance and I'm sorry if I don't have the correct etiquette down packed.提前非常感谢您,如果我没有正确的礼仪,我很抱歉。

In this R script, it uses the HTTP request endpoint of Forge: GET Folder Contents, which is one call of Data Management API. The link below is the API help about this endpoint.在这个R脚本中,它使用了Forge的HTTP请求端点:GET Folder Contents,这是数据管理API的一次调用。下面的链接是API关于这个端点的帮助。 It does not support getting document metadata or properties.它不支持获取文档元数据或属性。 https://forge.autodesk.com/en/docs/data/v2/reference/http/projects-project_id-folders-folder_id-contents-GET/ https://forge.autodesk.com/en/docs/data/v2/reference/http/projects-project_id-folders-folder_id-contents-GET/

To get metadata or properties, it falls into another category of Forge: Model Derivative 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/获取元数据或属性,属于Forge的另一类:Model Derivative 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/

This blog below may be of a little help for you to understand the endpoints: https://forge.autodesk.com/blog/get-all-dbid-without-enumerating-model-hierarchy下面的博客可能对您了解端点有一点帮助: https://forge.autodesk.com/blog/get-all-dbid-without-enumerating-model-hierarchy

So, that means, you will need to compose the call in R script with the schema of the endpoints above.因此,这意味着您将需要使用上述端点的模式在 R 脚本中编写调用。

However, please be aware:但是,请注意:

  1. When getting properties, the default limit is 20M.获取属性时,默认限制为20M。 If the response json is larger than 20M, Forge will not return the data by default, you will need to input a query parameter forceget, APII help tells more.如果响应json大于20M,Forge默认不会返回数据,需要输入一个查询参数forceget,APII帮助说明更多。 So, you may have imagined, the properties can be huge if it is a complicated model. It will take long time when executing R script, or even I am afraid it will be timeout.所以,你可能想过,如果是一个复杂的model,属性会很大。执行R脚本的时候会耗费很长时间,甚至恐怕会超时。
  2. Actually, when getting folder contents, this sample you are using is only dump the default page.实际上,在获取文件夹内容时,您使用的这个示例只是转储默认页面。 One folder may include a many items.一个文件夹可能包含许多项目。 By default, any web service does not return all items in one call, instead, we need to specify how many items that can be exported in one page.默认情况下,任何 web 服务都不会在一次调用中返回所有项目,相反,我们需要指定在一页中可以导出多少项目。 in the specific example, the maximum number of one page for item list is 200. In another word, if the folder you check has more than 200, this R script will not tell all documents/sheets.在具体的例子中,item list的一页最大页数是200。换句话说,如果你检查的文件夹超过200,这个R脚本不会告诉所有的文档/工作表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM