MicroStation is Bentley Systems flagship 3D computer-aided-design tool. Developers can customise MicroStation using one of several Application Programming Interfaces (APIs). This page lists some solutions to common MicroStation VBA (MVBA) problems. Tips are published as examples and are not necessarily working code.

Be Communities

A good place to post questions about MicroStation VBA is the Bentley Communities MicroStation Programming Forum.

Introduction

When working with planar shape elements, we sometimes want to merge them in some way. The term 'merge' is an informal description. The formal description is a boolean operation. Boolean operations on planar shapes include union, intersection and difference.

Here's an example. Given two coplanar overlapping shapes (one red, one blue) …

Candidate Shapes

Here are the results of performing a boolean operation on those shapes. In each case, the purple shape shows the result of the operation …

Shapes Difference Shapes Intersection Shapes Union
Difference Intersection Union

Q How do I merge two shape elements using MicroStation VBA?

A Similar questions crop up now and then on the MicroStation Programming Forum. We wrote the example Boolean Operations to illustrate one approach.

Boolean Operations Dialog

Shape Selection

The buttons labelled Locate Shape 1 and Locate Shape 2 each starts a primitive command class that Implements ILocateCommandEvents. The locator class is restricted to finding MicroStation ShapeElements. It writes each element's ID on the VBA UserForm.

Boolean Operations

The buttons in the group labelled Boolean Operations each performs a boolean operation on the two identified shapes. The result of the operation is added to the active DGN model.

Download Example Project

You can download the example VBA Boolean Operations project.

Copy the .mvba file to a known good location where MicroStation looks for VBA macros. For example, \Workspace\Standards\vba or anywhere that configuration variable MS_VBASEARCHDIRECTORIES includes.

Open the project in the VBA editor. Read the notes in module modMain. That module also contains the keyin to run the example …

vba run [BooleanOps]modMain.Main

Questions

Post questions about MicroStation programming to the MicroStation Programming Forum.