Introduction

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

Background

A MicroStation DGN file (VBA DesignFile object) is a container. It contains DGN models (VBA ModelReference objects). Each model has a name, which a MicroStation user can edit and change.

We'd like to rename a DGN model using VBA. And, in answer to a specific question, we'll offer an option to rename a sheet model after the DGN file name.

DGN ModelRenamer

The ModelRenamer.mvba project offers two entry points …

  1. modMain.Main provides an unfettered opportunity to rename any DGN model
  2. modMain.RenameSheetModel provides an opportunity to rename a DGN sheet model but no other model type

The VBA code to rename a DGN model is straightforward: we just assign the ModelReference.Name property. However, we need to check that another model having that name does not already exist. Additionally, with modMain.RenameSheetModel, we want to check the the model type (ModelReference.Type) is valid.

One questioner wants the new model name to be copied from the DGN file name. In both modMain.Main and modMain.RenameSheetModel we assume that is the case, and the active DGN file name is taken, with the file extension removed, to provide the new model name.

VBA Source Code

This VBA project includes source code. It is provided free of copyright and free of license — it's freeware. Read the notes in the main code module modMain. The project uses the Microsoft Scripting Runtime ActiveX library for elegant file I/O.

Download the Text Coordinate Exporter VBA Project

Download ModelRenamer.ZIP

The above code is available in this MicroStation VBA project. Unpack the ZIP archive and copy ModelRenamer.mvba to a location where MicroStation can find it. A good place to copy it would be \Workspace\Standards\vba. To start exporting survey points, type the following into MicroStation's keyin dialog …

vba run [ModelRenamer]modMain.Main

or

vba run [ModelRenamer]modMain.RenameSheetModel