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 …
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!
The project includes several modules …
modMain
, which contains the main entry point
UserForm
frmGeoGrid
clsSolicitCornerPoint
clsGridLine
draw and annotate a grid line
modFormat
that contains the code use to format grid labels
modOriginal
that contains original BASIC code from which GeoGrid derives
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 …
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
.
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.
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.
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.
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
GeoGrid.zip
(which contains GeoGrid.mvba
) and run it by following these instructions …
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
vba run [GeoGrid].modMain.Main
You will see the GeoGrid UserForm
.