Remove illegal text formatting

<?xml encoding=”UTF-8″>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:WindowsSystem32vbscript.dll3
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.


Comments

One response to “Remove illegal text formatting”

  1. Rodney Thomas Avatar
    Rodney Thomas

    In case you’re still wondering, this has happened for us fairly frequently if copying text from Autocad to Inventor. The note will display in Inventor but when exported you just end up with box and symbols.

Leave a Reply to Rodney ThomasCancel reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading