I managed to write a VBA script that scans a drawing and extracts number of text (either TextElements or TagSet or TextNode)
that are enclosed within a unique identifier, and then replaces them (with the text in thier new values ) into another new file (with the same drawing content).
The code scans these textsTobeReplaced, and stores the reference to the TextElement or TagSet. then prompts user fornew values (or via XLS sheet).
Now in the new file I am having this very wiered behaviour happening whereby, if I attempt to the fill in single enter-datafield
the new text entered is misbehaving. For instance.
Old Text: F11 (the length is 3 and center justified)
attempting to modify text using fill-in text editor with value of "F2", what happens is the justification is altered (to left)
and only "F" appears!!!
I spent some time comparing what has changed, I couldn't get to the buttom of it. I read the help page it indicates that fill-in data should preserve original length and justification!
Note: If I try to modify the text using Text editor (for text nodes) it works fine!!! (I dont even have to alter the length or justification).
Is there something that I need to preserve and I'm not?
Thanks for the help in advance
Please post a code sample.
Regards, Jon Summers LA Solutions
A snapshot of the code: btw this' not precisely what I'm using, but the core of it is.
The guts of it is:
myText.Text = myWS.Cells(row, col) myText.Rewrite ' I suspect this' a problem
myEleFilter.ExcludeAllTypes myEleFilter.IncludeType msdElementTypeTag myEleFilter.IncludeType msdElementTypeText myEleFilter.IncludeType msdElementTypeTextNode myEleFilter.IncludeType msdElementTypeCellHeader Dim modelCount As Integer Dim myModel As String For modelCount = 1 To myDGN.Models.count If myDGN.Models(modelCount).Type = msdModelTypeSheet Then Set myEleEnum = myDGN.Models(myDGN.Models(modelCount).Name).Scan(myEleFilter) Set myWS = Excel.Sheets("TitleBox Data") Do While myEleEnum.MoveNext If myEleEnum.Current.Type = msdElementTypeTag Then Set myTag = myEleEnum.Current If InStr(1, myTag.TagSetName, "Test", vbTextCompare) <> 0 Then If InStr(1, myTag.TagDefinitionName, "APPROVED", vbTextCompare) Then myTag.Value = myWS.Cells(3, 2) If (StrComp(myWS.Cells(3, 3), "N", 1) = 0) Then myTag.IsHidden = True Else myTag.IsHidden = False End If End If myTag.Rewrite End If Loop ElseIf myDGN.Models(modelCount).Type = msdModelTypeNormal Then Set myEleEnum = myDGN.Models(myDGN.Models(modelCount).Name).Scan(myEleFilter) Set myWS = Excel.Sheets("Drawing Data") 'Loop within the Enum Do While myEleEnum.MoveNext If myEleEnum.Current.Type = msdElementTypeText Then Set myText = myEleEnum.Current If (StrComp(myText.Text, "bitOP2", 1) = 0) Then myText.Text = myWS.Cells(5, 2) myText.Rewrite End If End If If myEleEnum.Current.Type = msdElementTypeTextNode Then Set myTextNode = myEleEnum.Current Set myEleEnum2 = myTextNode.GetSubElements Do While myEleEnum2.MoveNext If myEleEnum2.Current.Type = msdElementTypeText Then
Set myText= txtNodeElmntEnum.Current If InStr(1, textElmnt.Text, DELIM, vbTextCompare) <> 0 Then myText.Text = myWS.Cells(6 2) myText.Rewrite End If
End If Loop End If If myEleEnum.Current.Type = msdElementTypeCellHeader Then Set myCell = myEleEnum.Current Set myEleEnum2 = myCell.GetSubElements Do While myEleEnum2.MoveNext If myEleEnum2.Current.Type = msdElementTypeTextNode Then Set myTextNode = myEleEnum2.Current Set myEleEnum3 = myTextNode.GetSubElements Do While myEleEnum3.MoveNext If myEleEnum3.Current.Type = msdElementTypeText Then Set myText = myEleEnum3.Current If (StrComp(myText.Text, " 1a ", 1) = 0) Then myText.Text = myWS.Cells(4, 3) myText.Rewrite End If Loop End If If myEleEnum2.Current.Type = msdElementTypeText Then Set myText = myEleEnum2.Current If InStr(1, myText.Text, "OP1R", vbTextCompare) <> 0 Then myText.Text = myWS.Cells(4, 6) myText.Rewrite End If Loop End If Loop End If Next myDGN.Save myDGN.Close 'Close Microstation myUstation.Quit 'Quit the programEnd Sub
Further to my earlier post, in a textNode, the field MAX_LENGTH has been set to the length of the new string rather than the original one!!
for example if the text was $C1$ and the max length was set to 4, and the value user enters in the EXCEL sheet is 12, then the new length is 2!
It seems that rewrite clears the length field, but keeps some other attributes as they are!
I'm happy to mail the entire code with some drawings if required.
Thanks for the help