Skip to content

Commit

Permalink
Merge pull request #1 from chuongmep/dev
Browse files Browse the repository at this point in the history
Improvement batch process
  • Loading branch information
chuongmep authored Feb 28, 2024
2 parents 67d66b4 + eef2fa7 commit d3c4bce
Show file tree
Hide file tree
Showing 10 changed files with 544 additions and 49 deletions.
4 changes: 2 additions & 2 deletions APSToolkit/APSToolkit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
<EnableWindowsTargeting>true</EnableWindowsTargeting>
<PackageType>Dependency</PackageType>
<PackageId>APSToolkit</PackageId>
<AssemblyVersion>1.0.5</AssemblyVersion>
<PackageVersion>1.0.5</PackageVersion>
<AssemblyVersion>1.0.6</AssemblyVersion>
<PackageVersion>1.0.6</PackageVersion>
<GenerateAssemblyFileVersionAttribute>true</GenerateAssemblyFileVersionAttribute>
<Deterministic>false</Deterministic>
<PackageTags>revit;bim360;acc;adsk;forgetoolkit;forge;autodesk;aps;</PackageTags>
Expand Down
71 changes: 64 additions & 7 deletions APSToolkit/BIM360/BIM360.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1732,10 +1732,69 @@ 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);
}

/// <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)
{
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 @@ -1767,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 @@ -1778,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 @@ -1809,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);
}
}
}
}
18 changes: 11 additions & 7 deletions APSToolkitUnit/BIM360Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -446,16 +446,20 @@ 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);
}

[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");
}
}
27 changes: 21 additions & 6 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
![Platform](https://img.shields.io/badge/platform-Windows-lightgray.svg) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
![Platform](https://img.shields.io/badge/platform-Windows/MacOS/Linux-lightgray.svg) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

![ReSharper](https://img.shields.io/badge/ReSharper-2023-yellow) ![Rider](https://img.shields.io/badge/Rider-2023-yellow) ![Visual Studio 2022](https://img.shields.io/badge/Visual_Studio_2022-yellow) ![.NET Framework](https://img.shields.io/badge/.NET_6-yellow)

Expand All @@ -10,13 +10,13 @@
<img src="https://img.shields.io/twitter/follow/chuongmep?style=social&logo=twitter"
alt="follow on Twitter"></a>

## APS Toolkit
## 🔩 APS Toolkit

APS Toolkit (Former is Forge) is powerful for you to explore `Autodesk Platform Services`(APS). It's built on top of [Autodesk.Forge](https://www.nuget.org/packages/Autodesk.Forge/) and [Newtonsoft.Json](https://www.nuget.org/packages/Newtonsoft.Json/). Forge Toolkit includes some features allow you to read, download and write data from `Autodesk Platform Services` and export to CSV, Excel, JSON, XML, etc.

![APSToolkit](docs/APSToolkit.png)

## Features
## Features

- [x] Read/Download SVF Model
- [x] Read/Query Properties Database SQLite
Expand All @@ -30,7 +30,7 @@ APS Toolkit (Former is Forge) is powerful for you to explore `Autodesk Platform
- [x] Export Data to Excel
- [x] Export Data to Parquet

## Installation
## Installation

Please follow latest update at [APSToolkit Nuget](https://www.nuget.org/packages/APSToolkit)

Expand All @@ -46,7 +46,22 @@ APS_CLIENT_SECRET = <your client secret>
APS_REFRESH_TOKEN = <your refresh token>
```

## Tutorials
## ⭐ Getting Started

I want export Revit Data To Excel 👇

```csharp
using APSToolkit;
using Autodesk.Forge;
using APSToolkit.Database;
using APSToolkit.Auth;
var token = Authentication.Get2LeggedToken().Result;
string urn = "dXJuOmFkc2sud2lwcHJvZDpmcy5maWxlOnZmLk9kOHR4RGJLU1NlbFRvVmcxb2MxVkE_dmVyc2lvbj0z";
var RevitPropDbReader = new PropDbReaderRevit(urn, token);
RevitPropDbReader.ExportAllDataToExcel("result.xlsx");
```

## 📚 Tutorials

All Tutorials are available under Jupyter Notebook at [Tutorials](./docs/Tutorials)

Expand Down Expand Up @@ -77,7 +92,7 @@ Many thanks some repos:
- [UnityForgeImporter](https://github.com/chuongmep/UnityForgeImporter)
- [forge-bucketsmanager-desktop](https://github.com/Autodesk-Forge/forge-bucketsmanager-desktop)

## Contributing
## 👨‍🏫 Contributing

Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us.

Expand Down
31 changes: 27 additions & 4 deletions docs/Tutorials/01. Setup And Authentication.ipynb

Large diffs are not rendered by default.

Loading

0 comments on commit d3c4bce

Please sign in to comment.