Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Replacing Text In A Table Cell By NX Journal

Status
Not open for further replies.

EricFish

Mechanical
Jan 13, 2023
2
Hi All,

I am new to the NX journal and I recorded a journal that replaces text in one of the table cell in the title blocks on my drawing.

I figured that because of the selection stickiness, I can't use it on other drawings.

My initial thought was to specify the location of the cell with other method to replace the "FindObject" but I couldn't find instructions on how to do it.

Can someone help me with removing the selection stickiness or point me to the correct direction?

I am working with NX 12. Here is the recorded code. Thanks!


Imports System
Imports NXOpen

Module NXJournal
Sub Main (ByVal args() As String)

Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
Dim workPart As NXOpen.Part = theSession.Parts.Work

Dim displayPart As NXOpen.Part = theSession.Parts.Display

Dim markId1 As NXOpen.Session.UndoMarkId = Nothing
markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Edit Cell")

Dim table1 As NXOpen.Annotations.Table = CType(workPart.Annotations.Tables.FindObject("HANDLE R-9610"), NXOpen.Annotations.Table)

Dim displayableObject1 As NXOpen.DisplayableObject = CType(workPart.FindObject("HANDLE R-9508"), NXOpen.DisplayableObject)

table1.EditCellText(displayableObject1, "NA")

' ----------------------------------------------
' Menu: Tools->Journal->Stop Recording
' ----------------------------------------------

End Sub
End Module
 
Replies continue below

Recommended for you

Hello,

if You have cell to change in this same place, You can try use journal bellow.
You must select table to change, and write text to input box.
I do it for cell with column and row = 0, and You can change it.

Code:
<VB>
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpenUI
Imports System.Windows.Forms
Imports System.Environment


Module EditCellOfTable

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

    Dim workPart As NXOpen.Part = theSession.Parts.Work

    Dim displayPart As NXOpen.Part = theSession.Parts.Display


    '  Explicit Activation
    '      This entry point is used to activate the application explicitly
    Sub Main()

        Dim tabular_note_section As NXOpen.Tag
        Dim tabular_note As NXOpen.Tag
        Dim row As NXOpen.Tag
        Dim col As NXOpen.Tag
        Dim cell As NXOpen.Tag

        nxopenSession = NXOpen.UF.UFSession.GetUFSession()
        Dim markId1 As NXOpen.Session.UndoMarkId = Nothing
        markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start")

        While select_a_tabular_note(tabular_note_section) = Selection.Response.Ok

            ' now get the tabular note tag from the section tag:
            nxopenSession.Tabnot.AskTabularNoteOfSection(tabular_note_section, tabular_note)



            Dim initialText As String = (ReadCellText(tabular_note, 0, 0))

            Dim text As String
            text = NXInputBox.GetInputString("Give me cell text", "Cell text", initialText)

            WriteCellText(tabular_note, 0, 0, text)


        End While
        theSession.SetUndoMarkVisibility(markId1, Nothing, NXOpen.Session.MarkVisibility.Visible)
    End Sub

    ' function for select tablular note tag
    Function select_a_tabular_note(ByRef tabular_note As NXOpen.Tag) As Selection.Response

        Dim message As String
        Dim title As String = "Select a tabular note"
        Dim scope As Integer = UFConstants.UF_UI_SEL_SCOPE_ANY_IN_ASSEMBLY
        Dim response As Integer
        Dim obj As NXOpen.Tag
        Dim view As NXOpen.Tag
        Dim cursor(2) As Double
        Dim ip As UFUi.SelInitFnT = AddressOf init_proc
        nxopenSession.Ui.LockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)

        Try
            nxopenSession.Ui.SelectWithSingleDialog(message, title, scope, ip, Nothing, response, tabular_note, cursor, view)
        Finally
            nxopenSession.Ui.UnlockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)
        End Try

        If response <> UFConstants.UF_UI_OBJECT_SELECTED Then
            Return Selection.Response.Cancel
        Else
            Return Selection.Response.Ok
        End If

    End Function

    Function init_proc(ByVal select_ As IntPtr, ByVal userdata As IntPtr) As Integer
        ' Selection initialization

        Dim num_triples As Integer = 1
        Dim mask_triples(0) As UFUi.Mask
        mask_triples(0).object_type = UFConstants.UF_tabular_note_type
        mask_triples(0).object_subtype = UFConstants.UF_tabular_note_section_subtype
        mask_triples(0).solid_type = 0

        nxopenSession.Ui.SetSelMask(select_, UFUi.SelMaskAction.SelMaskClearAndEnableSpecific, num_triples, mask_triples)
        Return UFConstants.UF_UI_SEL_SUCCESS

    End Function

    Function ReadCellText(ByVal tableTag As Tag, ByVal columnNo As Integer, ByVal rowNo As Integer) As String

        Dim rowTag As Tag = Nothing
        Dim colTag As Tag = Nothing
        Dim cellTag As Tag = Nothing
        Try
            theUfSession.Tabnot.AskNthRow(tableTag, rowNo, rowTag)
            theUfSession.Tabnot.AskNthColumn(tableTag, columnNo, colTag)
            theUfSession.Tabnot.AskCellAtRowCol(rowTag, colTag, cellTag)
            Dim cellText As String = ""
            'Dim evalCellText As String = ""
            theUfSession.Tabnot.AskCellText(cellTag, cellText)
            'Dim evalCellText As String = ""
            'theUfSession.Tabnot.AskEvaluatedCellText(cellTag, evalCellText)
            Return cellText
        Catch
            Return ""
        End Try

    End Function
    Sub WriteCellText(ByVal tableTag As Tag, ByVal columnNo As Integer, ByVal rowNo As Integer, ByVal celltext As String)

        Dim rowTag As Tag = Nothing
        Dim colTag As Tag = Nothing
        Dim cellTag As Tag = Nothing
        'Try
        theUfSession.Tabnot.AskNthRow(tableTag, rowNo, rowTag)
        theUfSession.Tabnot.AskNthColumn(tableTag, columnNo, colTag)
        theUfSession.Tabnot.AskCellAtRowCol(rowTag, colTag, cellTag)
        'MsgBox(columnNo & "  " & rowNo)
        theUfSession.Tabnot.SetCellText(cellTag, celltext)

    End Sub



    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        'Unloads the image when the NX session terminates
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination

        '----Other unload options-------
        'Unloads the image immediately after execution within NX
        'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

        'Unloads the image explicitly, via an unload dialog
        'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Explicitly
        '-------------------------------

    End Function


