[CONNECT VBA] Applying a Text Style from a dgnlib to an element during scan

I feel like I have done this before but can't get it to work for some reason.

I would like to scan a model for text elements and set the text style for each one found.

I have the scan etc working fine but can't apply the text style -

        'Change text style of sign names
        
        Do While oEnumerator.MoveNext
             
            Set oText = oEnumerator.Current

            Set oText.TextStyle = oFile.TextStyles("1.8mm BG")
                
            'oEnumerator.Current.Rewrite
            
            oText.Redraw msdDrawingModeNormal
            oText.Rewrite
            
            counter = counter + 1
         
        Loop

Any help would be appreciated.

Parents
  • I have the scan etc working fine but can't apply the text style

    Text styles in VBA seem often to cause problems.  Try something like this...

    Dim oStyle As TextStyle
    Set oStyle = oFile.TextStyles("1.8mm BG")
    Debug.Assert Not oStyle Is Nothing
    Do While oEnumerator.MoveNext
      Set oText = oEnumerator.Current.AsTextElement
      Debug.Assert Not oText Is Nothing
      Set oText.TextStyle = oStyle
      oText.Rewrite
      counter = counter + 1
    Loop
    

     
    Regards, Jon Summers
    LA Solutions

  • I thought I had replied here but must have not.

    Thanks Jon although the text style is still not being applied.

    I have ran some debugging and the results are confirming the following are correct -

    Current Text Style name of the element

    Text contents of the element

    New Text Style name set to oStyle

            Do While oEnumerator2.MoveNext
    
                Set oText = oEnumerator2.Current.AsTextElement
    
                Debug.Assert Not oText Is Nothing
    
                Set oText.TextStyle = oStyle
    
                oText.Rewrite
    
                Debug.Print oText.Text
    
                Debug.Print "oText style name = " & oText.TextStyle.Name
    
                counter = counter + 1
    
            Loop

    Any (more) help would be greatly appreciated.

Reply
  • I thought I had replied here but must have not.

    Thanks Jon although the text style is still not being applied.

    I have ran some debugging and the results are confirming the following are correct -

    Current Text Style name of the element

    Text contents of the element

    New Text Style name set to oStyle

            Do While oEnumerator2.MoveNext
    
                Set oText = oEnumerator2.Current.AsTextElement
    
                Debug.Assert Not oText Is Nothing
    
                Set oText.TextStyle = oStyle
    
                oText.Rewrite
    
                Debug.Print oText.Text
    
                Debug.Print "oText style name = " & oText.TextStyle.Name
    
                counter = counter + 1
    
            Loop

    Any (more) help would be greatly appreciated.

Children