Submitted by jelrae_farsun on Tue, 12/06/2016 - 07:58
Forums:
As the subject hints, I am trying to remove a newline character from cells in a tabular note and replace them with a space. For example:
Sub
Assembly
to
Sub Assembly
How can I do this? I have tried:
cellText.Replace(vbCr, " ").Replace(vbLf, " ").Replace(vbCrLf, " ").Replace("\r\n", " ").Replace("\n", " ").Replace("\r", " ")
But no dice. Any help would be greatly appreciated.
re: newline in tabular note
I would suggest that you first check the "fit methods" applied to the cell(s) in question. The "wrap" fit method will break text into multiple lines even if there is no newline character in the original string.
re: new line in tabular note
Try checking for "Chr(10)" within the string. The code below seems to work (not heavily tested):
Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF
Module Module1
Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession
Dim workPart As Part = theSession.Parts.Work
Sub Main()
If IsNothing(theSession.Parts.Work) Then
'active part required
Return
End If
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()
Const undoMarkName As String = "tabular note line break"
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)
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 numRows As Integer
theUfSession.Tabnot.AskNmRows(tableNote, numRows)
Dim numCols As Integer
theUfSession.Tabnot.AskNmColumns(tableNote, numCols)
Dim tableOrigin(2) As Double
Dim tableSectionTag As Tag
theUfSession.Tabnot.AskNthSection(tableNote, 0, tableSectionTag)
For i As Integer = 0 To numRows - 1
Dim rowTag As Tag
theUfSession.Tabnot.AskNthRow(tableNote, i, rowTag)
For j As Integer = 0 To numCols - 1
Dim colTag As Tag
theUfSession.Tabnot.AskNthColumn(tableNote, j, colTag)
Dim cellTag As Tag
theUfSession.Tabnot.AskCellAtRowCol(rowTag, colTag, cellTag)
Dim theCellText As String = Nothing
theUfSession.Tabnot.AskCellText(cellTag, theCellText)
lw.WriteLine("cell tag: " & cellTag.ToString)
lw.WriteLine("cell text: " & theCellText)
lw.WriteLine("contains line break: " & theCellText.Contains(Chr(10)).ToString)
Next
Next
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 immediately after execution within NX
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
End Function
End Module