Q How can I report the number of cell instances in MicroStation?

Questions similar to this, posed by MicroStation users and VBA developers, appear on the Bentley Discussion Groups, typically the MicroStation Forum or Programming Forum.

A This VBA project implements a cell counter, and adds the facility to place a graphic table in a MicroStation DGN model as a cell legend.

Bentley Systems provide a MicroStation Cell Counter library tool for MicroStation V8i, but not for MicroStation CONNECT.

MicroStation Reports

MicroStation CONNECT Update 15 introduces aggregate functions for Reports. It should be possible to write a cell counter using a Report and pass the result to a Table. See our Reports overview.

Introduction

MicroStation users sometimes want something different from the set of tools provided in the product. VBA developers like to do things their way, just because they like VBA. The VBA project described here answers several questions …

  1. How can I report cell counts:
    • To a CSV file?
    • To a graphic table?
  2. Can I display cell counts in a graphic table?
    • Including a thumbnail image of the cell
  3. How do I write a VBA project to count cells and report their quantities?

VBA Cell Counter

Cell Counter Dialog

When you load & run the VBA project it pops a dialog (VBA UserForm). Click the button Harvest Cells to collect a list of all cell instances in the active model. You can filter the cells harvested by setting a selection or creating a fence. Conceptually, VBA creates a number of counters: one counter for each cell name. Each time it finds a cell, it looks for its matching counter and increments it.

Selection Set or Fence

The Cell Counter dialog is aware of MicroStation Fences and Selection Sets. The radio buttons in group Cell Source will be enabled appropriately if a fence or selection set is active when you start the macro. If a Fence is active, the tool harvests cells that satisfy the current fence settings. If a Selection Set is active, the tool harvests cells in that set. Otherwise, the tool harvests cells in the active DGN model.

Write Report

The browse button (Browse Button) lets you choose a file name. The Write Report button formats the cell counters into a comma-separated-variable (CSV) file. A CSV report may look something like this …

"Cell Name", "Cell Count"
"AreaLabel2", 4
"AreaLabel1", 7
"AreaLabelBig", 3
"AreaLabelSmall", 4
"Total Cell Count", 18

The first line of the CSV report is a header. It provides column captions.

Create Legend

The Create Legend button pops another dialog (VBA UserForm) …

Cell Counter Settings

The Cell Count Legend Settings dialog lets you adjust the appearance of the legend table. The dimensions of the legend table centre around the text size specified by a chosen MicroStation Text Style.

Press the Create Legend button to create a cell count legend table. First, the app. creates a new model in the active MicroStation design file. It draws the legend table in that model as a new cell.

The application creates a legend table something like this …

Cell Count Legend

When the application creates the legend, it places thumbnail images of the cells it found in the active DGN model. To place a thumbnail, the cell must be available in one of the attached cell libraries. It checks for the cell's availability using method IsCellAvailable (name).

MicroStation Tables

"Just one moment!" I hear you exclaim, "MicroStation has built-in Tables: why don't you create one of those?"

Well, we welcome the opportunity to offer the latest and greatest. Unfortunately, MicroStation VBA at the time of writing (MicroStation 2024) does not provide a Table class.

Download the Cell Counter VBA Project

Download CellCounter.ZIP

The above code is available in this MicroStation VBA project. Unpack the ZIP archive and copy CellCounter.mvba to a location where MicroStation can find it. A good place to copy it would be ..\Organization\Standards\macros. To create a cell legend, type the following into MicroStation's keyin dialog …

vba run [CellCounter]modMain.Main

Questions

Post questions about MicroStation programming to the MicroStation Programming Forum.