top of page

Developing a Revit Plugin for the Imprint Protocol: A Step-by-Step Guide

Oct 29, 2024

3 min read

0

25

0

Our code is open-sourced, and you can check out the project on our GitHub repository: AEC Hackathon QR Killer. You can also view our presentation here.


Credits: Developed and pair programmed with Nehansh Saxena

 

Creating a plugin for Autodesk Revit can greatly enhance your workflow, especially when integrating with innovative concepts like the Imprint Protocol. In this guide, we’ll walk you through the process of developing a Revit add-in that captures the active view as a PNG image and uploads it to the Imprint ecosystem. We'll be using Visual Studio and .NET Framework 4.8, as Revit is only compatible with Windows.


Prerequisites


Before you start, make sure you have the following:

  1. Autodesk Revit: Installed on your Windows machine.

  2. Visual Studio: Installed (preferably the latest version) with support for .NET Framework 4.8.

  3. .NET Framework 4.8 SDK: Installed on your system.

  4. Basic understanding of the Revit API: Familiarity with the Revit API documentation is helpful. You can find it here.


Step 1: Set Up Your Visual Studio Project


  1. Open Visual Studio and select Create a new project.

  2. In the project template window, search for Class Library (.NET Framework).

  3. Select the template and click Next.

  4. Name your project (e.g., ImprintRevitPlugin), choose a location, and ensure the Framework is set to .NET Framework 4.8.

  5. Click Create to initialize the project.


Step 2: Add References to Revit API


  1. In the Solution Explorer, right-click on your project and select Add > Reference.

  2. In the Reference Manager window, click on Browse and navigate to the Revit installation directory (usually located at C:\Program Files\Autodesk\Revit 2024\).

  3. Select the following DLL files:

    • RevitAPI.dll

    • RevitAPIUI.dll

  4. Click Add and then OK to add these references to your project.


Step 3: Create Your Plugin Class


  1. In the Solution Explorer, right-click on your project and select Add > Class.

  2. Name the class (e.g., ImprintCommand.cs).

  3. Replace the default code in the class file with the following sample code:


    Full example code can be viewed here: Imprint Command Example.

using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using System.Windows.Forms;
using System.IO;
using System.Net.Http;
using System.Text;
using Newtonsoft.Json;

public class ImprintCommand : IExternalCommand
{
    public Result Execute(ExternalCommandData commandData, ElementSet elements)
    {
        // Get the active document and view
        UIDocument uiDoc = commandData.GetUIDocument();
        Document doc = uiDoc.Document;
        View activeView = doc.ActiveView;

        // Define the path to save the image
        string imagePath = Path.Combine(Path.GetTempPath(), $"{activeView.Name}.png");

        // Save the active view as a PNG file
        SaveActiveViewAsPng(doc, activeView, imagePath);

        // Show a form to input metadata
        Form inputForm = new Form();
        // (Add controls for user input here)
        // ... input form setup ...

        if (inputForm.ShowDialog() == DialogResult.OK)
        {
            string metadata = inputForm.Controls["metadataTextBox"].Text; // Example control for metadata
            string uuid = UploadImageToImprint(imagePath, metadata).Result;

            MessageBox.Show($"Image uploaded successfully! UUID: {uuid}");
        }

        return Result.Succeeded;
    }

    private void SaveActiveViewAsPng(Document doc, View view, string imagePath)
    {
        // Logic to capture the active view and save it as a PNG
        // Use RenderedView to save the image
        using (Image img = view.GetImage())
    }

    private async Task<string> UploadImageToImprint(string imagePath, string metadata) 
	{ 
		using (HttpClient client = new HttpClient()) 
	}

    private class ResponseData 
	{ 
		public string Uuid { get; set; } 
	}
}

Step 4: Create an Add-In Manifest File


  1. In your project folder, create a new folder named AddIn.

  2. Inside the AddIn folder, create a new XML file named ImprintRevitPlugin.addin.

  3. Add the following content to the ImprintRevitPlugin.addin file:

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<RevitAddIns>
    <AddIn Type="Command">
        <Name>Imprint Revit Plugin</Name>
        <Assembly>$(AppData)\Autodesk\REVIT\Addins\2024\ImprintRevitPlugin.dll</Assembly>
        <AddInId>YOUR-ADDIN-ID-HERE</AddInId>
        <VendorId>YOUR-VENDOR-ID-HERE</VendorId>
        <VendorDescription>Your Name or Company</VendorDescription>
    </AddIn>
</RevitAddIns>
  • Replace YOUR-ADDIN-ID-HERE with a unique GUID (you can generate one using online GUID generators).

  • Replace YOUR-VENDOR-ID-HERE with your vendor ID (e.g., MyCompany).


Step 5: Build Your Project


  1. In Visual Studio, go to Build > Build Solution or press Ctrl + Shift + B.

  2. Ensure there are no errors in the Output window. If there are, fix them before proceeding.


Step 6: Deploy Your Plugin


  1. Copy the ImprintRevitPlugin.dll file from your project’s bin\Debug or bin\Release folder.

  2. Navigate to the Addins folder located at:

C:\Users\<YourUserName>\AppData\Roaming\Autodesk\Revit\Addins\2024\
  1. Paste the ImprintRevitPlugin.dll and ImprintRevitPlugin.addin files into this folder.


Step 7: Test Your Plugin in Revit


  1. Open Revit.

  2. Navigate to the Add-Ins tab in the ribbon. You should see your plugin listed there.

  3. Click on your plugin, and it should prompt you to input any additional metadata before uploading the active view image to the Imprint ecosystem.


Conclusion


Congratulations! You’ve successfully developed and deployed a Revit plugin that captures the active view, allows metadata input, and uploads the image to the Imprint Protocol ecosystem. This powerful tool can enhance your architectural projects, making your workflow more efficient.


Feel free to explore the Revit API documentation further to expand the functionalities of your plugin. If you have any questions or need assistance, don’t hesitate to reach out!


Showcase



Oct 29, 2024

3 min read

0

25

0

Comments

Share Your ThoughtsBe the first to write a comment.
bottom of page