Introduction
Bentley MicroStation is a CAD software product for two and three dimensional design and drafting. It provides you an extensible framework using which you can easily customize and add new functionalities to it as per your requirements. To develop any of MicroStation based applications, the first step is to configure your development environment. In this post, I will provide you a step by step guide to configure environment for MicoStation based application development.
Pre-requisite
The first thing you need is to install all the Pre-requisite Software:
- Visual Studio 2005 or later
- MicroStation
- MicroStation SDK
You can use any version of MicroStation and its compatible SDK but the one I am using at the time of writing this blog is 08.11.09.357.
Configure Development Environment
Once you are done with all the pre-requisite installations, the next step is to configure your development shell with all the required paths. There is a “MicroStation Developer Shell” shortcut under MicroStation Station SDK in “All Programs” menu but I prefer to use the simple “Command” shell for this purpose. This is because the required parameters are sometimes missing while calling “MicroStation Developer Shell” from the shortcut menu. Here are the steps to configure a plain “Command line” shell for MicroStation development:
- Launch Command Prompt
- Change directory to location where your MicroStation SDK is installed. In my case, it is installed in “C:\Program Files (x86)\Bentley\MicroStation\”
- The MicroStation SDK folder has “mdl\bin” folder switch to it. For example: C:\Program Files (x86)\Bentley\MicroStation\mdl\bin

Figure 1: Switch to MicroStation SDK bin Directory
- The next step is to call mstndevvars.bat file to configure the required paths. This file requires two parameters
[MicroStation dir] [MicroStation SDK dir]
In my case, MicroStation is installed in:
"C:\Program Files (x86)\Bentley\MicroStation V8i (SELECTseries)\MicroStation\”
And, MicroStation SDK is installed in:
"C:\Program Files (x86)\Bentley\MicroStation\"
Let’s call mstndevvars.bat with the required parameter as follows:
mstndevvars.bat "C:\Program Files (x86)\Bentley\MicroStation V8i (SELECTseries)\MicroStation\" "C:\Program Files (x86)\Bentley\MicroStation\"

Figure 2: Configure MicroStation Development Environment
- That’s all you have to do in order to configure any command prompt for MicroStation based application development.
Build Samples Shipped with MicroStation SDK
MicroStation SDK installs sample applications/Addin for your reference. By default, they get installed in your user document folder under “MDL Projects V8i” folder. They are the best starting point to test whether your development environment is properly configured or not. In addition, these samples are also the best references to help you in developing any custom Addin.
In your MicroStation development configured command prompt, switch the directory to location where MicroStation SDK sample projects are installed.

Figure 3: Switch to MDL Samples shipped with MicroStation
Though you can build all the applications using mdlexampl.mke file but in this case we will just compile “myapp
” for learning purposes.
In MDL Project, there is a sample application named as “myapp
” which demonstrates number of MDL concepts. Let’s build this application as our first MDL sample. To build, we will use bmake
command as follows:

Figure 4: Switch to "myapp" MDL Sample
This command will do the job. In case you get some signing issue, you can use the following command for building “myapp
”:
bmake myapp -a -dDLM_NO_SIGN
Once “myapp
” is successfully compiled, you can find its generated output in MicroStation installed folder under mdlapps
.

Figure 5: Generated output of Sample "myapp" MDL application
Load and Test Sample Application
Now “myapp
” is ready, you can easily load it using mdl
load command from inside MicroStation. Or you can update MicroStation\config\system\applicationload.cfg file to load “myapp
” wherever any Dgn
gets loaded by defining the following macro in it.
MS_DGNAPPS > myapp

Figure 6: Define Micro to load "myapp" when any dgn gets loaded
Configuration variable MS_DGNAPPS
provides a list of MDL applications that MicroStation should load when a new DGN file is opened. An application loaded at this time knows that a DGN file is open.
In case you want to load your application at MicroStation startup, you can use MS_INITAPPS
macro. Configuration variable MS_INITAPPS
provides a list of MDL applications that MicroStation should load at startup. It's similar, though not identical, to the -wa
command-line switch. An application loaded at this time can take over the way that MicroStation starts up. At this time, no DGN file is open. For example, you can replace the MicroStation Manager dialog or run MicroStation with no user interface.
Now, when you will launch MicroStation, you will find “myapp
” dialog with “date, color and line” options as shown in Figure 7.

Figure 7: "MyApp" loaded in MicroStation
Your MicroStation development environment is ready and now you can write your custom applications as per your requirements.
Points of Interest
It is extremely important to understand how one can configure the MicroStation development environment. This is one of the primary steps to start with CAD applications development in MicroStation.