Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations MintJulep on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem when special char in journal > vb.net and Blockstyler 1

Status
Not open for further replies.

lklo

Industrial
Nov 24, 2010
226
hi
I'm a little challenged regarding a program I'm doing these weeks....NXOpen API
It's about the special char ....

A. I need to be able to set a string(which contains this ∆ (triangle)) in a cell in a tabNote....
I tried in NX8.5...in this case the is changed to ? or # , when set from journal..
I also tried in NX10....then nothing where set - just an error...see attach pic
I both NX 8.5 and NX 10 - it's possible to output a in a msgbox from a journal...but not in a tabNote cell....
It's also possible to manuel paste a ∆ into a cell in a tabNote.....

here is small code...(remember "name_of_tabNote")
Code:
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module test_my_triangle

    Dim theSession As Session = Session.GetSession()
    Dim theUfSession As UFSession = UFSession.GetUFSession()

    Sub Main()
        Dim theTabNoteTag As Tag
        theTabNoteTag = Find_TabNote_of_Given_Name("name_of_tabNote")
        If theTabNoteTag = Tag.Null Then Return
        '===========================================================================

        ' test A
        msgbox("Δ") ' works

        ' test B
        Set_theTabnote_Cell_Text(theTabNoteTag, 1, 0, "∆") 'do not work
        ' test C
        Set_theTabnote_Cell_Text(theTabNoteTag, 2, 0, "Δ") 'do not work

        '===========================================================================

    End Sub

    Public Function Find_TabNote_of_Given_Name(ByVal name As String) As Tag
        Dim tempTag As Tag = Tag.Null
        Dim tabNoteTag As Tag = Tag.Null
        Dim theDispPart As Part = theSession.Parts.Display
        Dim type, subType As Integer
        Do
            theUfSession.Obj.CycleByNameAndType(theDispPart.Tag, name, UFConstants.UF_tabular_note_type, False, tempTag)
            If tempTag = NXOpen.Tag.Null Then
                Continue Do
            End If
            theUfSession.Obj.AskTypeAndSubtype(tempTag, type, subType)
            If subType = UFConstants.UF_tabular_note_section_subtype Then
                theUfSession.Tabnot.AskTabularNoteOfSection(tempTag, tabNoteTag)
                Return tabNoteTag
            End If
        Loop Until tempTag = NXOpen.Tag.Null ' No more tabular notes are found
        Return Tag.Null
    End Function
    Public Sub Set_theTabnote_Cell_Text(ByVal tabular_note As Tag, ByVal rowIndex As Integer, _
         ByVal colIndex As Integer, ByVal newText As String)
        Dim row As NXOpen.Tag
        Dim col As NXOpen.Tag
        Dim cell As NXOpen.Tag

        theUfSession.Tabnot.AskNthRow(tabular_note, rowIndex, row)
        theUfSession.Tabnot.AskNthColumn(tabular_note, colIndex, col)
        theUfSession.Tabnot.AskCellAtRowCol(row, col, cell)
        theUfSession.Tabnot.SetCellText(cell, newText)

    End Sub
    Public Function GetUnloadOption(ByVal dummy As String) As Integer
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
    End Function
End Module

B. I also tried to use a in Blockstyler..
In NX 8.5 when the is used in a text in a Radio button > output in dialog is a #
But in NX 10 this works as expected...see pic...

I will look forward, if anyone have some suggestions...

lklo

 
 http://files.engineering.com/getfile.aspx?folder=426af7b5-892c-4f76-bbe7-b33a498cbbf3&file=triangle_blockstyler.zip
Replies continue below

Recommended for you

NX 10 is (iirc) the first version to have full unicode support. Make sure the "journal file format" preference is set to one of the unicode variants (find one that works for you). You may need to set a similar preference in your code editor as well.

www.nxjournaling.com
 
Hi Cowski -
thanks a lot for your reply...

A. Yeahh , seems like that Blockstyler dialog's in NX 10 have unicode support...
B.. Regarding my vb code - I found the trick...
Maybe you'll find it usefull...
Here it comes:
ufs.Text.SetTextMode(UFText.ModeS.AllUtf8) 'enums: AllUtf8,Utf8 or Locale

Now I can simply put in my triangle directly in the code...

