Edit Data Field VS Fill in signle Enter Data Field

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 for
new 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

Parents
  • 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 program
    End Sub

Reply
  • 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 program
    End Sub

Children
  • 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

  • I find such a large, monolithic, code block hard to follow, particularly so since some of the code is Excel VBA and other of the code is MicroStation VBA.

    Divide and conquer! Move code that deals with one topic into a procedure. It benefits us because your logic becomes easier to follow, and it benefits you for the same reason. It's not unusual to find, in six months time, that the code you write today looks like it was written by someone who uses the same style as you but whose logic is beyond comprehension.

    For example …

    Dim oModel As ModelReference
    For Each oModel In myDGN.Models
      Select Case oModel.Type
      Case msdModelTypeSheet
        Call SheetModelOperations (oModel)
      Case msdModelTypeNormal
        Call NormalModelOperations (oModel)
      End Select
    Next oModel
    Private Sub SheetModelOperations (ByVal oModel As ModelReference)
    ...
    End Sub
    Private Sub NormalModelOperations (ByVal oModel As ModelReference)
    ...
    End Sub

    Regards, Jon Summers
    LA Solutions

     
    Regards, Jon Summers
    LA Solutions

  • @Jon: Thanks for the advise, and I value the attempt to help. Cheers :)


    I figured out what the issue was. Basically the textElement I'm dealing with contained DataEntry and text.
    accessing both is not the same. And if you attempt to treat a DataEntry as text then the
    signle Enter Data Field would confuse the setting (I find this to be interesting and I still dont understand why)

    I have modified the code to treat each seperatly.
    What I call pure text is basically a textElement without a dataEntry.
    and I'm lucky that there's only two cases, one is a DataEntry ONLY and one as pure text.



    So here's how it looks now (which is an exact snapshot copy, unlike earlier code) :
    Note: drawRef.DrawingRef is equivilant to textElement or TagElement object


    class DrawingReference  ' Prototype copy
       Private o_drawingRef    As Object     ' This holds the reference to a TextElement or a TagElement
       Private s_referenceType As String

       Private s_originalText  As String
       Private s_finalText     As String

       Private s_TEXT_TYPE     As String
       Private s_TAG_TYPE      As String
    end class


    Public Function updateDrawingReference(ByRef errorStr As String) As Boolean

       Dim drawRef        As DrawingReference
       Dim s_finalText    As String
       Dim s_originalText As String
       Dim data           As DataEntryRegion

       For Each drawRef In c_drawingReferenceCollec

          s_finalText = ""
          s_originalText = drawRef.OriginalText

          If drawRef.isTextType Then
             If drawRef.DrawingRef.DataEntryRegionsCount = 1 Then
                s_originalText = drawRef.DrawingRef.DataEntryRegionText(1)
             End If
          End If

          If Not prepareSubText(s_originalText, s_finalText) Then

                errorStr = errorStr & "Unable to process " & drawRef.DrawingRef.Text & vbNewLine
                GoTo returnFalse

          End If

          drawRef.FinalText = s_finalText

          If drawRef.isTagType Then

             drawRef.DrawingRef.Value = drawRef.FinalText

          ElseIf drawRef.isTextType Then

             drawRef.DrawingRef.Text = ""

    '=========================
    'This' the key change here
    '=========================
             If drawRef.DrawingRef.DataEntryRegionsCount = 1 Then

    '            drawRef.DrawingRef.DataEntryRegionText(1) = ""
               
                ' update length of data field
                data = drawRef.DrawingRef.DataEntryRegion(1)
                data.Length = Len(drawRef.FinalText)
                drawRef.DrawingRef.DataEntryRegion(1) = data

                ' update the actual text of the field
                drawRef.DrawingRef.DataEntryRegionText(1) = drawRef.FinalText

             Else ' a pure text

                drawRef.DrawingRef.Text = drawRef.FinalText

             End If

          End If

          drawRef.DrawingRef.Redraw
          drawRef.DrawingRef.Rewrite

       Next drawRef

       If updateDrawingReference Then GoTo returnBack

    returnFalse:
       updateDrawingReference = False

    returnBack:

    End Function