🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
Plugin Development Guide
This page was created by Wikiadmin on 2026-07-29. Last edited by Wikiadmin on 2026-07-29.

You can create a MDriven Designer or MDriven Framework Visual Studio extension plugin when you need to add design-time commands, react to code generation, or make custom OCL operations available to model validation and ViewModels.

Choose the right plugin

This guide covers Modlr plugins: .NET assemblies that extend MDriven Designer and the MDriven Framework Visual Studio extension. It does not describe the MDriven Turnkey Excel Plugin, which is an Excel add-in for working with an existing Turnkey application.

For example, use a Modlr plugin to add a context-menu command that checks model classes for a naming rule. Do not use it to download a Turnkey grid into Excel; that is the purpose of the Excel Plugin.

Extension points

A plugin implements IModlrPlugin to provide one or more context-menu operations. An operation implements IModlrPluginMenuOperation.

Extension point Implement when you need to Example
IModlrPlugin Register the plugin and its menu operations. Return an operation named Operation on class.
IModlrPluginMenuOperation Add a context-menu operation and decide whether it is enabled. Enable the operation only when the selected object is an Eco.ModelLayer.Class.
IModlrPluginImportantEventCallbackHandler Run logic before or after code generation. Check the model before code generation and stop it by setting stop.
IModlrPluginModelAccessOclType Register a custom OCL operation for design-time and runtime model access. Register SplitAtSemi so an expression can return the text before the first semicolon.

Build a context-menu plugin

  1. Create a .NET assembly that references the MDriven assemblies from the MDriven installation directory. Use the MDriven about box to locate that directory.
  2. Implement IModlrPlugin and return the operations that the plugin provides.
  3. Compile the assembly.
  4. Put the compiled assembly in the MDriven plugins folder.
  5. Restart MDriven Designer or Visual Studio.

The following example registers one operation. The operation is enabled only when the main context is a model class. When executed, it appends X to that class name.

using System.Collections.Generic;
using Modlr.Plugins;

public class DemoPlugin : IModlrPlugin
{
    public string GetName()
    {
        return "Demo plugin";
    }

    public List<IModlrPluginMenuOperation> ProvideOperations()
    {
        return new List<IModlrPluginMenuOperation>
        {
            new OperationActOnClass()
        };
    }
}

public class OperationActOnClass : IModlrPluginMenuOperation
{
    public void CheckEnableOrExecute(
        IEcoServiceProvider esp,
        bool execute,
        IEcoObject maincontext,
        IEcoObject subcontext,
        out bool enabled)
    {
        enabled = false;
        if (maincontext != null &&
            maincontext.AsIObject().AsObject is Eco.ModelLayer.Class)
        {
            enabled = true;
            if (execute)
            {
                (maincontext.AsIObject().AsObject as Eco.ModelLayer.Class).Name += "X";
            }
        }
    }

    public string GetName()
    {
        return "Operation on class";
    }
}

After you restart the host application, find the operation in the context menu. The enabled result prevents the command from being available when the current context is not a class.

Work within the model boundary

The context passed to a menu operation gives the plugin access to the loaded model. A plugin can inspect model objects such as diagrams, placed classes, state machines, tagged values, and attributes. For example, a command can iterate through attributes and report spelling errors, or inspect tagged values before generating a report.

Keep the operation focused on the current model context. Use the maincontext and subcontext arguments to decide whether the operation applies before changing model objects.

React to code generation

Implement IModlrPluginImportantEventCallbackHandler when the plugin must run around code generation.

In ImportantEventAboutToHappen, perform checks before code generation. Set stop and provide a message when the check must prevent generation. Use ImportantEventHasHappend for work that must run after the event.

Add a custom OCL operation

Implement IModlrPluginModelAccessOclType when a plugin defines an OCL operation. Register the operation through RuntimeModelAccess.

public void RuntimeModelAccess(IOclTypeService ocl)
{
    ocl.InstallOperation(new CustomOCL_SplitAtSemi());
}

A custom operation defines its name and input and result types in Init, and evaluates its result in Evaluate. For example, SplitAtSemi can accept a string such as "Ada;Lovelace" and return "Ada".

Assembly version requirement

In newer MDriven builds, use ModlrPlugins, MDriven.Handles, and other design-time assemblies from the installed Visual Studio extension (VSIX), not the NuGet packages. The VSIX assemblies are not published through NuGet.

A VSIX installation path resembles c:\users\<user>\appdata\local\microsoft\visualstudio\<VSVersion>\extensions\<random>\. Use assemblies from that installation when building a plugin for the Visual Studio extension.

See also