How to add Chinese font in Table through journal

Hi,

I am trying to create tabular note through journal and want to add chinese character in it.
For that i am using below mentioned code.
I am able to set the font separately after creating table but not through the code.
So how to do it ?
I have used Arial Unicode MS font style.

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.Annotations
Imports NXOpen.UI
Imports NXOpen.UF
Imports NXOpen.Utilities
Imports NXOpen.Builder
Imports NXOpen.NXObject
Imports System.Collections.Generic
Imports NXOpen.Features
Imports System.Threading

Module Module1

Dim theSession As Session
Dim workPart As Part
Dim displayPart As Part
Dim theCellPrefs As UFTabnot.CellPrefs
Dim myTabularNoteTags As New List(Of Tag)
Dim tableSectionBuilder1 As Annotations.TableSectionBuilder
Dim cellTag As Tag
Private ufsession As UFSession
Private theUfSession As UFSession
Private myTabNote As NXOpen.Annotations.TableSection
Dim OH As Double
Private dwgShtBld As Drawings.DrawingSheetBuilder
Dim rowTag As Tag
Dim colTag As Tag
Dim numRows As Integer
Dim numCols As Integer
Sub Main()

theSession = Session.GetSession()
workPart = theSession.Parts.Work
UFSession = UFSession.GetUFSession()
displayPart = theSession.Parts.Display

Dim nullAnnotations_TableSection As Annotations.TableSection = Nothing

displayPart = theSession.Parts.Display
dwgShtBld = workPart.DrawingSheets.DrawingSheetBuilder(workPart.DrawingSheets.CurrentDrawingSheet)

OH = dwgShtBld.Length

dwgShtBld.Commit()
dwgShtBld.Destroy()

tableSectionBuilder1 = workPart.Annotations.TableSections.CreateTableSectionBuilder(nullAnnotations_TableSection)
tableSectionBuilder1.Origin.Anchor = Annotations.OriginBuilder.AlignmentPosition.MidLeft
tableSectionBuilder1.Origin.Plane.PlaneMethod = Annotations.PlaneBuilder.PlaneMethodType.ModelView
tableSectionBuilder1.Origin.Anchor = Annotations.OriginBuilder.AlignmentPosition.TopLeft
tableSectionBuilder1.RowHeight = 7.1
tableSectionBuilder1.Style.TableSectionStyle.AlignmentPosition = Annotations.TableSectionStyleBuilder.AlignmentPositionType.BottomRight
tableSectionBuilder1.Style.LetteringStyle.GeneralTextAspectRatio = 0.68

tableSectionBuilder1.NumberOfColumns = 5
tableSectionBuilder1.NumberOfRows = 1
tableSectionBuilder1.ColumnWidth = 30
tableSectionBuilder1.Style.TableSectionStyle.MaximumHeight = 2000

'--Setting the properties of Table--------------------------------------
Dim fitmethods1(0) As Annotations.TableCellStyleBuilder.FitMethodType
fitmethods1(0) = Annotations.TableCellStyleBuilder.FitMethodType.Wrap
' fitmethods1(1) = Annotations.TableCellStyleBuilder.FitMethodType.AutoSizeRow
tableSectionBuilder1.Style.TableCellStyle.SetFitMethods(fitmethods1)

Dim assocOrigin1 As Annotations.Annotation.AssociativeOriginData
assocOrigin1.OriginType = Annotations.AssociativeOriginType.Drag
Dim nullView As View = Nothing
assocOrigin1.View = nullView
assocOrigin1.ViewOfGeometry = nullView
Dim nullPoint As Point = Nothing

tableSectionBuilder1.Origin.SetAssociativeOrigin(assocOrigin1)
Dim point1 As Point3d

point1 = New Point3d(OH - 200, 70, 0.0)

tableSectionBuilder1.Origin.Origin.SetValue(Nothing, nullView, point1)
tableSectionBuilder1.Origin.SetInferRelativeToGeometry(True)

Dim nXObject1 As NXObject
nXObject1 = tableSectionBuilder1.Commit()
Dim objects1() As NXObject
objects1 = tableSectionBuilder1.GetCommittedObjects()
tableSectionBuilder1.Destroy()

Dim objectGeneralPropertiesBuilder1 As ObjectGeneralPropertiesBuilder
objectGeneralPropertiesBuilder1 = workPart.PropertiesManager.CreateObjectGeneralPropertiesBuilder(objects1)

Dim selectNXObjectList1 As SelectNXObjectList
selectNXObjectList1 = objectGeneralPropertiesBuilder1.SelectedObjects

objectGeneralPropertiesBuilder1.NameLocationSpecified = False
objectGeneralPropertiesBuilder1.Index = 1
objectGeneralPropertiesBuilder1.Name = "EXAMPLE"

Dim nXObject3 As NXObject
nXObject3 = objectGeneralPropertiesBuilder1.Commit()

If FindTabularNotes(myTabularNoteTags) = 0 Then
'no tabular notes to process
Return
End If
'----------------------------------------------------

Dim tableNote As NXOpen.Tag

For Each tableNote In myTabularNoteTags
tableNote = myTabularNoteTags.Item(0)
ufsession.Tabnot.AskNmRows(tableNote, numRows)
ufsession.Tabnot.AskNmColumns(tableNote, numCols)

