MicroStation®

MicroStation is Bentley Systems' premier 3D/2D computer-aided-design product. One of its many strengths is its adaptability. Inherent to that adaptability are tools to customise and extend MicroStation.

User Customisation

MicroStation lets an administrator modify its user interface. You can create custom menus, toolboxes, and icon buttons that provide a fast track to commands and functions that you use frequently. You can store those customisations in a DGNLIB that you make available to all your users, so that everyone has the same user interface and task-specific tools. These customisation tools are not discussed further here: they are well documented in MicroStation's delivered help manuals.

Application Development

This article is written for application developers. It focusses on the formal programming languages provided with MicroStation: VBA, MDL, BASIC, JMDL and the less-formal UCMs.

If you are developing for Bentley PowerDraft, see these comments for PowerDraft developers.

VBA, MDL, MicroStationAPI, BASIC, UCM

Bentley Systems provide several programming languages to enable the development of extensions to MicroStation. Extensions are also known as Plug-Ins or Add-Ins. Development languages for MicroStation V8 include …

Current Development Languages
Visual Basic for Applications VBA™ or MVBA
C# and VB.NET .NET
MicroStation Development Library MDL
MicroStationAPI C++ Interface

Older versions of MicroStation provided languages that are no longer used for new development. Deprecated development languages are …

Deprecated Development Languages
MicroStation BASIC Not compatible with VBA
MicroStation Java JMDL
User Command Macros UCMs

Prefer VBA to BASIC. We compare MicroStation VBA with MicroStation BASIC.

Development Strategies

For in-house development, use VBA or MDL.

Avoid the following languages, and prefer the recommended alternative …

For commercial development, use MDL and the MicroStationAPI. MDL provides a robust development toolset. From MicroStation V8i Bentley encourages us to use Visual Studio 2005 as the primary development tool, writing code in Visual C++ v8. In this case, consider the MicroStationAPI: it provides a set of C++ classes that either add new functionality or supplant some MDL functions.

The Bentley MDL development tools don't have the most up-to-date Interactive Development Environment (IDE). However, from MicroStation V8 it's possible to use Visual Studio as a development tool, where the IDE is Microsoft Visual Studio.

Although VBA provides significant functionality, there are certain security aspects of the language that make it unattractive to commercial developers.

Performance

An MDL or MicroStationAPI application written using Visual C++ always wins. Why? Because MDL is MicroStation's optimised API, and C++ is compiled using Microsoft's optimising compiler. With that combination, you have the best performing code. If your application need to do heaps of number crunching, then an MDL project built using Visual C++ will provide the best result.

Here's what Herb Sutter has to say about C++ and performance. This citation is taken from Dr Dobb's Interview with Herb Sutter …

Managed languages are perfectly appropriate where your goal is to optimize programmer productivity above all else, even at the cost of performance by having always available garbage collection that you can't turn off, always available metadata, always available JIT execution, and a virtual machine whether you're actually using it or not, you bear the cost. But, you make the programmer so much more productive. Great. That's what you should optimize for if your biggest cost and constraint is programmer productivity. But more and more, at least part or all of your of your application needs to optimize for performance per dollar, or performance per watt, performance per transistor – because you can only put so many of them in a device. And that's why C++ is the preeminent language, because it's the king of performance per dollar. That's why it's making a comeback.

Second-best is pure MDL compiled using Bentley's own compiler. Compiled MDL is not Windows native code, but offers good performance.

VBA is interpreted code. It has a high overhead in procedure calls and especially when invoking object references (i.e. anything that requires a Set statement). However, VBA provides a comfortable and fast development environment. If speed of development is important to you, then VBA is a good choice. If application performance is important to you, then VBA is a good way to prototype an application before turning it over to the MDL experts.

MicroStation Java's performance is neither here nor there, since it's obsolescent. As interpreted code, it never was as fast as MDL.

MicroStation BASIC (not VBA) provides neither a developer's dream toolkit nor Formula 1 performance. If you're starting a new project, leave MicroStation BASIC snoozing in the old programming languages rest home.

UCMs? Not even Intergraph Corporation claimed any performance from UCMs, and the development environment (a text editor) is not what we expect in the 21st century.

Training

The Bentley Institute offers training in many Bentley technologies, including MicroStation VBA, MDL and the MicroStationAPI.

LA Solutions offers training and consultancy in VBA, MDL and the MicroStationAPI. Contact LA Solutions using this enquiry form.

Visual Basic for Applications

