Submitted by dwang953 on Wed, 08/05/2015 - 18:38
Forums:
I want to get all the appended text below a dimension, and I am using the .GetBelowText method from .GetAppenededText. NXOpen says that it is supposed to return a list of strings, but I am having trouble accessing the list?
Dim belowtexts As New List(Of String)
belowtexts = myDimension.GetAppendedText.GetBelowText()
For each belowtext As String in belowtexts
do something...
Next
Would this not work?
If not, how can I iterate through each line of appended text and do what I want to it (format the text)?
re: appended text
The .net reference doc says that the return value is a "list of lines". The actual return value (as shown by the function signature) is an array of type string. Arrays and lists are very similar concepts; the documentation may have been written before "generic lists" were introduced to the .net framework. Since the term "list" now has a very specific meaning in .net, the NXOpen API reference wording is misleading. I'd suggest that you log an incident report (IR) with GTAC to bring it to their attention so it can be improved in future versions.
Thank you! That makes sense.
Thank you! That makes sense. If it's just an array, can i just step through it by index?
Also, it seems that dimensions with no apparent appended text still output blank lines as "appended text". Do you know a way of ignoring these lines besides just checking the string?
re: appended text
You can check the .Length of the returned array; if the .Length = 0, then there is no appended text in that location. The "For Each" loop will make it easy to step through the array values. If desired, blank lines can be found by using the String.IsNullOrWhiteSpace method.
Example snippet below:
Dim myAppendedText As Annotations.AppendedText = myDim.GetAppendedText
Dim aboveText() As String = myAppendedText.GetAboveText
lw.WriteLine("above text number of lines: " & aboveText.Length.ToString)
If aboveText.Length > 0 Then
lw.WriteLine("above text:")
For Each textLine As String In aboveText
If String.IsNullOrWhiteSpace(textLine) Then
lw.WriteLine(" ")
Else
lw.WriteLine(" " & textLine)
End If
Next
End If