Skip to content

autodesk-platform-services/aps-hubs-recursive-extraction

Repository files navigation

Files and folders extraction sample

Platforms .NET License

oAuth2 Data-Management BIM360 ACC

MongoDB

Advanced

Description

This sample demonstrate how to retrieve data of all the folders and files on a specific project to render on a table and export it as csv. This sample recursively iterate through all folders of the selected project. It then, stores the data on a MongoDB collection temporarily, until the client retrieves that to render on its page. By the end of the extraction, every file and folder under the selected project are rendered on the user table and can be exported as csv.

Thumbnail

thumbnail

Live version

Try it at https://aps-hubs-recursive-extraction.autodesk.io/

Setup

Prerequisites

  1. APS Account: Learn how to create a APS Account, activate subscription and create an app at this tutorial.
  2. Visual Studio: Either Community (Windows) or Code (Windows, MacOS).
  3. .NET Core basic knowledge with C#
  4. MongoDB: noSQL database, learn more. Or use a online version via mLab (this is used on this sample)
  5. HangFire: Library for dealing with queueing. [learn more] (https://www.hangfire.io).

Running locally

Clone this project or download it. It's recommended to install GitHub desktop. To clone it via command line, use the following (Terminal on MacOSX/Linux, Git Shell on Windows):

git clone https://github.com/autodesk-platform-services/aps-hubs-recursive-extraction

MongoDB

MongoDB is a no-SQL database based on "documents", which stores JSON-like data. For testing purpouses, you can either use local or live. For cloud environment, try MongoDB Atlas (offers a free tier). With MongoDB Atlas you can set up an account for free and create clustered instances, intructions:

  1. Create a account on MongoDB Atlas.
  2. Under "Collections", create a new database (e.g. named filesnfoldersextraction) with a collection (e.g. named items).
  3. Under "Command Line Tools", whitelist the IP address to access the database, see this tutorial. If the sample is running on Heroku, you'll need to open to all (IP 0.0.0.0/0). Create a new user to access the database.

At this point the connection string should be in the form of mongodb+srv://<username>:<password>@clusterX-a1b2c4.mongodb.net/inventor2revit?retryWrites=true. Learn more here

There are several tools to view your database, Robo 3T (formerly Robomongo) is a free lightweight GUI that can be used. When it opens, follow instructions here to connect to MongoDB Atlas.

Visual Studio (Windows):

Right-click on the project, then go to Debug. Adjust the settings as shown below. For environment variable, define the following:

  • ASPNETCORE_ENVIRONMENT: Development
  • APS_CLIENT_ID: your id here
  • APS_CLIENT_SECRET: your secret here
  • APS_CALLBACK_URL: http://localhost:8080/api/aps/callback/oauth
  • ITEMS_COLLECTION: your collection for temporary storage of files and folders
  • HANGFIREDATABASE: Hangfire database name
  • MONGO_CONNECTOR: your mongodb connection string
  • ITEMS_DB: your items database name

Visual Sutdio Code (Windows, MacOS):

Open the folder, at the bottom-right, select Yes and Restore. This restores the packages (e.g. Autodesk.Forge) and creates the launch.json file. See Tips & Tricks for .NET Core on MacOS.

At the .vscode\launch.json, find the env vars and add your APS Client ID, Secret and callback URL. Also define the ASPNETCORE_URLS variable. The end result should be as shown below:

"env": {
  "ASPNETCORE_ENVIRONMENT": "Development",
  "ASPNETCORE_URLS" : "http://localhost:8080",
  "ITEMS_COLLECTION": "your collection for temporary storage of files and folders",
  "APS_CALLBACK_URL": "http://localhost:8080/api/aps/callback/oauth",
  "APS_CLIENT_SECRET": "your client secret here",
  "HANGFIREDATABASE": "Hangfire database name",
  "MONGO_CONNECTOR": "your mongodb connection string",
  "APS_CLIENT_ID": "your client Id here",
  "ITEMS_DB": "your items database name"
},

Open http://localhost:3000 to start the app. Select Index my BIM 360 Account before using (this process may take a while). Check the http://localhost:3000/dashboard to see the jobs running (Hangfire dashboard).

Further Reading

Documentation:

Other APIs:

Tips & Tricks

This sample uses .NET Core and works fine on both Windows and MacOS, see this tutorial for MacOS.

Troubleshooting

  1. Cannot see my BIM 360/ACC projects: Make sure to provision the APS App Client ID within the BIM 360 Account, learn more here. This requires the Account Admin permission.

  2. error setting certificate verify locations error: may happen on Windows, use the following: git config --global http.sslverify "false"

License

This sample is licensed under the terms of the MIT License. Please see the LICENSE file for full details.

Written by

João Martins @JooPaulodeOrne2, APS Partner Development

About

Files and folders extraction sample:Sample to demonstrate how to retrieve data of all the folders and files on a specific project to show on a table and export it as CSV.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published