Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

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

i try to find get the title of a attribute for a tabular note, but failed

Status
Not open for further replies.

godpaul

Automotive
Joined
May 4, 2014
Messages
119
Location
US
i first recorded the journal to see what code it will give to you if i try to modify the title of attribute. then i get the code and modify it with my understanding

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.Annotations
Imports NXOpen.UI
Imports NXOpen.UF
Imports NXOpen.Utilities
Imports System.Windows.Forms
Imports System.Collections.Generic
Imports System.Environment

Module replace_tabular_note_experiment

Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession
Dim workPart As Part = theSession.Parts.Work
Dim theUI As UI = UI.GetUI()

Sub Main()

If IsNothing(theSession.Parts.Work) Then
'active part required
Return
End If

Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()

Dim myTabularNoteTags As New List(Of Tag)
If FindTabularNotes(myTabularNoteTags) = 0 Then
'no tabular notes to process
Return
End If


For Each tableNote As Tag In myTabularNoteTags

Dim obj(0) As NXObject
Dim tableSection As Annotations.TableSection = CType(workPart.Annotations.TableSections.FindObject("tableNote"), Annotations.TableSection)
obj(0) = tableSection
Dim attribute As AttributePropertiesBuilder
attribute = theSession.AttributeManager.CreateAttributePropertiesBuilder(workPart, obj, AttributePropertiesBuilder.OperationType.None)
Dim titleName As String = attribute.Title

lw.WriteLine(titleName)
Exit 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

Do
theUfSession.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
theUfSession.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




error is no objects is found with this name "tableNote". the "tableNote" is right click property general tab and revise the name there

 
here is the only codes i came up with last night...... it works an no error BUT didnt return correct result
after the program runs, it returns Table 32434, whose digits can vary from session to session.......

Code:
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.Annotations
Imports NXOpen.UI
Imports NXOpen.UF
Imports NXOpen.Utilities
Imports System.Windows.Forms
Imports System.Collections.Generic
Imports System.Environment

Module replace_tabular_note_experiment

    Dim theSession As Session = Session.GetSession()
    Dim theUfSession As UFSession = UFSession.GetUFSession
    Dim workPart As Part = theSession.Parts.Work
    Dim theUI As UI = UI.GetUI()

    Sub Main()

        If IsNothing(theSession.Parts.Work) Then
            'active part required
            Return
        End If

        Dim lw As ListingWindow = theSession.ListingWindow
        lw.Open()

        Dim myTabularNoteTags As New List(Of Tag)
        If FindTabularNotes(myTabularNoteTags) = 0 Then
            'no tabular notes to process
            Return
        End If

        ''get excel file ready
        'Dim objExcel = CreateObject("Excel.Application")
        'If objExcel Is Nothing Then
        '    MsgBox("Could not start Excel, this journal will now exit.", MsgBoxStyle.Critical, "Error")
        '    Exit Sub
        'End If
        ''excel file location
        'Dim excelFile As String = "k:\excelsheet.xlsx"
        'If Not IO.File.Exists(excelFile) Then
        '    MsgBox("Specified file not found, journal will now exit.", MsgBoxStyle.Critical, "File not found.")
        '    Exit Sub
        'End If
        ''open excel file
        'Dim objWorkbook = objExcel.Workbooks.Open(excelFile)
        'If objWorkbook Is Nothing Then
        '    MsgBox("Could not open Excel file, journal will now exit.", MsgBoxStyle.Critical, "Error")
        '    Exit Sub
        'End If

        Dim emptyStr As String = ""

        For Each tableNote As Tag In myTabularNoteTags
            Dim tableTitle As String
            Dim rowTag As Tag
            Dim colTag As Tag
            Dim cellTag As Tag
            'get the title info from the current table, not the best way, i want to get the property name...later
            theUfSession.Tabnot.AskNthRow(tableNote, 0, rowTag)
            theUfSession.Tabnot.AskNthColumn(tableNote, 0, colTag)
            theUfSession.Tabnot.AskCellAtRowCol(rowTag, colTag, cellTag)
            theUfSession.Tabnot.AskCellText(cellTag, tableTitle)

[b]            Dim obj As NXObject
            obj = theUfSession.GetObjectManager.GetTaggedObject(tableNote)
            Dim ai As NXObject.AttributeInformation() = obj.GetUserAttributes
            lw.WriteLine(obj.ToString())
            lw.WriteLine(obj.Name)[/b]        Next
        lw.Close()

    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

        Do
            theUfSession.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
                theUfSession.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

    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.LibraryUnAloadOption.Explicitly
        '-------------------------------

    End Function

End Module
 
i am exhausted....

so far, find two ways, one is get unique ID no of each table on drawing which is:

Code:
            Dim ID As UInteger = 0
            Dim version As UInteger = 0
            Dim fileData As String = Nothing
            Dim handle As String = theUfSession.Tag.AskHandleOfTag(tableNote)
            theUfSession.Tag.DecomposeHandle(handle, fileData, ID, version)
            lw.WriteLine(ID)

this return ID no. like 4892832 34324839 etc, etc, they really dont change from session to session, but too hard to handle....


another one is attributeproperty builder which is

Code:
        Dim obj(0) As NXObject
            obj(0) = NXObjectManager.Get(tableNote)
            Dim attributePropertiesBuilder1 As AttributePropertiesBuilder
            attributePropertiesBuilder1 = theSession.AttributeManager.CreateAttributePropertiesBuilder(workPart, obj, AttributePropertiesBuilder.OperationType.None)
            Dim str As String = attributePropertiesBuilder1.Title
            lw.WriteLine(str)

however, this returns nothing..........


if you replace the code highilighed with bold font from the upper reply with the code here, you will see..

help needed..

here is the drawing fiel contains two tables and they have title and name in the attribute
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top