This sample will add a Windows Explorer context menu "Extract Properties" for Revit files, which uploads the file to Forge, extract all properties and generates a Excel (XLS) file at the same folder as the original RVT file.
It includes 3 projects:
1. CSShellExtContextMenuHandler: Class Library (.DLL) that implement the required COM interface to extend the Windows Explorer context menu. The original source code is available at this Code Project article.
2. Translator: WinForm .EXE that contains a basic interface and handles upload of the Revit files, download of Excel results and notifications during the process.
3. TranslatorServer: ASP.NET project that handles all Forge related tasks, hiding those operations from the end-user. Forge Client ID & Secret are used here.
After registering the DLL, the new option should appear on the Windows Explorer right-click context menu. During the processing, a notification ballon indicate the overall process. When ready, the Excel file will be downloaded to the same folder as the original Revit file.
Your Forge Client ID & Secret should never be exposed or embedded on a desktop application, it is never safe. Your write-enabled token should also not be send to a desktop application. There are several articles about that available on the web.
This sample keeps all Forge related information on the TranslationServer and only send a random GUID to the desktop application (Transaltor.exe) that allow access to the resulting Excel and expires after 24 hours (same as Transient Bucket retention policy). The desktop app keeps this GUID in memory and use it to request the status (progress) and download the Excel file when it's done.
- Forge Account: Learn how to create a Forge Account, activate subscription and create an app at this tutorial.
- Visual Studio: Community version or higher (Professional/Enterprise)
- .NET basic knowledge with C#
Clone this project or download it. It's recommended to install GitHub desktop. To clone it via command line, use the following (Git Shell on Windows):
git clone https://github.com/autodesk-forge/model.derivative-csharp-context.menu
For using this sample, you need an Autodesk developer credentials. Visit the Forge Developer Portal, sign up for an account, then create an app that uses Data Management and Model Derivative APIs. For this new app, use http://localhost:3000/api/forge/callback/oauth as Callback URL, although is not used on 2-legged flow. Finally take note of the Client ID and Client Secret.
At the TranslatorServer project, open the web.config file and adjust the appSettings (for deployment, use host settings instead):
<appSettings>
<add key="FORGE_CLIENT_ID" value="<<Your Client ID from Developer Portal>>" />
<add key="FORGE_CLIENT_SECRET" value="<<Your Client Secret>>" />
</appSettings>
Compile the solution, Visual Studio should download the NUGET packages (Autodesk Forge, RestSharp and Newtonsoft.Json)
The CSShellExtContextMenuHandler.dll must be registered with Admin level permissions on the local machine:
regasm.exe CSShellExtContextMenuHandler.dll /codebase
Run should start the TranslatorServer web app.
Right-click on a .RVT file and select the "Extract Properties" menu option, it should trigger the "Translator.exe" on the same folder as the DLL.
This video demonstrates how to run it locally.
The TranslatorServer should be deployed to a ASP.NET compatible host, like Azure or Appharbor. For Appharbor deployment, following this steps to configure your Forge Client ID & Secret.
Adjust the Translator desktop app app.config with the server address:
<appSettings>
<add key="TranslatorServer" value="https://YOUR_DOMAIN_NAME.COM"/>
</appSettings>
Documentation:
Other samples:
- BIM 360 XLS live and source code
- Nothing happens after click on context menu "Extract Properties": make sure the path of the
Translator.exe
is correct at the Context Menu class. You may need to unregister the DLL to fix it.
This sample is licensed under the terms of the MIT License. Please see the LICENSE file for full details.
Augusto Goncalves @augustomaia, Forge Partner Development