You are currently reviewing an older revision of this page.
Background Information
The existing MicroStation functionality to search and replace features many options and variations. However, there are always cases in which a considerable effort has to be taken when larger inventories need to be changed, and at the same time a number of replacements have to be made. This short series of examples will address different problems that may arise in this matter. I will start with a simple example and add some more options later to cover many aspects.
Simple Example for Substituting it by text in the current model
The following example searches the active model and searches for text that has been given as the first parameter when starting up the VBA routine. When this text is found, it is replaced by the text that was passed as the second parameter.I use the pipe character "|" as a delimiter when calling to separate the parameters cleanly.
Here is an example of how this can be done:
Option Explicit Sub TxtRep_simple() Dim sToFind As String ' Find the text Dim sToReplace As String ' Replace with this text Dim CmdLine() As String Dim Ee As ElementEnumerator Dim Sc As New ElementScanCriteria ' As a separator between parameters, use "|" CmdLine = Split(KeyinArguments, "|") ' Cancel if incorrect parameters were given: If UBound(CmdLine) <> 1 Then ' given the wrong parameter MessageCenter.AddMessage "Replace text: incorrect parameters were given, see details" , "Call was made with" + KeyinArguments, msdMessageCenterPriorityError Exit Sub End If sToFind = Trim(CmdLine(0)) '1.Parameter - text to search sToReplace = Trim(CmdLine(1)) '2.Parameter - new text ' Browse current model based on texts and examine Sc.ExcludeAllTypes Sc.IncludeType msdElementTypeText Set Ee = ActiveModelReference.Scan(Sc) Do While Ee.MoveNext With Ee.Current.AsTextElement If .Text = sToFind Then .Text = sToReplace .Rewrite End If End With Loop End Sub
When this routine is loaded, it can be started using the following syntax:
vba run TxtRep_simple findtext | replacetext
It searches for the "findtext" in the drawing and replaces it with the "replacetext" in this example.
If you want to replace the text "House" by the word "Shed", you would call it like this:
vba run TxtRep_simple House | Shed
Upper case and lower case of the search text must be exact so that it is found. In addition, this will only replace if the entire word is exactly the same. We are looking for the active model and the texts will be checked that if found, meaning that no text nodes or cells will be searched.
>> Continue on to part 2 >>