The introduction of VBA with MicroStation V8 was a big step forward. Bentley Systems have licensed Microsoft's Visual Basic for Applications Toolkit and extended it to provide MicroStation-specific functionality.

VBA's IDE

VBA is …

MicroStation VBA shares its interactive development environment (IDE) with VBA implemented in other applications. In other words, if you've used the IDE with MicroStation VBA, you already know how to use VBA with other products, including Microsoft Office tools such as Word™ and Excel™. The IDE is similar, though not identical, to that of Microsoft Visual Basic.

One of MicroStation VBA's many strengths is extensibility. You can create a generic project (a .mvba file) that provides functions and methods you want to use many times. By referencing one project into another you can call the referenced procedures: you don't have to copy them or write them again. You can also add functionality in an ActiveX component, which is a DLL created using Visual Basic. There are a few more benefits obtained from creating an ActiveX component in this way. Not only can you reuse the functionality in VBA, but also in other VB projects.

MicroStation VBA also provides the necessary COM interface that other applications can use. In other words, you can write a VB or VBA program in some other application, such as Microsoft Word™ or Excel™. By referencing the MicroStationDGN.Application object, other VB/VBA code can invoke MicroStation functionality.

There is a number of articles about MicroStation VBA.

Future VBA Implementations

For a long time, Microsoft has told us that VBA is old-fashioned and we should convert to VB.NET. However, their own Office products include VBA, and have done so for many years. Despite Microsoft's own words of advice, VBA remains in Office. What you may not have noticed, because Microsoft has chosen not to publicise it, is that VBA7 has arrived!

Yes, Office 2010® includes VBA 7! VBA 7 works in both 32-bit and 64-bit environments. More accurately, there are both 32-bit and 64-bit versions of VBA 7.

MicroStation V8 provides VBA 6.4 (MicroStation CONNECT provides VBA 7.1).

Windows Win32 API

You can call the Windows Win32 API from VB, VBA and MDL native-code. You may want to make Win32 API calls to use features of Windows that are not exposed by VB. To learn more about Win32 API possibilities, we recommend that you search the web for sites that offer VB/VBA examples and help.

MDL API

The MDL API reference documentation includes VB procedure declarations for most MDL functions. For example, MDL function mdlModelRef_isReadOnly is documented as having this VB declaration …

VBA Wrapper Declaration
Declare Function mdlModelRef_isReadOnly Lib "stdmdlbltin.dll" ( ByVal modelRef As Long ) As Long

Simple functions like the above example are safe to use in VBA. However, many MDL functions deal with C memory management, including pointers and pointers-to-pointers. VBA as a language knows nothing about pointers, pointer arithmetic, or memory allocation and memory deallocation. Using such functions from VBA is rather like giving someone a map of Paris, France and asking them to use that map to find an office in Los Angeles, California.

In general, it's wise to stay clear of any MDL function that requires you to allocate memory. For example, mdlElmdscr_read reads an element and allocates memory pointed to by an MSElementDescr* pointer. At some time you must deallocate that MSElementDescr block of bytes using mdlElmdscr_freeAll. Debugging hybrid code is a nightmare. If you fail to free that memory, your code will at best leak memory or, worse, crash MicroStation.

Because VBA knows nothing about C memory management, it can't respond when things go wrong. If, through VBA, you cause a memory problem, there's no way to handle it. Usually a memory problem results in a MicroStation crash, and you don't know what part of your code caused it nor why it happened.

As a rule-of-thumb, if you find the need to use more than four or five MDL functions in your code, it's time to re-think your development strategy. Using the wrong tools for a job, as we learn from experience, leads to a poorly-executed job. The right tool for the job gets the job done efficiently, in a timely fashion, and is easily maintained. The right tool for the job in this case is a real MDL application.

C# and VB.NET

Microsoft .NET languages provide a rich user interface. Its IDE has of course excellent support for the .NET languages C# and VB.NET. Visual Studio .NET includes useful database and XML development tools. The LINQ technology provided with .NET 3.5 and later enhances productivity enormously.

You can write a COM server (ActiveX component) using .NET, then call it from your VBA or C++ code. This enables programmer productivity using Visual Studio combined with simple MicroStation interfacing via VBA.

When writing a .NET application that works with MicroStation, you use the COM server provided by MicroStation VBA. You use the .NET InterOp technology to create a reference to MicroStationDGN.Application. In other words, from the functional point of view, .NET doesn't offer anything more than that which can be written using VBA. However, the richness of the user interface and the Visual Studio IDE may sway you in favour of Microsoft's latest offering.

