Quantcast
Channel: Manufacturing DevBlog
Viewing all articles
Browse latest Browse all 532

Remove illegal text formatting

$
0
0

By Adam Nagy

Not sure how you end up with text formatting in DrawingNote's where the Font is set to nothing, i.e. the DrawingNote.FormattedText contains things like this:

<StyleOverride Font=''>

Maybe the Font type being used on the system where the drawing was created does not exist on the other system where the drawing has been opened? 

Unfortunately, this seems to cause issues when exporting your drawing to other formats like PDF or DWF and you will get a message like the following:

Fontformatting2

... and the exported document might contain illegible text:

Fontformatting

If you know the exact problem you are looking for - in our case Font='' - then you could simply remove these from the FormattedText of the notes. In case of VBA you could use the Microsoft VBScript Regular Expressions COM library. If you are using .NET or C++ there would be other options.

' Using 'Microsoft VBScript Regular Expressions 5.5' COM library' C:\Windows\System32\vbscript.dll\3
Public Sub RemoveInvalidNoteFormatting(ByRef note As DrawingNote)' Remove bad formatting in tags like <StyleOverride Font=''>' where Font is set to nothing ''
    Dim r As New RegExp
    r.Global = True
    r.IgnoreCase = True
    r.Pattern = "Font=''"
    note.formattedText = r.Replace(note.formattedText, "")
End Sub

Public Sub RemoveInvalidFormatting()
    Dim doc As DrawingDocument
    Set doc = ThisApplication.ActiveDocument
    
    Dim sht As Sheet
    For Each sht In doc.Sheets
        Dim note As DrawingNote
        For Each note In sht.DrawingNotes
            Call RemoveInvalidNoteFormatting(note)
        Next
    Next
End Sub

Once I've run the above code on the drawing, I could export it without any problem.


Viewing all articles
Browse latest Browse all 532

Trending Articles