I’ve been attempting to write some LotusScript code to parse a RichTextItem and change all the text content to DefaultSansSerif size 10 … yep, you guessed it, so it will display correctly on the web! Sigh!
I wrote a routine (cribbed heavily from the Notes help) - see below. However when I run this routine, and save the backend document and then reload the UIDoc, I get an NSD crash in the client.
I have see Andre Guirard’s post (Hi Andre - the kiwi’s back!) about how to change the value in an RTF field and refresh without saving the document. So I’ll try incorporating that approach next. However the client shouldn’t be able to be crashed should it!!??
Any help with the code below would be VERY VERY welcome!
Thanks all,
Regards
Mark
Here’s the call to the subroutine:
Sub Click(Source As Button)
Dim s As New NotesSession
Dim ws As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim rtitem As NotesRichTextItem
Set uidoc=ws.CurrentDocument
Dim doc As NotesDocument
Set doc=uidoc.Document
If uidoc.IsNewDoc Then
Call uidoc.Save
Call uidoc.Reload
End If
Set rtitem=doc.GetFirstItem("RichText2")
Call SetRTFont(doc,rtitem)
Call doc.Save(True,False)
'Call uidoc.Refresh
'Call uidoc.Reload
REM NOTE : commented above out to prevent NSD crash … now hangs instead!!!
End Sub
Here’s the Subroutine itself
Sub SetRTFont(doc As NotesDocument, rtitem As NotesRichTextItem)
Dim rtnav As NotesRichTextNavigator
Dim rtnav2 As NotesRichTextNavigator
Dim rtrange As NotesRichTextRange
Dim rtrange2 As NotesRichTextRange
Dim currstyle As NotesRichTextStyle
'Find paragraphs in rtitem
Set rtnav = rtitem.CreateNavigator
If rtnav.FindFirstElement(RTELEM_TYPE_TEXTPARAGRAPH) Then
Set rtrange = rtitem.CreateRange
Set rtnav2 = rtitem.CreateNavigator
Set rtrange2 = rtitem.CreateRange
count% = 0
Do
count% = count% + 1
' Set range for paragraph
Call rtrange.SetBegin(rtnav)
Call rtrange.SetEnd(rtnav)
' Create navigator for paragraph
Set rtnav2 = rtrange.Navigator
' Find text runs in paragraph
If rtnav2.FindFirstElement(RTELEM_TYPE_TEXTRUN) Then
count2% = 0
msg$ = ""
Do
count2% = count2% + 1
' Set range for text run
Call rtrange2.SetBegin(rtnav2)
' Now get the existing style of the run
Set currstyle=rtrange2.Style
' Change font face and size to FONT_HELV and size 10
currstyle.NotesFont=FONT_HELV
currstyle.FontSize=10
' And replace it again
Call rtrange2.SetStyle(currstyle)
' Get next text run
Loop While rtnav2.FindNextElement(RTELEM_TYPE_TEXTRUN)
End If
' Get next paragraph
Loop While rtnav.FindNextElement(RTELEM_TYPE_TEXTPARAGRAPH)
Else
Print "No text in Rich Text field: " & rtitem.Name ,, "No text"
End If
End Sub