Code:
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module test_my_triangle

    Dim theSession As Session = Session.GetSession()
    Dim theUfSession As UFSession = UFSession.GetUFSession()
    Dim ufs As UFSession = UFSession.GetUFSession()
    Sub Main()
        Dim theTabNoteTag As Tag
        theTabNoteTag = Find_TabNote_of_Given_Name("name_of_tabNote")
        If theTabNoteTag = Tag.Null Then Return
        '===========================================================================
        [b]ufs.Text.SetTextMode(UFText.ModeS.AllUtf8)[/b] ' here is the trick
        Dim str As String = "Δ"
        ' test B
        Set_theTabnote_Cell_Text(theTabNoteTag, 1, 1, str) 'do now work

        '===========================================================================

    End Sub
        Public Function Find_TabNote_of_Given_Name(ByVal name As String) As Tag
        Dim tempTag As Tag = Tag.Null
        Dim tabNoteTag As Tag = Tag.Null
        Dim theDispPart As Part = theSession.Parts.Display
        Dim type, subType As Integer
        Do
            theUfSession.Obj.CycleByNameAndType(theDispPart.Tag, name, UFConstants.UF_tabular_note_type, False, tempTag)
            If tempTag = NXOpen.Tag.Null Then
                Continue Do
            End If
            theUfSession.Obj.AskTypeAndSubtype(tempTag, type, subType)
            If subType = UFConstants.UF_tabular_note_section_subtype Then
                theUfSession.Tabnot.AskTabularNoteOfSection(tempTag, tabNoteTag)
                Return tabNoteTag
            End If
        Loop Until tempTag = NXOpen.Tag.Null ' No more tabular notes are found
        Return Tag.Null
    End Function
    Public Sub Set_theTabnote_Cell_Text(ByVal tabular_note As Tag, ByVal rowIndex As Integer, _
         ByVal colIndex As Integer, ByVal newText As String)
        Dim row As NXOpen.Tag
        Dim col As NXOpen.Tag
        Dim cell As NXOpen.Tag

        theUfSession.Tabnot.AskNthRow(tabular_note, rowIndex, row)
        theUfSession.Tabnot.AskNthColumn(tabular_note, colIndex, col)
        theUfSession.Tabnot.AskCellAtRowCol(row, col, cell)
        theUfSession.Tabnot.SetCellText(cell, newText)

    End Sub
    Public Function GetUnloadOption(ByVal dummy As String) As Integer
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
    End Function
End Module

lklo
 
Hi again -
just a small update on code..
Now I ask for original TextMode before changing - and the restore again when "cell writing" is done....

Code:
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module test_my_triangle

    Dim theSession As Session = Session.GetSession()
    Dim theUfSession As UFSession = UFSession.GetUFSession()
    Dim ufs As UFSession = UFSession.GetUFSession()
    Sub Main()
        Dim theTabNoteTag As Tag
        theTabNoteTag = Find_TabNote_of_Given_Name("name_of_tabNote")
        If theTabNoteTag = Tag.Null Then Return
        '===========================================================================
        [b]Dim orignalTextMode As UFText.ModeS = ufs.Text.AskTextMode() 'rememeber
[/b]        Dim str As String = "Δ"
        ' test A
        [b]ufs.Text.SetTextMode(UFText.ModeS.AllUtf8)[/b] ' set temporary yo Utf
        Set_theTabnote_Cell_Text(theTabNoteTag, 1, 1, str) 'do now work

        str = "lars" ' try comment out
        ' test B
        [b]ufs.Text.SetTextMode(orignalTextMode)[/b] ' set back again to part original
        Set_theTabnote_Cell_Text(theTabNoteTag, 1, 2, str) 'now it fails again if str = "Δ" - as expected

        '===========================================================================

    End Sub
        Public Function Find_TabNote_of_Given_Name(ByVal name As String) As Tag
        Dim tempTag As Tag = Tag.Null
        Dim tabNoteTag As Tag = Tag.Null
        Dim theDispPart As Part = theSession.Parts.Display
        Dim type, subType As Integer
        Do
            theUfSession.Obj.CycleByNameAndType(theDispPart.Tag, name, UFConstants.UF_tabular_note_type, False, tempTag)
            If tempTag = NXOpen.Tag.Null Then
                Continue Do
            End If
            theUfSession.Obj.AskTypeAndSubtype(tempTag, type, subType)
            If subType = UFConstants.UF_tabular_note_section_subtype Then
                theUfSession.Tabnot.AskTabularNoteOfSection(tempTag, tabNoteTag)
                Return tabNoteTag
            End If
        Loop Until tempTag = NXOpen.Tag.Null ' No more tabular notes are found
        Return Tag.Null
    End Function
    Public Sub Set_theTabnote_Cell_Text(ByVal tabular_note As Tag, ByVal rowIndex As Integer, _
         ByVal colIndex As Integer, ByVal newText As String)
        Dim row As NXOpen.Tag
        Dim col As NXOpen.Tag
        Dim cell As NXOpen.Tag

        theUfSession.Tabnot.AskNthRow(tabular_note, rowIndex, row)
        theUfSession.Tabnot.AskNthColumn(tabular_note, colIndex, col)
        theUfSession.Tabnot.AskCellAtRowCol(row, col, cell)
        theUfSession.Tabnot.SetCellText(cell, newText)

    End Sub
    Public Function GetUnloadOption(ByVal dummy As String) As Integer
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
    End Function
End Module
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor