Create non-existant text style

Create non-existant text style

SRSDS
Advisor Advisor
777 Views
3 Replies
Message 1 of 4

Create non-existant text style

SRSDS
Advisor
Advisor

Some .doc files don't contain a text style I want to use.

The code: GetOrCreateTextStyle I found somewhere uses a variable called "bgfilename" which I assume points to a generic font template file.

Does anyone know what file path this variable might refer to?

 

Public Function GetOrCreateTextStyle(ByVal stylename As String, ByVal fontfilename As String, ByVal bgfilename As String, ByVal textheight As Double, ByRef trans As Transaction) As ObjectId
        Dim id As ObjectId = GetTextStyle(stylename, trans)
        If id = Nothing Then
            id = CreateTextStyle(stylename, fontfilename, bgfilename, textheight, trans)
        End If
        Return id
    End Function
    Public Function GetTextStyle(ByVal stylename As String, ByRef trans As Transaction) As ObjectId
        Dim db As Database = Application.DocumentManager.MdiActiveDocument.Database
        Return GetNonErasedTableRecordId(db.TextStyleTableId, stylename, trans)
    End Function
    Public Function GetNonErasedTableRecordId(ByVal TableId As ObjectId, ByVal Name As String, ByRef trans As Transaction) As ObjectId
        Dim id As ObjectId = Nothing
        Dim table As SymbolTable = DirectCast(trans.GetObject(TableId, OpenMode.ForRead), SymbolTable)
        If table.Has(Name) Then
            id = table(Name)
            If Not id.IsErased Then
                Return id
            End If
            For Each recId As ObjectId In table
                If Not recId.IsErased Then
                    Dim rec As SymbolTableRecord = DirectCast(trans.GetObject(recId, OpenMode.ForRead), SymbolTableRecord)
                    If String.Compare(rec.Name, Name, True) = 0 Then
                        Return recId
                    End If
                End If
            Next
        End If
        Return id
    End Function
    Public Function CreateTextStyle(ByVal stylename As String, ByVal filename As String, ByVal bgfilename As String, ByVal textheight As Double, ByRef trans As Transaction) As ObjectId
        Dim id As ObjectId = Nothing
        Dim db As Database = Application.DocumentManager.MdiActiveDocument.Database
        Try
            Dim tst As TextStyleTable = DirectCast(trans.GetObject(db.TextStyleTableId, OpenMode.ForRead, False), TextStyleTable)
            Using ts As New TextStyleTableRecord()
                ts.Name = stylename
                ts.FileName = filename
                If bgfilename <> String.Empty Then
                    ts.BigFontFileName = bgfilename
                End If
                ts.TextSize = textheight
                ts.XScale = 1.0
                tst.UpgradeOpen()
                tst.Add(ts)
                trans.AddNewlyCreatedDBObject(ts, True)
                id = ts.ObjectId
            End Using
        Catch ex As Exception
            MsgBox(Reflection.MethodBase.GetCurrentMethod.Name() + " Exception: " + ex.Message)
        End Try
        Return id
    End Function
0 Likes
Accepted solutions (1)
778 Views
3 Replies
Replies (3)
Message 2 of 4

Ajilal.Vijayan
Advisor
Advisor
Accepted solution

This is to set the big font file property of text style.

If your new style is not shx font, then you can ignore this variable by giving an empty string ( "")

If you want to use then use and big font file name , like bigfont.shx or other

Capture.JPG

0 Likes
Message 3 of 4

SRSDS
Advisor
Advisor

Thanks Ajilal,

That explains things.

I also worked out that the template file with the 'problem' was causing the app to fail to load correctly which was the cause of the missing font.

 

0 Likes
Message 4 of 4

Ajilal.Vijayan
Advisor
Advisor

You're welcome, glad I could help.

0 Likes