[V8i VBA] Text node rewrite error - changing level & color

When I run the code below I get an error when attempting to rewrite one specific text node element in the attached file. This does not happen for all of the other text nodes, and I can't figure out how this one text node is any different than the rest. Another strange thing is that the error does not happen in V8, only in V8i. Any ideas? Help!

Sub ChangeTranslatedElementLevelAndColor()Dim TranslatedElement As Element
Dim TranslatedTextE As TextElement
Dim TranslatedNode As TextNodeElement
Dim NodeEE As ElementEnumerator
Dim EnglishColor As Long
Dim VersionTest As String
Dim oEnglishLevel As Level
Dim EE As ElementEnumerator
Dim oCriteria As ElementScanCriteria
Set oCriteria = Nothing
Set oCriteria = New ElementScanCriteria

With oCriteria
.ExcludeAllTypes
.IncludeType msdElementTypeText
.IncludeType msdElementTypeTextNode
.IncludeOnlyVisible
.ExcludeAllClasses
.IncludeClass msdElementClassPrimary
.IncludeClass msdElementClassDimension
End With

Set EE = ActiveModelReference.Scan(oCriteria)
Do Until EE.MoveNext = False
'define English Level
Set oEnglishLevel = ActiveDesignFile.Levels("English Translation")
'define color
EnglishColor = ActiveDesignFile.ExtractColorTable.FindClosestColor(RGB(128, 255, 255))
'MicroStation V8 requires adjustment to
'color number to get the correct color
VersionTest = Application.Version
If Left$(VersionTest, 13) = "Version 08.05" Then
EnglishColor = EnglishColor - 1
End If
'change level and color of text element
If EE.Current.IsTextElement Then
Set TranslatedTextE = EE.Current
With TranslatedTextE
.Level = oEnglishLevel
.Color = EnglishColor
.Rewrite
.Redraw
End With
End If

'change level and color of text node
If EE.Current.IsTextNodeElement Then
Set TranslatedNode = EE.Current
'change each text element within the text node
Set NodeEE = TranslatedNode.GetSubElements
Do While NodeEE.MoveNext
Set TranslatedTextE = NodeEE.Current
With TranslatedTextE
.Level = oEnglishLevel
.Color = EnglishColor
.Rewrite
.Redraw
End With
Loop

'change level and color of text node element
Set TranslatedElement = TranslatedNode
With TranslatedElement
.Level = oEnglishLevel
.Color = 23
.Rewrite
.Redraw
End With
End If
Loop
End Sub

test.dgn
Parents Reply Children
  • Thank you so much for the responses. This has helped me to find a solution that fits my needs, even though the error caused by changing the color of the specific text node has technically not been resolved.

    For my purposes, it turns out I only need to change the level of the text node and not the text node color. I thought that it was both the level change and the color change that was causing the problem, but it was only the color change. So removing ".Color = 23" from the code works for me.

    Jon - I'm really impressed that you took the time to look into this and what you have done is great! I have learned so much from your posts and your website. Thank you!!

  • Hi Jon,

    Thank you for pointing out this. But even when I back to MicroStatation 8.5, the analyze element command can't to change the color of text node itself (the color item of text node in Element Information dialog is always grey). I think you must change it by program. 

    YongAn