End Module
<\VB>

I try it in NX2027 (or something near). If You have some problem with journal settings, I try run NX12.

Best regards

MANok
NX2027
TC14
 
Thanks for the help MANox!

This works prefect for me.

Since I want to use this journal to pre fill some of the cells on the title block, I changed the user input into simple strings and created couple user commands for different tables.

I think this is a great work around for what I was trying to do. My question is: if there is way to specify all the tables that I need to edit so I can combine the user commands into one and update the cells in one click? I noticed that the all the tabular notes do not have a name associate to them on the drawing. so I am not sure if this is possible to do with NX journal.

Thank!
 
Hello EricFish,

"if there is way to specify all the tables?"

I was do this with add names to tables (in properties), and after I create ListOf tables, and after with select case (by name) I work with every table.

This is code to select table by name:

Code:
Dim myStartTabNotes As New List(Of Tag)
        FindTabularSectionNotes(myStartTabNotes)

        Dim myTabNotes As New List(Of Tag)
        For Each tabNote As Tag In myStartTabNotes
            Dim tablesection1 As NXOpen.Annotations.TableSection
            tablesection1 = NXOpen.Utilities.NXObjectManager.Get(tabNote)

            Select Case tablesection1.Name
                Case "table_1", "table_2", "table_3", "table_4"
                    myTabNotes.Add(tabNote)
            End Select
        Next

        If myTabNotes.Count = 0 Then
            MsgBox("Drawing haven't tables with names. Sorry.", MsgBoxStyle.OkOnly, "Oops!... I did It again")
            Exit Sub
        End If
and Procedure FindTabularSectionNotes:
Code:
Sub FindTabularSectionNotes(ByRef tagList As List(Of Tag))

        Dim tmpTabNote As NXOpen.Tag = NXOpen.Tag.Null
        Dim NxType As Integer
        Dim NxSubtype As Integer

        Do
            theUfSession.Obj.CycleObjsInPart(workPart.Tag, UFConstants.UF_tabular_note_type, tmpTabNote)
            If tmpTabNote <> NXOpen.Tag.Null Then
                theUfSession.Obj.AskTypeAndSubtype(tmpTabNote, NxType, NxSubtype)
                If NxSubtype = UFConstants.UF_tabular_note_section_subtype Then
                    tagList.Add(tmpTabNote)

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

    End Sub

If You have old tables without names, You can try identyfity its by size (or/and text in selected cells) and after add name.
If You need help with this - write and I can find and send part of code to help convert table to more usefull for You.

In my work I use UserForm. Journal read date from table, show its in UserForm, and after click OK actualize date in table.

Best regards and nice works with journals


MANox
NX2027
TC14


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor