Questions similar to these appear in the Be Communities MicroStation Programming Forum.

This page lists some solutions to common MicroStation VBA (MVBA) problems. Tips are published as examples and are not necessarily working code.

Introduction

We've created a text style search & replace tool for MicroStation, written in MicroStation VBA. You can search for text in several different element types, and replace the text style of each TextElement found.

Text Style Search & Replace Tool for MicroStation

You don't need to know anything about VBA to use our tool. If you're not interested in the description of the VBA code that follows, then skip to the download section.

Text Style Search & Replace Tool

This tool searches for text in MicroStation TextElements, TextNodeElements, TagElements and CellElements. For each TextElement it finds, it tests its style name against the user-supplied style name.

Text Style Search & Replace Tool for MicroStation

Press the Find button. The tool scans the active DGN model for elements that might contain text. For each text element that it locates, it extracts its text and compares its style name to the user-supplied style name. The number of matches is shown next to the Find button.

The tool pops the Search Results dialog that shows the Element IDs and type description of each matching element …

Text Style Search Results dialog

The Search Results dialog shows a list of matching elements.

Select a row in the list and click the Locate button to instruct MicroStation to focus on the selected element in view 1.

Click the Select button to instruct MicroStation to add all elements in the list to a selection set.

Selection Sets and Fences

This text style search tool is sensitive to user-defined selections and fences. The algorithm implemented here is …

Replace Text style

If you want to replace text style, then take these additional steps …

  1. Type a replacement text style name into the New Style Name box

Press the Execute button. The tool scans the active DGN model as before. This time, in addition to finding text whose style name matches the user specification, it also replaces the style for each match.

This operation is undoable. The command is stored in MicroStation's command buffer, so you can choose Edit|Undo to reverse the changes …

Text Style Replacer: Edit|Undo Text style Replacement
Download

Download the Text Style Replacer Tool

You can download the Text Style Replacer MVBA project. The ZIP package includes the MVBA project TextStyleReplacer.mvba.

If you're interested in the VBA source code, then that's included. Just open the project in MicroStation's VBA Interactive Development Environment (IDE).

Questions

Post questions about MicroStation programming to the MicroStation Programming Forum.