Skip to content

shubhamgadekar5/model.derivative-csharp-context.menu

 
 

Repository files navigation

model.derivative-csharp-context.menu

Platforms .NET ASP.NET License

Description

This sample will add a Windows Explorer context menu "Extract Properties" for Revit files. The desktop app will upload the .RVT to the Forge Model Derivative API, translate and extract all properties into a Excel file. It was written in C# for Windows (tested on Windows 10) and 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 files, download of results and notifications.

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.

Demonstration

See this video demonstration.

The new option should appear on the Windows Explorer right-click context menu:

A notification ballon indicate the overall process:

When ready, the Excel file will be downloaded to the same folder as the original Revit file.

Security

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.

Setup

Install Visual Studio 2015.

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.

Deployment

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>

License

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

Written by

Augusto Goncalves @augustomaia, Forge Partner Development

About

Extract properties from a Revit file into a Excel spreadsheet

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 99.8%
  • Classic ASP 0.2%