Skip to content

RevitAddin.CommandLoader project compiles IExternalCommand with Revit open using CodeDom.Compiler and creates a PushButton on the Revit ribbon.

License

Notifications You must be signed in to change notification settings

ricaun-io/RevitAddin.CommandLoader

Repository files navigation

RevitAddin.CommandLoader

Revit 2017 Visual Studio 2022 Nuke License MIT Build

CommandLoader

RevitAddin.CommandLoader project compiles IExternalCommand with Revit open using CodeDom.Compiler and creates a PushButton on the Revit ribbon.

This project was generated by the AppLoader Revit plugin.

Features

  • Compile multiple IExternalCommand at once with Revit opened.
  • Generate PushButton with the compiled IExternalCommand with IExternalCommandAvailability.
  • AutoUpdate plugin using ricaun.Revit.Github.
  • Gist link downloads the content and compiles each file.

Compiler Limitations

Revit 2017 to 2020 the CodeDom.Compiler only work with C# compiler version v4.0 maximum, the following features do not work in C# version 4.

  • Async Features (C# version 5)
  • String interpolation (C# version 6)

Revit 2021 to 2024 the CodeDom.Compiler uses the Roslyn version compiler. The Roslyn compiler is a new compiler that supports C# version 6 and above.

Revit 2025+ the CodeDom.Compiler uses the Microsoft.CodeAnalysis.CSharp to work with NET Core.

The RevitAddin.CommandLoader.Tests have some tests to make sure the compiler works in Net Framework and Net Core.

Customize IExternalCommand

Using System.ComponentModel attributes is possible to customize the IExternalCommand that is generated in the Revit ribbon.

  • DisplayNameAttribute: Set the Text in the PushButton.
  • DescriptionAttribute: Set the Tooltip in the PushButton.
  • DesignerAttribute: Set the LargeImage in the PushButton. (Works with component, URL, and base64)

If IExternalCommandAvailability is added in the same IExternalCommand class the availability gonna be applied in the PushButton.

Example

The command below show the version of Revit in a MessageBox.

using System;
using System.ComponentModel;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;

namespace RevitAddin
{
    [DisplayName("Revit\rVersion")]
    [Description("Show a Window with the Revit VersionName.")]
    [Designer("/UIFrameworkRes;component/ribbon/images/revit.ico")]
    [Transaction(TransactionMode.Manual)]
    public class Command : IExternalCommand, IExternalCommandAvailability
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elementSet)
        {
            UIApplication uiapp = commandData.Application;
            System.Windows.MessageBox.Show(uiapp.Application.VersionName);
            return Result.Succeeded;
        }
        public bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
        {
            return true;
        }
    }
}

Gist Example

The RevitAddin.CommandLoader have the feature to download gist files from GitHub and compile the IExternalCommand with the gist file.

Just copy the gist link in the RevitAddin.CommandLoader compiler and execute.

Resources

Installation

Video

Videos in Portuguese with the creation of this project.

VideoIma1

Videos in English about this project.

VideoIma2 VideoIma3 VideoIma4

License

This project is licensed under the MIT Licence.


Do you like this project? Please star this project on GitHub!

About

RevitAddin.CommandLoader project compiles IExternalCommand with Revit open using CodeDom.Compiler and creates a PushButton on the Revit ribbon.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project