Skip to content

About

Open-source C# libraries for Autodesk Inventor add-ins (2024-2027): ribbon and command base classes, an isolated add-in loader, WPF shell, logging. AI-agent ready.

Topics

Resources

Stars

4 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

BasAutomation for Autodesk Inventor

C# libraries for building Autodesk Inventor add-ins (2024-2027): the plugin and ribbon plumbing, an isolated add-in loader, a WPF shell, logging and typed iProperties. They are the foundation of the commercial add-ins by Bas Automation Services, published here as open source under the MIT licence.

An add-in built on these libraries, in Inventor

Starting a new add-in? Use the Inventor add-in template. It sets up a solution on these libraries with the layering, tests, installer files and instructions for AI coding agents already in place.

Why

Writing an Inventor add-in means solving the same problems every time:

  • Dependency clashes. Inventor loads every add-in into one process. Two add-ins that ship different versions of the same library (Newtonsoft.Json, Serilog, a WPF control library) break each other. The Loader gives each add-in its own AssemblyLoadContext.
  • Ribbon boilerplate. Button definitions per environment, tabs and panels that may already exist, icons converted to IPictureDisp, cleanup on unload. Here you declare a CommandDefinition and the base class does the rest.
  • No host. An add-in has no Program.Main, so no dependency injection, configuration or logging. PluginBase builds a .NET Generic Host when Inventor activates the add-in.
  • Untyped iProperties. "Design Tracking Properties", "Part Number": strings everywhere. InventorPropertyName.PartNumber instead.

Libraries

Project What it is References Inventor
BasAutomation.Inventor.Core Plugin and ribbon base classes, commands, InventorClient, transactions, progress bars, typed iProperties Yes
BasAutomation.Inventor.Loader The COM shim base class and the build targets that load an add-in in its own AssemblyLoadContext Yes
BasAutomation.UI WPF: a shell window with page navigation, window/dialog/file services, ViewModelBase, converters, styles No
BasAutomation.Logging Serilog setup: one log folder per add-in under %APPDATA% No
BasAutomation.Core The few contracts and helpers the others need No

Inventor.Core depends on Core, Logging and UI; UI on Core; Core on Logging. The Loader has no dependencies.

Using them in an add-in

The Inventor add-in template does all of this for you. By hand: add this repo to your add-in as a git submodule in Inventor\, and the add-in builds the libraries from source.

git submodule add https://github.com/Bas-Automation-Services/BasAutomation.Inventor Inventor
  • Directory.Build.props of the add-in sets InventorRoot to $(MSBuildThisFileDirectory)Inventor\ and InventorVersion (2024-2027). The libraries import that file when they sit in <add-in>\Inventor\, so they build for the same Inventor.
  • Directory.Packages.props of the add-in imports $(InventorRoot)Build\Packages.Shared.props, the versions of every package the libraries use, and adds only the add-in's own packages.
  • Projects that use the Inventor API reference $(InventorRoot)src\BasAutomation.Inventor.Core\BasAutomation.Inventor.Core.csproj and import $(InventorRoot)Build\Inventor.targets, which adds the interop of the installed Inventor.
  • The shim references the Loader project and imports $(InventorRoot)src\BasAutomation.Inventor.Loader\build\Shim.targets; the implementation imports Implementation.targets from the same folder.

To update, move the submodule: git submodule update --remote Inventor.

A minimal add-in

An add-in is two projects: a tiny COM shim that Inventor loads, and the add-in itself.

The shim (MyAddin.Addin, references BasAutomation.Inventor.Loader):

[ComVisible(true)]
[Guid("A35BF192-8E9E-4596-AEA6-54F645056AE6")]   // your add-in's own GUID
public class Plugin : RibbonPluginShim
{
    protected override string ImplementationAssemblyName => "MyAddin.Implementation";
    protected override string ImplementationTypeName => "MyAddin.Implementation.Plugin";
}

The plugin (MyAddin.Implementation, references BasAutomation.Inventor.Core):

public class Plugin : RibbonPluginBase
{
    public override string AddInClientId => "A35BF192-8E9E-4596-AEA6-54F645056AE6";

    protected override Type GetAppConfigType() => typeof(AppConfig);

    // Every CommandDefinition in this assembly goes on the ribbon.
    protected override void LoadCommandDefinitions() =>
        CommandDefinitions.AddRange(new CommandDefinitionFactory(typeof(Plugin).Assembly).GetCommandDefinitions());

    public override void ConfigureServices(HostBuilderContext context, IServiceCollection services)
    {
        LoggingHelpers.AddLoggingInSubDirectory(services, "MyAddin");   // %APPDATA%\MyAddin\logs
        services.AddSingleton<IPartNumberReader, PartNumberReader>();
    }
}

A command: where it goes on the ribbon, and what it does.

public class PartNumberCommandDefinition : CommandDefinition
{
    private static readonly RibbonTabDefinition Tab = new("My Tools");
    private static readonly RibbonPanelDefinition Panel = new("Info");

    public PartNumberCommandDefinition()
    {
        RibbonLocations.Add(new RibbonLocation(RibbonEnvironment.Part, Tab, Panel));
        RibbonLocations.Add(new RibbonLocation(RibbonEnvironment.Assembly, Tab, Panel));
        Command = new PartNumberCommand();
    }

    public override IInventorButtonCommand Command { get; }
}

public class PartNumberCommand : ServiceAwareButtonCommandBase
{
    public override string DisplayName => "Part number";
    public override Icon Icon => Resources.PartNumber;

    public override bool CanExecute() => InventorClient.HasActiveDocument;

    public override void Execute()
    {
        var doc = InventorClient.GetActiveEditDocument();
        MessageBox.Show(doc.GetPropertyValue(InventorPropertyName.PartNumber)?.ToString(), DisplayName);
    }
}

