Q How can I analyze the models in a DGN file and report level usage?
Questions similar to this, posed by MicroStation users and VBA developers, appear on the Be Communities MicroStation Forum or Programming Forum.
A This VBA project implements a tool for analyzing DGN models and reporting their level usage.
MicroStation users sometimes want something different from the set of tools provided in the product.
The question asked, on Be Communities, was: "How can I use VBA to analyze DGN models and report the number of levels used in each model?"
The Report Levels in Models tool is implemented using a VBA classes that analyzes each model in a DGN file. It writes the results to a CSV text file.
This VBA project uses
Microsoft Scripting Runtime
to create a FileSystemObject
.
Scripting.FileSystemObject
is used to open a text file (Scripting.TextStream
).
clsModelAnalyzer
is a VBA class that works with a DGN model.
It's ReportLevels
method does the work of analyzing a model and reporting the levels used in that model.
The result is written as a line of CSV to the text file opened above.
The report file is a text file formatted as Comma Separated Values (CSV). You can open a CSV file with a text editor or a spreadsheet application such as Microsoft Excel.
Here's an example Levels.csv
file, showing level count, created by this utility …
"File Name", "Model Name", "Level Count" "\\Server\DataFolder\LevelsInModelsTest.dgn","Model 1",2 "\\Server\DataFolder\LevelsInModelsTest.dgn","Model 2",2 "\\Server\DataFolder\LevelsInModelsTest.dgn","Model 3",2
Here's an example Levels.csv
file, showing level names, created by this utility …
"File Name", "Model Name", "Level Name", "Level Code" "Server\DataFolder\LevelsInModelsTest.dgn","Model 1","Level 1",1 "Server\DataFolder\LevelsInModelsTest.dgn","Model 1","Level 2",2 "Server\DataFolder\LevelsInModelsTest.dgn","Model 2","Level 3",3 "Server\DataFolder\LevelsInModelsTest.dgn","Model 2","Level 4",4 "Server\DataFolder\LevelsInModelsTest.dgn","Model 3","Level 5",5 "Server\DataFolder\LevelsInModelsTest.dgn","Model 3","Level 6",6
The code described is available in a MicroStation VBA project. The macro is provided as freeware with no guarantee of suitability for any particular purpose. Use at your own risk. We grant you a zero-cost license to use this software.
Unpack the ZIP archive and copy LevelsInModels.mvba
to a location where MicroStation
can find it.
A good place to copy it would be \Workspace\Standards\macros
.
To start the macro, use the following MicroStation key-in …
vba run [LevelsInModels]modMain.Main
Post questions about MicroStation programming to the MicroStation Programming Forum.