Skip to content

Commit

Permalink
add support BatchReportItemVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
chuongmep committed Feb 28, 2024
1 parent 3a2886f commit aadce9c
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
55 changes: 55 additions & 0 deletions APSToolkit/BIM360/BIM360.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1734,6 +1734,61 @@ public void BatchExportAllRevitToExcelByFolder(string directory, string projectI
{
ExportRevitExcelRecursive(directory, projectId, folderId,isRecursive);
}

/// <summary>
/// Generates a report of item versions in a specified folder within a project.
/// </summary>
/// <param name="projectId">The unique identifier of the project.</param>
/// <param name="folderId">The unique identifier of the folder within the project.</param>
/// <param name="extenstion">The file extension to filter items by. Default is ".rvt".</param>
/// <param name="isRecursive">A boolean value indicating whether to recursively search subfolders. Default is false.</param>
/// <returns>
/// A DataTable containing the report data. Each row represents an item in the folder (and subfolders if isRecursive is true),
/// and includes the project ID, folder ID, item ID, item name, and latest version number.
/// </returns>
public DataTable BatchReportItemVersion(string projectId, string folderId,string extenstion=".rvt",bool isRecursive =false)
{
DataTable dataTable = new DataTable();
dataTable.Columns.Add("ProjectId", typeof(string));
dataTable.Columns.Add("FolderId", typeof(string));
dataTable.Columns.Add("ItemName", typeof(string));
dataTable.Columns.Add("ItemId", typeof(string));
dataTable.Columns.Add("LatestVersion", typeof(long));
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();
// refresh token
string get2LeggedToken = Auth.Authentication.Get2LeggedToken().Result;
foldersApi.Configuration.AccessToken = get2LeggedToken;
dynamic result = foldersApi.GetFolderContentsAsync(projectId, folderId).Result;
get2LeggedToken = Auth.Authentication.Get2LeggedToken().Result;
foreach (KeyValuePair<string, dynamic> itemInfo in new DynamicDictionaryItems(result.data))
{
string name = (string)itemInfo.Value.attributes.displayName;
string id = (string)itemInfo.Value.id;
if (itemInfo.Value.type == "items" && name.EndsWith(extension))
{
dynamic? item = GetLatestVersionItem(get2LeggedToken, projectId, id);
string fileName = item?.attributes.displayName;
long versionNumber = item?.attributes.versionNumber;
string itemId = item?.relationships.item.data.id;
DataRow row = dt.NewRow();
row["ProjectId"] = projectId;
row["FolderId"] = folderId;
row["ItemName"] = fileName??string.Empty;
row["ItemId"] = itemId??string.Empty;
row["LatestVersion"] = versionNumber;
dt.Rows.Add(row);
}
else if (itemInfo.Value.type == "folders" && isRecursive)
{
BatchReportItemVersionRecursive(projectId,id, extension,ref dt,isRecursive);
}
}
}
public void BatchExportAllRevitToExcel(string token2Leg,string directory,string hubId,string projectId,bool isRecursive)
{
(string, string) projectFilesFolder = GetTopProjectFilesFolder(token2Leg, hubId, projectId);
Expand Down
9 changes: 9 additions & 0 deletions APSToolkitUnit/BIM360Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -458,4 +458,13 @@ public void TestBatchExportAllRevitToExcelByFolder(string projectId,string folde
}
bim360.BatchExportAllRevitToExcelByFolder(directory, projectId,folderId,true);
}

[Test]
[TestCase("b.1f7aa830-c6ef-48be-8a2d-bd554779e74b","urn:adsk.wipprod:fs.folder:co.dEsE_6gCT6q0Kz7cRSGx0w")]
public void BatchReportItemVersionTest(string projectId,string folderId)
{
BIM360 bim360 = new BIM360();
DataTable dataTable = bim360.BatchReportItemVersion(projectId,folderId,".rvt",true);
dataTable.ExportDataToExcel("result.xlsx");
}
}

0 comments on commit aadce9c

Please sign in to comment.