Home > Geoespatial / GIS > Developing VBA applications with MicroStation

Developing VBA applications with MicroStation

TRANSLATION NOTES: Please read some comments at the end of this post.

To make applications, Microstation supports different languages, including Microstation Development Language (MDL) which is preferred by the Bentley’s gurus. It also supports old Basic since many years ago and once supported Java, hence that version called Microstation J.

But to develop with pleasure and without much back, it is more practical to work on the Visual Basic module that comes with the program; in versions prior to XM (8.9) includes a Visual Basic 6.3 full editor, in the latest versions, it goes further.

clip_image001

How to start the job

It is clear that someone who has no idea of programming does not have much to do. However, for someone who understands object-oriented programming, and has played with Visual Basic 6, will be find almost died laughing. With the program usually come a few examples, but here is the trick I’ve seen being used by the technicians: The use of macros.

Microstation facilitates routine’s storing in the form of a mvba extension macro; seeing the code facilitates starting in the way how it operates Microstation programming rather than beginning from scratch (*). For now I’ll use Mexican friends’ example, who last week asked me to help them with theming in Geographics.

How a macro will be created.

Utilities > macro > project manager.

clip_image002

Here you create a new project, and is assigned a name. Usually there are stored in Program Files / Bentley / workspace / projects / vba but you can select any destination.

clip_image003

How it will be saved.

To start recording, press the blue wheel icon. The program saves everything made from there onwards.

For example: Place a fence from the view, turn off all levels except the block boundaries and centroids, move boundaries links to centroids, create shapes at level 62, turn off the borders, remove links from centroids to shapes, load command for theming, theming according to the sector in which are placed the blocks with a specific color for each sector, place the legend.

The process can be stopped on pause, or end with the red square icon. If you press the play button, the program will run the full routine as it has been saved. The utility of this even without programming is very interesting if it can be taken advantage, I have seen menus done only with macro made by non-programmer people.

If you want that each time we run Geographics the macro will be loaded, it will be activated the fourth column labeled Auto-load, and that will create a variable in the msgeo.ucf file.

How the code is edit.

To see the code, press the button that opens the Visual Basic editor.

clip_image004

Everything is saved as a single module, but in case of making it step by step, it is facilitated the integration of statements. You can also run with the step by step option, which would let the implementation in stages as a debugger.

clip_image005

The example I’m showing that has already been worked by the Mexican’s(**) friends, includes separately, modules to ensure the database connection, the performing linked routine, the creation of related entities, the application of a theme and one for global configurations. The code can take password, which prevents the operator to cause a disaster or facilitate the separation of class libraries that we don’t wish to share with the user programmer.

TRANSLATION NOTES:

(*) hacerse mangas la camisa desde cero. It’s a Spanish Idiom which means to begin since scratch.

(**) charro. It’s a colloquial way to refer to a Mexican citizen.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.