Design Automation For Revit – Part 1

Amazing! Design Automation For Revit – Part 1

Information about Design Automation For Revit – Part 1

Phil Puccio

I recently got a new version of my. released RVT according to IFC Online converter. Among other modifications, this new version now uses the Autodesk Design Automation API instead of the model derivative API.

What is this design automation API? It is a set of Autodesk Forge capabilities for running a Revit add-in in the cloud. Instead of running an add-in on your own Revit on your local computer, upload that add-in to the Autodesk Forge server, where it will run on a Revit engine specially designed to run in that environment. It allows you to edit Revit files without having Revit installed locally.

In this two part series we will see how this API works and together we will create a Forge plugin to export a Revit file to IFC without opening Revit.

To do this, we need an Autodesk Forge application and a custom Revit add-in to upload to that application. This application will be exactly the same that RVT To IFC does.

Most of the explanations presented here are from the Official documentation from Design Automation.

We’ll start by creating a new class library in Visual Studio that we’ll call the RevitToIFCBundle. In this project we add the “RevitAPI.dll” and set its “Copy Local” property to “False” (1)

Copy locally

We then add “Autodesk.Forge.DesignAutomation.Revit”. Nuget package to our soution.

Since we will be running this plugin on a headless server, we will not be able to use the RevitAPIUI.dll (the Revit interface) or other UI based libraries like Windows Form or WPF.

We also need an .addin file with the type “DBApplication” for our application:

<?xml version="1.0" encoding="utf-8"?>
  <AddIn Type="DBApplication">
    <Description>"Export to IFC"</Description>

We’ll create a new class, RevitToIFCBundleApp, which will hold most of our add-in. This class inherits from IExternalDBApplication. Since we don’t have access to the Revit UI when running our plugin, we don’t have a button to launch our application. To handle this we implement two methods, OnStartup and OnShutdown:

        public ExternalDBApplicationResult OnStartup(
          Autodesk.Revit.ApplicationServices.ControlledApplication app)
            DesignAutomationBridge.DesignAutomationReadyEvent += HandleDesignAutomationReadyEvent;
            return ExternalDBApplicationResult.Succeeded;

        public ExternalDBApplicationResult OnShutdown(
          Autodesk.Revit.ApplicationServices.ControlledApplication app)
            return ExternalDBApplicationResult.Succeeded;

The entry point into our code is handled by the DesignAutomationReadyEvent handler. The DesignAutomationReadyEvent is triggered when the Revit engine is ready to run our add-in.

        public void HandleDesignAutomationReadyEvent(object sender, DesignAutomationReadyEventArgs e)
            e.Succeeded = true;

Finally, we’ll create an ExportToIFC function that will hold our code. The code here is simple, we get the Revit document, create a transaction, and export the model to IFC.

The entire source for this plugin is available on Github.

Before we upload the add-in to the Forge server, we need to debug it locally. We need them for that local debug tool for Design Automation for Revit. After cloning the repository, we create the solution and get a Revit plugin.

We also need to copy the plugin’s .addin file and .dll to the Revit add-in folder. We’ll also add these lines to the post build in Visual Studio:

if exist "$(AppData)AutodeskREVITAddins2021" 
         copy "$(ProjectDir)*.addin" "$(AppData)AutodeskREVITAddins2021"
if exist "$(AppData)AutodeskREVITAddins2021"
         copy "$(ProjectDir)$(OutputPath)*.dll" "$(AppData)AutodeskREVITAddins2021"

We also add Revit.exe as a launcher for our debugging session (1).

We also need a working directory that simulates the working directory of the Forge server. We add this directory in Visual Studio as below (2). In this case, our plugin needs an input file, the Revit file, which is to be converted to IFC. We add their path in the command line arguments (3).

Visual Studio configuration

Then we can start the debugging session in Visual Studio. The input file will open, we go to the Add-Ins tab and run the DesignAutomationHandler command:

Design automation handler

The plugin runs smoothly and the resulting IFC file is saved in the working directory.

The next post will show you how to build and run the Forge application.

Breaking Story – Design Automation For Revit – Part 1

The Latest News on Design Automation For Revit – Part 1

Original Source:
Category – BIM

© 2022 - WordPress Theme by WPEnjoy