Questions similar to this appear on the Bentley Discussion Groups. This problem appeared in the MicroStation Forum.

Q

This project arose after a MicroStation user asked, on the MicroStation Forum, if there is a macro available to draw a grid. There was a BASIC macro for MicroStation V8, inherited from the last century. However, BASIC is not supported in MicroStation CONNECT. The GeoGrid project is the result: a freeware macro to draw a grid in MicroStation CONNECT.

A GeoGrid is the solution. GeoGrid shows a dialog where you can change a few settings, and prompts you to place two corner points. Then it draws your grid …

Annotated grid created by GeoGrid

Introduction

This article describes a MicroStation VBA project GeoGrid.mvba. You don't have to be a VBA whizz to use this macro: just key-in the MicroStation command to load the VBA project.

If you're not interested in the VBA internals, skip the next few paragraphs. Head straight for the download area!

VBA Project Contents

The project includes several modules …

  1. modMain, which contains the main entry point
  2. A UserForm frmGeoGrid
  3. A datapoint capture class clsSolicitCornerPoint
  4. A class to clsGridLine draw and annotate a grid line
  5. Code module modFormat that contains the code use to format grid labels
  6. Code module modOriginal that contains original BASIC code from which GeoGrid derives
GeoGrid dialog

Class SolicitCornerPoint

clsSolicitCornerPoint is a primitive command class that Implements IPrimitiveCommandEvents. Its purpose is to obtain two user-supplied corner points that define the grid extent.

This tool draws a temporary shape to help you place the corner points …

GeoGrid: place corner points

Class GridLine

clsGridLine is a class that encapsulates the methods require to draw and annotate a grid line. It is called repeatedly by subroutine CreateGrid in modMain.

GeoGrid UserForm

The GeoGrid UserForm captures user requirements. It needs to know the grid interval — the distance between two grid lines — in order to calculate the grid placement. You can choose a DGN level on which to place the grid, and a DGN Text Style to use for the annotation.

Annotation Text Style

Create a MicroStation Text Style for the grid annotation. The text size should be appropriate for your grid — GeoGrid doesn't scale the text. The text justification should be right centre justified, otherwise your grid labels will look odd.

Label Formatting

GeoGrid provides flexible formatting through VBA's Format function. The formatting is isolated in VBA module modFormat. The two functions that define formatting for eastings and northings are FormatGridLabelWithPrefix and FormatGridLabelWithSuffix.

Two versions of the formatter are provided, to suit the requirements of different countries. If your requirements differ, you can write your own VBA formatter.

Use one of those function in the CreateGrid function in modMain. There are some comments in that function that describe what you can do.

modFormat contains an example of a test function for each formatter. The test functions are private and so work only in that module.

Custom Label Formatting

If you want to write your own formatting, then copy-and-paste one of the existing formatters in modFormat. Then write your own test function so you can test your formatting locally. Once the formatting meets your requirements, edit the code CreateGrid to use your new formatting function.

Download the GeoGrid VBA Project

GeoGrid.ZIP

Download GeoGrid.zip (which contains GeoGrid.mvba) and run it by following these instructions …

  1. Copy GeoGrid.mvba to one of the folders in your computer's VBA search path (MS_VBASEARCHDIRECTORIES).
    C:\ProgramData\Bentley\Organisation\Macros\ is a good choice
  2. Open MicroStation's key-in window from the Utilities menu
  3. Start the utility with the following key-in …
    vba run [GeoGrid].modMain.Main

You will see the GeoGrid UserForm.