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.

Text Font Search Tool

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

Text Font 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.

Introduction

The following subroutine uses the Microsoft VBScript Regular Expressions 5.5 to search a string for a Unicode sequence …

Text Font Search & Replace Tool

Text Font Search & Replace Tool for MicroStation

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

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 font name to the user-supplied font 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 Font 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 font search tool is sensitive to user-defined selections and fences. The algorithm implemented here is …

Replace Text Font

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

  1. Type a replacement font name (e.g. Arial) into the New Font Name box

Press the Execute button. The tool scans the active DGN model as before. This time, in addition to finding text whose font name matches the user specification, it also replaces the font name 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 Font Replacer: Edit|Undo Text Font Replacement
Download

Download the Text Font Replacer Tool

You can download the Text Font Replacer MVBA project. The ZIP package includes the MVBA project TextFontReplacer.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.