Building a Simple Add-in Application


In this chapter, we will build the simplest Hello World Add-in application from scratch step by step, which can be loaded and run in Mstn.

  1. Open Visual Studio and select the menu File> New> Project or directly press the shortcut key Ctrl+Shift+N to pop up a new project. Click Visual C# on the left side of the form, and click Bentley > MicroStation > Connect Edition > MDL Command on the right side. Then select the project path and enter the project name, and finally confirm that the .NET Framework is set to 4.6.1 before clicking the OK button. After that, a user interface appears. On the left is the automatically generated C# code, and on the right is the Solution Explorer form.

2.  Select Project > csAddins and then Properties to open the project properties window. After that select, the Output path on the Build page and click the Browse button to browse to the Mdlapps folder under your MicroStation CE directory.By default, Mstn path is set to C:\Program Files\Bentley\MicroStation CONNECT Edition\MicroStation\Mdlapps\. (If your Addins DLL file is not generated in the Mdlapps folder but in a folder you specify, you need to set the configuration variable MS_ADDINPATH to point to the path you specify if you want to load it in Mstn.)

3. Modify the references in the project. In this step, we will refer to the .Net libraries that will be used frequently in the future development process .

Note: NET applications uses the demand-loading mechanism. When .Net loads our DLLs, we do not rely on all DLLs at the same time. All of the DLLs are loaded, but a corresponding DLL will be loaded when the code that references the objects in other DLLs is executed. So even if our project references a lot of NET libraries, if the objects in the library are not used, the extra DLL will not be loaded. Even if it is used, it will not be loaded if the thread does not run to the corresponding code.

Note: If you only implement a dialog that can load programs and display a Hello World in MicroStation, you can only refer to the last DLL (i.e., ustation.dll). The Bentley.MstnPlatfomNet.Addin object is included in this ustation.dll file. However, for future extensions of the program, including all the above DLLs will make your future programming work less of a concern about which DLLs to add.

The final list of references is shown below: 

To enable a .NET assembly to run as an Add-ins under MicroStation, the following three conditions need to be met:

4. Select Build > Build Solution from the menu to generate this solution. When you see the following message in the output window of VS, you have successfully created a MicroStation Add-in. If you, unfortunately, see 0 succeeded, x failed message, you need to carefully check the above steps. Looking at the error description in the output window will also help you find the problem.

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

5.Now to verify our Add-in program, Please start MicroStation, click on the icon as shown below to open the key-in window (or open it via F9 shortcut). Type MDL LOAD csAddins in the typing field and press Enter. At this point, you should see a message saying, "Hello World!" in a dialog box.

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