'------------------------------------------------------------
'For First row
'-------------------------------------------------------------
For i As Integer = 0 To 0
ufsession.Tabnot.AskNthRow(tableNote, i, rowTag)
ufsession.Tabnot.SetRowHeight(rowTag, 4.5)
For j As Integer = 0 To numCols - 1
ufsession.Tabnot.AskNthColumn(tableNote, j, colTag)
Dim cellTag As Tag
ufsession.Tabnot.AskCellAtRowCol(rowTag, colTag, cellTag)

If j = 0 Then
ufsession.Tabnot.SetColumnWidth(colTag, 35)
ElseIf j = 1 Then
ufsession.Tabnot.SetColumnWidth(colTag, 27)
ElseIf j = 2 Then
ufsession.Tabnot.SetColumnWidth(colTag, 27)
ElseIf j = 3 Then
ufsession.Tabnot.SetColumnWidth(colTag, 27)
ElseIf j = 4 Then
ufsession.Tabnot.SetColumnWidth(colTag, 79)
End If

'Set the RowHeight
ufsession.Tabnot.SetRowHeight(rowTag, 7.1)
'get the current cell preferences
ufsession.Tabnot.AskCellPrefs(cellTag, theCellPrefs)
theCellPrefs.text_aspect_ratio = 0.68
'change the font preference setting
Dim Font As Integer = workPart.Fonts.AddFont("Arial Unicode MS", FontCollection.Type.Standard)
'theCellPrefs.text_aspect_ratio = 0.68

theCellPrefs.text_height = 3.5
theCellPrefs.horiz_just = UFTabnot.Just.JustMiddle
theCellPrefs.vert_just = UFTabnot.Just.JustCenter

Dim LL() As Integer = {4, 1, 5} '------To change the linetype of border
theCellPrefs.bottom_line_cfw = LL
theCellPrefs.right_line_cfw = LL
'apply the new settings to the cell
ufsession.Tabnot.SetCellPrefs(cellTag, theCellPrefs)
ufsession.Tabnot.SetRowHeadCfw(rowTag, LL) '----Sets only the extreme left border of a row -----
' ufsession.Tabnot.SetCellText(cellTag, "")

If j = 0 Then
ufsession.Tabnot.SetCellText(cellTag, "Created By/制图")
End If
Next
Next
Next

End Sub

Function FindTabularNotes(ByRef theTabNotes As List(Of Tag)) As Integer

Dim tmpTabNote As NXOpen.Tag = NXOpen.Tag.Null
Dim type As Integer
Dim subtype As Integer
theSession = Session.GetSession()
workPart = theSession.Parts.Work
ufsession = ufsession.GetUFSession()
displayPart = theSession.Parts.Display

Do
ufsession.Obj.CycleObjsInPart(workPart.Tag, UFConstants.UF_tabular_note_type, tmpTabNote)
If tmpTabNote = NXOpen.Tag.Null Then
Continue Do
End If
If tmpTabNote <> NXOpen.Tag.Null Then
ufsession.Obj.AskTypeAndSubtype(tmpTabNote, type, subtype)
If subtype = UFConstants.UF_tabular_note_subtype Then

theTabNotes.Add(tmpTabNote)

End If
End If
Loop Until tmpTabNote = NXOpen.Tag.Null

Return theTabNotes.Count

End Function

End Module

I suggest adding the font before creating the table; the current code has the .AddFont call in a nested loop, meaning it will be called for every cell in the table. NX will not add the same font multiple times, but there will be a small performance penalty and it is just bad practice. However, for illustration on how to set the cell font, the following small change should work:

ufsession.Tabnot.AskCellPrefs(cellTag, theCellPrefs)
theCellPrefs.text_aspect_ratio = 0.68
'change the font preference setting
Dim Font As Integer = workPart.Fonts.AddFont("Arial Unicode MS", FontCollection.Type.Standard)
theCellPrefs.text_font = Font

theCellPrefs.text_height = 3.5
theCellPrefs.horiz_just = UFTabnot.Just.JustMiddle
theCellPrefs.vert_just = UFTabnot.Just.JustCenter

Dim LL() As Integer = {4, 1, 5} '------To change the linetype of border
theCellPrefs.bottom_line_cfw = LL
theCellPrefs.right_line_cfw = LL
'apply the new settings to the cell
ufsession.Tabnot.SetCellPrefs(cellTag, theCellPrefs)

Note that the "Font" variable is used to specify the cell preference font.

Since you are applying the same preferences to every cell, you can greatly simplify your code by modifying the default cell preferences before creating the tabular note. Psuedocode outlining the strategy is below:

Dim Font As Integer = workPart.Fonts.AddFont("Arial Unicode MS", FontCollection.Type.Standard)
ufsession.Tabnot.AskDefaultCellPrefs(cellTag, theDefaultCellPrefs)
'change default cell prefs, including the font
ufsession.Tabnot.SetDefaultCellPrefs(cellTag, theDefaultCellPrefs)

'create tabular note

Hi,

First of all thanks for suggestion on improving my code skill.

I have tried your suggestion, so I am able to set the required font style. But still when i am inserting the text

("Created By/制图") in cell i am not getting this result.

I am getting "Created By/??" in the cell.

Bhavik S.

Check your "journal file format" option and make sure that it is set to the proper Unicode format that you are using. If it is set to "ASCII", the character values from the journal file are being interpreted as ASCII text instead of unicode characters. This option can be found at: menu -> preferences -> user interface -> journal -> journal file format.

Hi
I have checked in settings and it is set as Unicode....

Bhavik S.

Have you tried the other Unicode options (Unicode big endian and UTF-8)?

If none of them work for you, I'd suggest contacting GTAC. They should be able to track down the issue.