Skip to content

Commit

Permalink
add BatchReportItem method
Browse files Browse the repository at this point in the history
  • Loading branch information
chuongmep committed Feb 28, 2024
1 parent e65e02b commit 9d19445
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
36 changes: 35 additions & 1 deletion APSToolkit/BIM360/BIM360.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1760,6 +1760,7 @@ public DataTable BatchReportItemVersion(string projectId, string folderId,string
BatchReportItemVersionRecursive(projectId, folderId,extenstion,ref dataTable,isRecursive);
return dataTable;
}

private void BatchReportItemVersionRecursive(string projectId,string folderId,string extension, ref DataTable dt,bool isRecursive)
{
var foldersApi = new FoldersApi();
Expand All @@ -1774,11 +1775,13 @@ private void BatchReportItemVersionRecursive(string projectId,string folderId,st
string id = (string)itemInfo.Value.id;
if (itemInfo.Value.type == "items" && name.EndsWith(extension))
{
string urn = string.Empty;
dynamic? item = GetLatestVersionItem(get2LeggedToken, projectId, id);
string fileName = item?.attributes.displayName;
long versionNumber = item?.attributes.versionNumber;
string itemId = item?.relationships.item.data.id;
string urn = item?.relationships.derivatives.data.id;
bool flag = item?.relationships.ContainsKey("derivatives");
if(flag) urn = item?.relationships.derivatives.data.id;
DataRow row = dt.NewRow();
row["ProjectId"] = projectId;
row["FolderId"] = folderId;
Expand All @@ -1794,6 +1797,37 @@ private void BatchReportItemVersionRecursive(string projectId,string folderId,st
}
}
}
public DataTable BatchReportItem(string projectId, string itemId)
{
DataTable dataTable = new DataTable();
dataTable.Columns.Add("ItemId", typeof(string));
dataTable.Columns.Add("Version", typeof(long));
dataTable.Columns.Add("URN", typeof(string));
var itemsApi = new ItemsApi();
// refresh token
string get2LeggedToken = Auth.Authentication.Get2LeggedToken().Result;
itemsApi.Configuration.AccessToken = get2LeggedToken;
dynamic result = itemsApi.GetItemVersionsAsync(projectId, itemId).Result;
get2LeggedToken = Auth.Authentication.Get2LeggedToken().Result;
foreach (KeyValuePair<string, dynamic> itemInfo in new DynamicDictionaryItems(result.data))
{
string urn = string.Empty;
long version = itemInfo.Value.attributes.versionNumber;
// check DynamicDictionary contains derivatives, fix does not contain a definition for 'derivatives'
bool flag = itemInfo.Value.relationships.ContainsKey("derivatives");
if (flag)
{
urn = itemInfo.Value.relationships.derivatives.data.id;
}
DataRow row = dataTable.NewRow();
row["ItemId"] = itemId;
row["Version"] = version;
row["URN"] = urn;
dataTable.Rows.Add(row);

}
return dataTable;
}
public void BatchExportAllRevitToExcel(string token2Leg,string directory,string hubId,string projectId,bool isRecursive)
{
DirectoryInfo directoryInfo = new DirectoryInfo(directory);
Expand Down
11 changes: 9 additions & 2 deletions APSToolkitUnit/BIM360Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -456,11 +456,18 @@ public void TestBatchExportAllRevitToExcelByFolder(string projectId,string folde

[Test]
[TestCase("b.1f7aa830-c6ef-48be-8a2d-bd554779e74b","urn:adsk.wipprod:fs.folder:co.dEsE_6gCT6q0Kz7cRSGx0w")]
// [TestCase("b.ec0f8261-aeca-4ab9-a1a5-5845f952b17d","urn:adsk.wipprod:fs.folder:co.OyLhAc9PSoymP-_yAb3YoQ")]
public void BatchReportItemVersionTest(string projectId,string folderId)
{
BIM360 bim360 = new BIM360();
DataTable dataTable = bim360.BatchReportItemVersion(projectId,folderId,".rvt",true);
dataTable.ExportDataToExcel("result.xlsx");
dataTable.ExportToCsv(@"D:/_WIP/Forge/Earth-Demo.csv");
}
[Test]
[TestCase("b.1f7aa830-c6ef-48be-8a2d-bd554779e74b","urn:adsk.wipprod:dm.lineage:NxImvLT2T0yiFi0yZW_cKw")]
public void BatchReportItemTest(string projectId,string itemId)
{
BIM360 bim360 = new BIM360();
DataTable dataTable = bim360.BatchReportItem(projectId,itemId);
dataTable.ExportToCsv(@"D:/_WIP/Forge/ItemId_Report.csv");
}
}

0 comments on commit 9d19445

Please sign in to comment.