MicroStation V8i provides some C# examples in the MDL examples \DotNet\Examples folder.

MicroStationAPI

The MicroStationAPI is C++. Its functionality in some cases supersedes what is available through MDL. In other cases the MicroStationAPI provides functionality not available elsewhere.

Because it is C++, the MicroStationAPI can be used only for applications that are built using a C++ compiler and linker. You can continue to use MDL functions in the same source code as MicroStationAPI classes, so you get the best of both worlds.

The MicroStationAPI is …

There are a number of articles about the MicroStationAPI.

MicroStation Development Library

The introduction of MDL with MicroStation V4 was a big step forward. MDL introduced a versatile, event-driven user interface and programming tools to match.

You can write an application using Visual Studio and call MDL functions from your C++ code. From the introduction of MicroStation V8, MDL code can be compiled using Microsoft Visual C++ as a native-code DLL. This both enhances programmer productivity through the use of C++ object-oriented concepts and provides better performance. When writing C++, you can additionally take advantage of the MicroStationAPI.

MDL continues to offer the most versatile development tool at the expense of complexity and a requirement to understand the C++ language …

There are a number of articles about the MicroStation Development Library.

In order to create a MicroStation application using MDL and/or the MicroStationAPI, you should understand at least five of the following …

  1. MicroStation
  2. 2D and 3D vector algebra
  3. The C language
    • The C++ language if planning to use the MicroStationAPI
  4. Visual C++ 2005
  5. Your user requirements

User Command Macros

User Command Macros (UCMs) were developed by Intergraph Corporation in about 1980 as a low-level macro capability for their Interactive Graphic Design System (IGDS). In the twenty-first century, UCMs have few advantages but several disadvantages. Variable names are restricted to two characters and there is a limited number of registers for data storage. Disadvantages include …

MicroStation Java

MicroStation/J introduced the Java MicroStation Development Library (JMDL). JMDL enabled one to develop and run either pure Java or JMDL code in MicroStation's Java Virtual Machine (JVM). JMDL added MicroStation-specific extensions to the Java language to integrate with the graphics engine and state machine.

JMDL continued to be supported by MicroStation V8 but was not developed further. Like MicroStation BASIC, JMDL reached an evolutionary dead-end.

MicroStation BASIC

MicroStation BASIC was introduced in 1996 with MicroStation 95. Like JMDL, BASIC reached an evolutionary dead-end. Although more useful at the time than UCMs, BASIC has its drawbacks, including …

MicroStation BASIC 's dialog design tool is unusual. At best, it's a compromise; at worst, it's infuriating. Worse yet, dialogs are stored in your macro's compiled .ba file. Why is that bad? Because the .ba is updated each time you run your modified .bas code during development, you may regard the .ba as temporary. If, in a fit of tidying, you decide to delete a bunch of .ba files, you will discover subsequently that each macro's dialog boxes have also been tidied into the dustbin of eternity.

MicroStation BASIC continues to be supplied with MicroStation V8 but was not developed further. Like MicroStation Java, BASIC reached an evolutionary dead-end.

Prefer MicroStation VBA to BASIC

The foundation of MicroStation VBA is the same as other VBA implementations. That means if you can use VBA in one product, such as Microsoft Excel, you will find it easy to learn VBA in another product, such as MicroStation.

VBA has a better user interface than MicroStation BASIC: it's easier to design forms & dialogs, and there's a wealth of widgets available either in the product or externally.

VBA has better help, more examples, and an enthusiastic user community, notably in the Be Communities MicroStation Programming Forum .

How to Distinguish MicroStation BASIC from VBA

It's easy for beginners to become confused about MicroStation BASIC and MicroStation VBA (MVBA). They are both developed from the BASIC language, but VBA is substantially more capable than MicroStation BASIC. VBA is compatible with a number of other Microsoft technologies, whereas BASIC is not.

Many MicroStation BASIC keywords (function and variable names) begin with Mbe or MBE. If your code includes lines like Dim origin As MbePoint then you have an example of MicroStation BASIC.

Bentley PowerDraft®

Bentley PowerDraft is Bentley Systems' lower cost 3D/2D computer-aided-design product. PowerDraft supports VBA, MDL, and native-code DLLs just as MicroStation does. However, although it includes the VBE development environment it includes no MDL or MicroStationAPI development tools. Rather, you develop applications for PowerDraft using MicroStation as the development platform.

A further complication is created by two restrictions on PowerDraft that affect developers …

For more information, contact Bentley Systems.