Cancel
Showing results for 
Search instead for 
Did you mean: 

Add Row in Top to bottom to direction

Pioneer
Pioneer

HI I am trying to add row in Table. I am able to add the row in direction from bottom to top and I have used below code for that.I

 

But i want to add row from top to bottom direction.
Please help..

 

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports Insert_View_SH
Imports System.Threading
Imports System.Reflection
Imports System.Collections.Generic
Imports NXOpen.Annotations
Module module11
    Dim theSession As Session
    Dim ufsession As UFSession
    Dim workPart As NXOpen.Part
    Dim displayPart As NXOpen.Part
    Dim dwgSheet As Drawings.DrawingSheet
    Dim dwgShtBld As Drawings.DrawingSheetBuilder
    Dim OH As Double
    Dim dwgSheetList As New List(Of String)
    Dim myTabNotes As New List(Of Annotations.TableSection)
    Dim myTabularNoteTags As New List(Of Tag)
    Dim numCols As Integer
    Dim numRows As Integer
    Dim cellTag As NXOpen.Tag
    Dim rowTag As NXOpen.Tag
    Dim theCellPrefs As UFTabnot.CellPrefs
    Dim colTag As Tag
    Dim startcellTag As Tag
    Dim endcellTag As Tag
    Dim RowHeight1() As Double
    Dim RowHeight2() As Double
 
  Sub Main()
 
        theSession = Session.GetSession()
        workPart = theSession.Parts.Work
        ufsession = ufsession.GetUFSession()
        displayPart = theSession.Parts.Display
 
        dwgShtBld = workPart.DrawingSheets.DrawingSheetBuilder(workPart.DrawingSheets.CurrentDrawingSheet)
 
        ' ----------------------------------------------
 
        If FindTabularNotes(myTabularNoteTags) = 0 Then
            'no tabular notes to process
            Return
        End If
 
        Dim k As Integer
 
        '--------------Get row height of each row------3columns
        For Each tableNote As Tag In myTabularNoteTags
            tableNote = myTabularNoteTags.Item(0)
            ufsession.Tabnot.AskNmRows(tableNote, numRows)
            ReDim RowHeight2(numRows)
            RowHeight2(0) = 7
            For i As Integer = 0 To numRows - 1
                ufsession.Tabnot.AskNthRow(tableNote, i, rowTag)
                ufsession.Tabnot.AskRowHeight(rowTag, RowHeight2(i + 1))
            Next
            Exit For
        Next
 
        '  -------------------------------------------------------------
        For Each tableNote As Tag In myTabularNoteTags
            tableNote = myTabularNoteTags.Item(0)
            For k = 0 To 0
                If k = 0 Then
                    Dim numRows As Integer
                    ufsession.Tabnot.AskNmRows(tableNote, numRows)
                    Dim numCols As Integer
                    ufsession.Tabnot.AskNmColumns(tableNote, numCols)
 
                    '------------------------------------------------------------
                    'For First row
                    '-------------------------------------------------------------
                    For i As Integer = 0 To 0
                        Dim rowTag As Tag
                        ufsession.Tabnot.AskNthRow(tableNote, i, rowTag)
                        ufsession.Tabnot.CreateRow(7, rowTag)
                        ufsession.Tabnot.AddRow(tableNote, rowTag, 0) 'UFConstants.UF_TABNOT_APPEND) '----- Adds at the top
 
                        For j As Integer = 0 To numCols - 1
                            ufsession.Tabnot.AskNthColumn(tableNote, j, colTag)
                            ufsession.Tabnot.AskCellAtRowCol(rowTag, colTag, cellTag)
                            If j = 0 Then
                                startcellTag = cellTag
                            ElseIf j = numCols - 1 Then
                                endcellTag = cellTag
                            End If
                            'get the current cell preferences
                            ufsession.Tabnot.AskCellPrefs(cellTag, theCellPrefs)
                            theCellPrefs.text_aspect_ratio = 0.68
                            'change the font preference setting
                            Dim fntMonoBT As Integer = workPart.Fonts.AddFont("Monospac821 BT", FontCollection.Type.Standard)
                            theCellPrefs.text_font = 8
                            theCellPrefs.text_height = 3.2
                            theCellPrefs.horiz_just = UFTabnot.Just.JustMiddle
                            theCellPrefs.vert_just = UFTabnot.Just.JustCenter
 
                            Dim LineType() As Integer = {4, 1, 5}     '------To change the linetype of border (Doted type)
                            theCellPrefs.bottom_line_cfw = LineType
                            theCellPrefs.right_line_cfw = LineType
                            'apply the new settings to the cell
                            ufsession.Tabnot.SetCellPrefs(cellTag, theCellPrefs)
                            ufsession.Tabnot.SetRowHeadCfw(rowTag, LineType) '----Sets only the extreme left border of a row -----
 
                            theCellPrefs.horiz_just = UFTabnot.Just.JustMiddle
                            theCellPrefs.vert_just = UFTabnot.Just.JustCenter
                            ufsession.Tabnot.SetCellPrefs(cellTag, theCellPrefs)
                        Next
                    Next
                End If
            Next
        Next
 
 
 
        For Each tableNote As Tag In myTabularNoteTags
            tableNote = myTabularNoteTags.Item(1)       '---For three columns table
            ufsession.Tabnot.AskNmRows(tableNote, numRows)
            For i = 0 To numRows - 1 ' - 2
                ufsession.Tabnot.AskNthRow(tableNote, i, rowTag)
                ufsession.Tabnot.SetRowHeight(rowTag, RowHeight2(i))
            Next
            Exit For
        Next
 
        dwgShtBld.Commit()
        dwgShtBld.Destroy()
 
 
 
    End Sub
 
	 Function FindTabularNotes(ByRef theTabNotes As List(Of Tag)) As Integer '----For after adding the table
        'myTabularNoteTags
 
        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