Q How do I increment a MicroStation text element or text node element that contains a number?
A If you just want to use the Text Incrementor macro, jump to the download paragraph. Otherwise, keep on reading.
Q How do I create a sequence of MicroStation text elements or text node elements that start with a number and increment that number for each member of a sequence?
A If you just want to use the Text Incrementor macro to sequence numbers, jump to the download paragraph. Otherwise, keep on reading.
Read the text element, pass its content to an incrementor function, set the content to the result, and rewrite the element …
TextElement
TextElement
into memory
IncrementText
function to the TextElement
TextElement
The Text Incrementor VBA project is a working project that implements a text locator along with the text increment function. It works with simple text elements and with text node elements. For example …
ABC123
becomes ABC124
EM-3614NS-ISS-24
becomes EM-3614NS-ISS-25
In the last case, the incrementor considers only the last few digits in the text string.
The Text Incrementor is sensitive to selection sets and fences. If a fence is active, or a selection set is present, the macro processes the elements in that collection. Otherwise, it provides a pick tool, which prompts you to pick text or text node elements.
When used with a text node element, the Text Incrementor looks only at the last text element in the node. That is, if your text node looks like this …
ABC DEF 123
The incrementor considers only the last line (123
) and increments that, like this …
ABC DEF 124
You don't have to be a VBA whizz to use this macro. Follow the instruction to download the macro and invoke the key-in mentioned below.
When sequencing text, the Text Incrementor expects an active selection set or a fence. It extracts the text of the first text element in that set, and uses it as the pattern for subsequent values in the sequence.
Text Incrementor looks at the first text or text node element in the selection or fence.
It uses that as the pattern for subsequent text.
For example, if the first element contains text ABC 123
, then Text Incrementor
calculates the next value of the sequence as N x increment
.
N
is the current index in the sequence, and increment
is the increment (or decrement) value.
In this example, the sequences becomes …
ABC 123 ABC 124 ABC 125 ... ABC 199
The numbers in a sequence may not be what you expect. If elements are in a selection set, the numbers correspond to the position of each text element in that set. You have control over the order in which you select elements. If elements are in a fence, the numbers may appear almost random. The numbers correspond to the file order of text elements found in the fence. You have no control over the order in which the Text Incrementor processes the fence contents.
If you want a tool to increment non-numeric text, then read this article
You may find the article about numeric text formatting interesting.
The IncrementText
class does the work of incrementing a single text or text-node element, or multiple text or text-node elements.
It extracts the element's text, calculates the incremented value that it applies to the text, then rewrites the text element.
When creating a sequence of numbers, it finds the first text element in the selection or fence, and uses that as a pattern for the rest of the sequence.
For example, if the first text element in the selection contains ABC 123
, then the pattern for subsequence text will be …
ABC
& 123 + index * increment
.
If you're a VBA developer, then download the macro and examine the source code using MicroStation's Interactive Development Environment (IDE).
Download the
TextIncrementor ZIP archive, and unpack it to a suitable location such as
\Workspace\Standards\vba
.
Start the macro using the key-in …
vba run [TextIncrementor]modMain.Main
By default, the Text Incrementor uses the active settings value of Tag Increment. You can modify that by specifying an alternative value on the command line. For example, if you want to use an increment of two, do this …
vba run [TextIncrementor]modMain.Main 2
Or, if you want to use an increment of decimal 0.1, do this …
vba run [TextIncrementor]modMain.Main .1
Or, if you want to sequence numbers, do this …
vba run [TextIncrementor]modMain.Main sequence
When creating a sequence, the Text Incrementor works on multiple text elements. It expects to find those elements either in a selection set or a fence.
Any of those key-ins reveals the macro version number in MicroStation's Message Center …
Post questions about MicroStation programming to the MicroStation Programming Forum.