cancel
Showing results for 
Search instead for 
Did you mean: 

How To Add Chinese Font In Tabluar Note Through Journal

Pioneer
Pioneer

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.

 

Belwo is the code

 

 

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

10 REPLIES

Re: How To Add Chinese Font In Tabluar Note Through Journal

Phenom
Phenom

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
theDefaultCellPrefs.text_font = Font ufsession.Tabnot.SetDefaultCellPrefs(cellTag, theDefaultCellPrefs)   'create tabular note

Re: How To Add Chinese Font In Tabluar Note Through Journal

Pioneer
Pioneer

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.

The reuslt is shown in attached image.

 

 

Re: How To Add Chinese Font In Tabluar Note Through Journal

Phenom
Phenom

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.

Re: How To Add Chinese Font In Tabluar Note Through Journal

Pioneer
Pioneer

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

Re: How To Add Chinese Font In Tabluar Note Through Journal

Phenom
Phenom

Have you tried the other Unicode options (Unicode big endian and UTF-8)? If none of them work, I'd suggest contacting GTAC.

Re: How To Add Chinese Font In Tabluar Note Through Journal

Esteemed Contributor
Esteemed Contributor

UTF-8 should work best, since NX 10 is also working with UTF-8.

Stefan Pendl, Systemmanager CAx, HAIDLMAIR GmbH
Production: NX10.0.3, VERICUT 8.0, FBM, MRL 3.1.4 | TcUA 10.1 MP7 Patch 0 (10.1.7.0) | TcVis 10.1
Development: VB.NET, Tcl/Tk    Testing: NX11.0 EAP, NX12.0 EAP

How to Get the Most from Your Signature in the Community

Re: How To Add Chinese Font In Tabluar Note Through Journal

Pioneer
Pioneer

HI

 

I have tried the options thaat you have suggested.

I have used below code to set journal format.

If I will add chinese font manually in tabular note then it is coming But thorugh journal it is not coming.

 

theSession.Preferences.UserInterface.JournalLanguage = Preferences.SessionUserInterface.JournalLanguageType.VisualBasic
theSession.Preferences.UserInterface.JournalFileFormat = Preferences.SessionUserInterface.JournalFileFormatType.Utf8

Re: How To Add Chinese Font In Tabluar Note Through Journal

Esteemed Contributor
Esteemed Contributor

Do not set these preferences in the journal, they only work correctly if set through the customer defaults or before you record a journal.

They do not take affect for replaying a journal.

Stefan Pendl, Systemmanager CAx, HAIDLMAIR GmbH
Production: NX10.0.3, VERICUT 8.0, FBM, MRL 3.1.4 | TcUA 10.1 MP7 Patch 0 (10.1.7.0) | TcVis 10.1
Development: VB.NET, Tcl/Tk    Testing: NX11.0 EAP, NX12.0 EAP

How to Get the Most from Your Signature in the Community

Re: How To Add Chinese Font In Tabluar Note Through Journal

Pioneer
Pioneer

Hi,

 

I have set the prefernece to UFT-8 externally and ran my journal to execute. But i am getting error message as shown in attached image.

I have tried both the options UTF-8 and Unicode big endian.

I am using NX10.