Skip to content

Commit

Permalink
fix Recursive directory create
Browse files Browse the repository at this point in the history
  • Loading branch information
chuongmep committed Feb 28, 2024
1 parent aadce9c commit 26f3488
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
16 changes: 9 additions & 7 deletions APSToolkit/BIM360/BIM360.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1732,6 +1732,8 @@ public PropDbReaderRevit GetPropDbReaderRevit(string token3Leg,string versionId)
public void BatchExportAllRevitToExcelByFolder(string directory, string projectId, string folderId,
bool isRecursive)
{
DirectoryInfo directoryInfo = new DirectoryInfo(directory);
if(!directoryInfo.Exists) directoryInfo.Create();
ExportRevitExcelRecursive(directory, projectId, folderId,isRecursive);
}

Expand Down Expand Up @@ -1791,6 +1793,8 @@ private void BatchReportItemVersionRecursive(string projectId,string folderId,st
}
public void BatchExportAllRevitToExcel(string token2Leg,string directory,string hubId,string projectId,bool isRecursive)
{
DirectoryInfo directoryInfo = new DirectoryInfo(directory);
if(!directoryInfo.Exists) directoryInfo.Create();
(string, string) projectFilesFolder = GetTopProjectFilesFolder(token2Leg, hubId, projectId);
string TopFolderId = projectFilesFolder.Item1;
var foldersApi = new FoldersApi();
Expand Down Expand Up @@ -1822,8 +1826,6 @@ public void ExportRevitDataToExcel(string token3Leg,string filePath,string versi
}
private void ExportRevitExcelRecursive(string directory, string projectId, string folderId,bool isRecursive)
{
DirectoryInfo directoryInfo = new DirectoryInfo(directory);
if(!directoryInfo.Exists) directoryInfo.Create();
var foldersApi = new FoldersApi();
// refresh token
string get2LeggedToken = Auth.Authentication.Get2LeggedToken().Result;
Expand All @@ -1833,11 +1835,7 @@ private void ExportRevitExcelRecursive(string directory, string projectId, strin
{
string name = (string)itemInfo.Value.attributes.displayName;
string id = (string)itemInfo.Value.id;
if (itemInfo.Value.type == "folders" && isRecursive)
{
ExportRevitExcelRecursive(directory, projectId, id,isRecursive);
}
else if (itemInfo.Value.type == "items" && name.EndsWith(".rvt"))
if (itemInfo.Value.type == "items" && name.EndsWith(".rvt"))
{
get2LeggedToken = Auth.Authentication.Get2LeggedToken().Result;
dynamic? item = GetLatestVersionItem(get2LeggedToken, projectId, id);
Expand All @@ -1864,6 +1862,10 @@ private void ExportRevitExcelRecursive(string directory, string projectId, strin
LogUtils.Info("Export " + fileName + " done in " + TotalTime.TotalMinutes + " minutes");

}
else if (itemInfo.Value.type == "folders" && isRecursive)
{
ExportRevitExcelRecursive(directory, projectId, id,isRecursive);
}
}
}
}
9 changes: 2 additions & 7 deletions APSToolkitUnit/BIM360Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -446,16 +446,11 @@ public void TestBatchExportAllRevitToExcel(string hubId,string projectId)
bim360.BatchExportAllRevitToExcel(Settings.Token2Leg,directory, hubId, projectId,true);
}
[Test]
[TestCase("b.1f7aa830-c6ef-48be-8a2d-bd554779e74b","urn:adsk.wipprod:fs.folder:co.dEsE_6gCT6q0Kz7cRSGx0w")]
[TestCase(Settings.ProjectId,Settings.FolderId)]
public void TestBatchExportAllRevitToExcelByFolder(string projectId,string folderId)
{
BIM360 bim360 = new BIM360();
string directory =
@"/output";
if (!System.IO.Directory.Exists(directory))
{
System.IO.Directory.CreateDirectory(directory);
}
string directory = @"./output";
bim360.BatchExportAllRevitToExcelByFolder(directory, projectId,folderId,true);
}

Expand Down

0 comments on commit 26f3488

Please sign in to comment.