Introduction

Questions similar to this appear on the MicroStation Forum.

Often we have a DGN file with multiple cell instances. We want to find the cell library where each cell may be found. In other words, an audit of cells. Usually, this is an area of interest to CAD Administrators.

A MicroStation session has access to zero or more cell libraries (*.cel files). Those libraries are found in the folders indicated by configuration variable MS_CELL.

Cell Audit dialog

The MicroStation VBA macro described here performs several tasks concerning cells and cell libraries …

  1. Finds all cell libraries using configuration variable MS_CELL
    • Optionally, writes a CSV file of libraries
  2. Finds all cell instances in the active DGN model
    • Optionally, writes a CSV file of cell instances
  3. Correlates cell instances with cell libraries
    • Optionally, writes a CSV file of cells and the description and library where each cell is found

CSV Example

Here's some example data from a CSV file produced by the Cell Audit macro …

"Cell Name", "Description", "Library Path"
"Single Door","CCW arc","\\asterix\datadir\Bentley\CONNECT\LA Solutions\Standards\Cell\DoorsWithSmartText.cel"
"Single Door 2","CW arc","\\asterix\datadir\Bentley\CONNECT\LA Solutions\Standards\Cell\DoorsWithSmartText.cel"
"Copy of AreaLabel2","Unavailable","Not Found"
"AreaLabel4","Show model name updating automatically","\\asterix\datadir\Bentley\CONNECT\LA Solutions\Standards\Cell\AreaAnnotatorTemplateLibrary.cel"
"Cell contains some text","Unavailable","Not Found"
"AreaLabel1","area label template for AreaAnnotator","\\asterix\datadir\Bentley\CONNECT\LA Solutions\Standards\Cell\AreaAnnotatorTemplateLibrary.cel"
"Fraction","Unavailable","Not Found"

VBA Utility: Cell Audit

Cell Audit dialog

The order of performing a cell audit is …

  1. Harvest visible cell libraries using the Evaluate Cell Libraries button
    • Libraries are found by searching the folders mentioned in configuration variable MS_CELL
  2. Harvest cell instances from the active DGN model using button Get Cells
    • Anonymous cell are ignored
  3. Correlate cells with libraries using the Correlate button
    • When a cell is found, its description is copied from the cell library
At each step you have the option to create a CSV file of the related data.

Notes for Developers

Scripting.Dictionary

When collecting information about cells and libraries, the code makes use of the Scripting.Dictionary class. A Dictionary object is similar to a PERL associative array, or a Python dictionary.

A dictionary stores data as a pair: a key and an object. The object can be of almost any data type. In this macro, the key is a String (e.g. a cell name) and the object is a String or another class.

There are two dictionaries, both held by the UserForm as member variables …

This macro represents the limit of VBA capabilities. I would have preferred to write this as a C++ or C# app, because those languages provide more help for storing, comparing, and sorting classes.

OpenDesignFileForProgram

This macro uses OpenDesignFileForProgram to examine each cell library (DGN file) and read cell (model) names and descriptions. Often, I advise against using OpenDesignFileForProgram, but in this case it's a valid use.


Download

Download Example VBA Project

A sample project is available. It includes code similar to that above and the VBA UserForm shown above. The macro is provided as freeware. It is not formally supported software. Use at your own risk.

You can download a ZIP file, and then extract CellAudit.mvba to a folder that MicroStation can find. A good place to put it would be ..\Workspace\Standards\macros, or any other folder specified in the MS_VBASEARCHDIRECTORIES configuration variable.

Start the macro with this MicroStation key-in …

vba run [CellAudit]modMain.Main

Questions

Post questions about MicroStation programming to the MicroStation Programming Forum.