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.
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 well documented in MicroStation's delivered help manuals.
This article focusses on the formal programming languages provided with MicroStation: VBA, MDL, BASIC, JMDL and the less-formal UCMs.
Bentley Systems provide several programming languages to enable the development of extensions to MicroStation. Languages include …
There's also a Comparison of VBA and BASIC.
For in-house development, use VBA or MDL. Avoid the following languages, and prefer the recommended alternative …
For commercial development, use MDL. MDL provides a robust development toolset, albeit not with the most up-to-date Interactive Development Environment (IDE), with an intimate association with MicroStation internals. Although VBA provides significant functionality, there are certain security aspects of the language that make it unattractive to commercial developers.
An MDL 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.
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.
The Bentley Institute offers training in many Bentley technologies, including MicroStation VBA and MDL.
LA Solutions offers training and consultancy in VBA and MDL.
Contact LA Solutions using this
enquiry form.
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 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 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.
You can call the Windows Win32 API from VB and VBA. 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.
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.
The introduction of MDL with MicroStation V4 was a big step forward. MDL introduced a flexible, event-driven user interface and programming tools to match.
You can write an application using the Visual Studio IDE 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.
MDL continues to offer the most versatile development tool at the expense of complexity and a requirement to understand the C language …
UCMs were developed by Intergraph Corporation in about 1980 as a low-level macro capability for their Interactive Graphic Design System (IGDS). 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/J introduced the Java MicroStation Development Language (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 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 …
.ba files are prone to inadvertent deletion
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.
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.
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.