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 ElementDim TranslatedTextE As TextElementDim TranslatedNode As TextNodeElementDim NodeEE As ElementEnumeratorDim EnglishColor As LongDim VersionTest As StringDim oEnglishLevel As LevelDim EE As ElementEnumeratorDim oCriteria As ElementScanCriteriaSet 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 LoopEnd Sub
Sub ChangeTranslatedElementLevelAndColor()
Dim TranslatedElement As ElementDim TranslatedTextE As TextElementDim TranslatedNode As TextNodeElementDim NodeEE As ElementEnumeratorDim EnglishColor As LongDim VersionTest As StringDim oEnglishLevel As LevelDim EE As ElementEnumeratorDim 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 LoopEnd Sub
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
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!!
I tidied up your code to make it easier for me to understand (see attachment). I get the same error as you, on one particular text node. I used MicroStation's analytic tools to examine that node, but don't see anything special.
Regards, Jon Summers LA Solutions
Answer Verified By: JJ Wutt
modTest.bas
Unknown said:The color of textnode is meaningless
Not meaningless...
The text node number can take a different colour to the text elements of that node. The old Analyze Element tool (not the current Element Information tool) lets you apply different colours to each text element and to the node itself.
You can try to comment out the seventh last line ".Color = 23" because the color of textnode is meaningless. Please see the below screenshot, you can notice the color item of TextNode is grey.
HTH, YongAn