The template wires all of this up, including the .addin manifests, the app bundle and the build targets that deploy it to ApplicationPlugins.

What's in it

BasAutomation.Inventor.Core

Plugin and ribbon

  • PluginBase: implements ApplicationAddInServer; on activation builds the Generic Host (configuration, DI, logging), calls ConfigureServices, and writes an error log if activation fails.
  • RibbonPluginBase: creates tabs, panels and buttons from your CommandDefinitions, in the environments you list (ZeroDoc, Part, Assembly, Drawing), reusing tabs and panels that already exist, and removes them again on unload. IRibbonPanelOverride takes over the layout of a single panel.
  • CommandDefinitionFactory: finds every CommandDefinition in an assembly.

Commands

  • ServiceAwareButtonCommandBase: a ribbon button with GetService<T>() and CreateScope() into the add-in's container, CanExecute(), DisplayName, Description, ToolTip and Icon. Exceptions from Execute() are caught and logged by the ribbon.
  • PictureDispConverter: .NET Icon/Bitmap to the IPictureDisp Inventor wants.

Talking to Inventor

  • InventorClient: the Application, plus helpers: GetActiveEditDocument<T>() (the part being edited in place, not just the active assembly), CreatePart/Assembly/Drawing, OpenModel, default templates, TransientGeometry/TransientObjects, RunRule for iLogic.
  • Outside Inventor (console apps, tests): InventorClient.Connect() attaches to a running Inventor, ConnectOrStart() starts one if needed, ConnectDedicated() starts a private, optionally headless instance so parallel runs don't share a session.
  • InventorTransaction.Wrap(() => ..., doc, "Name"): one undo step for many changes.
  • SilentOperation.Wrap(...): no dialogs during batch work.
  • InventorStatusBarProgressBar, InventorModalProgressBar: Inventor's own progress bars.

iProperties

  • InventorPropertySetName, InventorPropertyName and the typed DesignProperties, SummaryProperties, DocumentSummaryProperties.
  • doc.GetPropertyValue(...), doc.SetProperty(...), GetOrCreateCustomProperty, GetCustomPropertyValue.

WPF inside Inventor

  • InventorWindowIntegrationHelper: host a WPF window in an Inventor dockable window.
  • InventorShellStatusBridge: status and progress from your WPF window also show in Inventor's status bar.

BasAutomation.Inventor.Loader

  • RibbonPluginShim: the COM-visible entry point. It loads the implementation assembly and its dependencies from a runtime folder into a private AssemblyLoadContext and forwards every ApplicationAddInServer call to it.
  • WPF control libraries that can only exist once per process are shared with the copy that is already loaded, if its major version matches.
  • build/Shim.targets and build/Implementation.targets: the COM host, the per-Inventor-version output, the .NET 8 (2024-2026) / .NET 10 (2027) runtime folders, and the deploy to C:\ProgramData\Autodesk\ApplicationPlugins\<Bundle> on every local build (skip it with -p:DevDeployBundle=false).
  • Manifest2024Base ... Manifest2027Base: the .addin manifest per Inventor version.
  • A loader log in the add-in's log folder, for when the add-in fails before its own logging starts.

BasAutomation.UI

  • ShellWindowBase + ShellViewModelBase: a window with a navigation frame and a footer for status and progress (IShellStatusService).
  • INavigationService + IPageService (services.AddPage<TViewModel, TPage>()): navigate by view model; pages implement INavigationAware to load their data.
  • IWindowService: opens windows from the container and remembers their position and size.
  • IDialogService (confirm, info, error, open/save file), IFileService (JSON read/write).
  • ViewModelBase (CommunityToolkit.Mvvm), converters (TrueToVisibility, EnumToDescription, RadiansToDegrees, CentimetersToMillimeters, ...) and base styles.

BasAutomation.Logging

  • LoggingHelpers.AddLoggingInSubDirectory(services, "MyAddin"): Serilog to %APPDATA%\MyAddin\logs, wired into ILogger<T>.
  • LoggableBase: a logger for classes that aren't created by the container.

Requirements

  • Autodesk Inventor 2024, 2025, 2026 or 2027, installed. The projects compile against the interop in C:\Program Files\Autodesk\Inventor <version>\Bin\Public Assemblies; Autodesk's interop is not redistributable, so it is not in this repo.
  • .NET 8 SDK (and the .NET 10 SDK for Inventor 2027).

Build

dotnet build BasAutomation.sln -c Release

On its own this repo builds against Inventor 2024; use -p:InventorVersion=2026 (or another version) to build against that version instead. As a submodule it builds for the add-in's InventorVersion.

Working with AI coding agents

AGENTS.md (and CLAUDE.md for Claude Code) gives an agent the layout of this repo, the rules and the Inventor API traps: database units (cm, kg, radians), 1-based collections, the edit document vs. the active document, transactions for undo, Inventor's thread. Add-ins made from the template get their own agent guide and skills.

Made by Bas Automation Services

These libraries are the foundation of the Inventor add-ins by Bas Automation Services. Need a custom add-in, or help with your own? Get in touch.

More: other open-source projects · articles on the Inventor API · LinkedIn

How this repo is made

This is a mirror of the libraries Bas Automation Services develops and uses in its own add-ins. Each release is one commit. Issues are welcome; pull requests are applied by hand in the source repo and come back with the next release.

Licence

MIT, see LICENSE.

About

Open-source C# libraries for Autodesk Inventor add-ins (2024-2027): ribbon and command base classes, an isolated add-in loader, WPF shell, logging. AI-agent ready.

Topics

Resources

Stars

4 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages