Chapter 1: Building a Simple Add-in Application


 

In this chapter, you'll learn how to build your first MicroStation add-in application from scratch. We'll walk through each step to create a simple "Hello World" application and then load and run it inside MicroStation.

 

  1. Launch Visual Studio

 

      Select Visual Studio 2022 (right click and Run as administrator).

 

  1. Create new project

 

      In Visual Studio 2022, select “Create a new project”.

 

       In the “Create a new project” form,

 

 

Note: The Class Library may have multiple options, select the correct type “Class Library (.NET Framework)”, a C# class library (.dll) as shown below.

 

 

       In the “Configure your new project” form,

 

 

 

 

        On the left is the automatically generated C# code, and on the right is the Solution Explorer form.

 

  1. Set Add-in DLL path

      In the Solution Explorer,

 

 

  C:\Program Files\Bentley\MicroStation 2026\MicroStation\Mdlapps\

        Note: By default, MicroStation searches for Add-ins in the Mdlapps folder.

                 If your Add-in DLL is created in a different location, set the MS_ADDINPATH configuration variable

                   to include the folder containing the DLL before attempting to load it.

 

  1. Add References

 

 

 

  System.Windows.Forms

 

 

…\MicroStation\ustation.dll

…\MicroStation\Bentley.GeometryNET.dll

…\MicroStation\Bentley.GeometryNET.Common.dll

…\MicroStation\Bentley.GeometryNET.Structs.dll

…\MicroStation\Bentley.DgnDisplayNet.dll

…\MicroStation\Bentley.DgnPlatformNET.dll

…\MicroStation\Assemblies\Bentley.Interop.MicroStationDGN.dll

…\MicroStation\Assemblies\Bentley.MicroStation.dll

…\MicroStation\Assemblies\Bentley.MicroStation.Interfaces.1.0.dll

…\MicroStation\Assemblies\Bentley.MicroStation.Ribbon.dll

…\MicroStation\Assemblies\Bentley.MicroStation.WPF.dll

…\MicroStation\Assemblies\ECFramework\Bentley.General.1.0.dll

…\MicroStation\Assemblies\ECFramework\Bentley.Platform.dll

…\MicroStation\Assemblies\ECFramework\Bentley.UI.dll

…\MicroStation\Assemblies\ECFramework\Bentley.Windowing.dll

…\MicroStation\Assemblies\ECFramework\Bentley.EC.Persistence3.dll

…\MicroStation\Assemblies\ECFramework\Bentley.ECObjects3.dll

…\MicroStation\Assemblies\ECFramework\Bentley.ECSystem3.dll

…\MicroStation\Assemblies\ECFramework\Bentley.ECObjects.Interop3.dll

 

          Note: If you only want to load programs and display a “Hello World” dialog box in MicroStation,

                     you can simply refer to the ustation.dll. The Bentley.MstnPlatfomNet.AddIn object is

                     included in this ustation.dll file. However, for future program expansions, including all

                     the above DLLs mean you don’t have to worry about which DLLs to add. 

 

         .NET loads DLLs on demand, so referenced libraries are only loaded when code uses their objects.

         Unused libraries, or code paths that are never executed, will not cause the corresponding DLLs

         to be loaded.

 

        The final reference list is shown in the figure below:

 

  1. Rename “Class1.cs”

 

      Right-click “Class1.cs” in the solution browser and select Rename from the pop-up menu,

      then change “Class1.cs” to “MyAddin.cs”.

 

      Please select Yes to confirm the rename.

 

      Note: This step is not required, but it's best to do it.

 

  1. Modify “MyAddins.cs” and add the following code.

 

 

 

using Bentley.MstnPlatformNET;
using System.Windows.Forms;

namespace csAddins
{
    internal sealed class MyAddin : AddIn
    {
        public static MyAddin Addin = null;

        private MyAddin(System.IntPtr mdlDesc) : base(mdlDesc)
        {
            Addin = this;
        }

        protected override int Run(string[] commandLine)
        {
            MessageBox.Show("Hello World!");
            return 0;
        }
    }
}

 

       The .NET assembly must meet the following three conditions for it to run as Add-in under MicroStation:

 

  1. Build Solution

 

      Under menus, select Build > Build Solution to compile the solution.

 

      When you see the following information in the VS output window, it means you have

      successfully created an MicroStation Add-in. 

    ========== Build All: 1 succeeded, 0 failed, 0 skipped ==========

 

      If you unfortunately see a message as

    ========== Build All: 0 succeeded, x failed ==========

 

      Checking the error descriptions in the output window can help you identify the problem.

 

 

  1. Run your Add-in program

 

 

 

 

 

    We have successfully created and loaded our first Add-in.

 

    You can download the source code for this wiki here.

 

If you plan to create similar projects in the future, consider turning this project into a Visual Studio template. This allows you to quickly create new projects with the same structure, settings, and references already in place. Check out the following link for detailed instructions on how to create and use a Visual Studio project template.

Create project templates.

 

 

 

Prev: Introduction and Prerequisite Next: Creating Elements in Add-in