[英]R scripting: BIM360 metadata to PowerBi via Forge
目前我在 BIM360 上有 revit 文件,我正在嘗試將元數據放入 PowerBi。我遇到了關於如何執行此操作的代碼,但我有一些問題,也許有人可以回答。 目前看來,正在提取的元數據來自 model 屬性,我需要來自工作表屬性的元數據。 下面的代碼顯示了哪些字段被拉取:
#######################################################################
## 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 腳本中的 package 預先確定的方式還是服務器端名稱的顯示方式?
提前非常感謝您,如果我沒有正確的禮儀,我很抱歉。
在這個R腳本中,它使用了Forge的HTTP請求端點:GET Folder Contents,這是數據管理API的一次調用。下面的鏈接是API關於這個端點的幫助。 它不支持獲取文檔元數據或屬性。 https://forge.autodesk.com/en/docs/data/v2/reference/http/projects-project_id-folders-folder_id-contents-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/
下面的博客可能對您了解端點有一點幫助: https://forge.autodesk.com/blog/get-all-dbid-without-enumerating-model-hierarchy
因此,這意味着您將需要使用上述端點的模式在 R 腳本中編寫調用。
但是,請注意:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.