Section line label

Hi, I am using NX 7.5 and need help with the following journal... I need to identify all the section line label and update is to specific font while using journal it is considered as a note. Is there any way to separate this and update the Font as shown below.

Dim generalText1 As Annotations.Lettering
generalText1.Size = 0.1
If note1.GetType().ToString() = "Section Line Label" Then
generalText1.Size = 0.2

End If
generalText1.CharacterSpaceFactor = 1.0
generalText1.AspectRatio = 1.0
generalText1.LineSpaceFactor = 1.0
generalText1.Cfw.Color = 6
generalText1.Cfw.Font = fontIndex1
generalText1.Cfw.Width = Annotations.LineWidth.Thin
letteringPreferences1.SetGeneralText(generalText1)

note1.SetLetteringPreferences(letteringPreferences1)
note1.RedisplayObject()

In interactive NX, if you hover the cursor over the objects, the status line will show "note" or "section line label" or "view and scale label". So NX knows the difference between a note and a section line label; however, I've not found a fool-proof way to differentiate between them with NXOpen code.

The code below looks to see if the text refers to a certain attribute; if it does it then looks to see if the origin is associated to geometry. If the "note" meets both of these criteria, it is assumed to be a section line label. In my testing so far this has successfully identified section line labels; but I would not be surprised if there were a combination of settings that would cause it to return incorrect results. Please post back if you find such a combination.

Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen

Module Module1

Sub Main()

Dim theSession As Session = Session.GetSession()
If IsNothing(theSession.Parts.BaseWork) Then
'active part required
Return
End If

Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()

Const undoMarkName As String = "update section line labels"
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)

Dim sectionLineLabels As New List(Of Annotations.Note)

For Each temp As Annotations.Note In workPart.Notes

Dim theText() As String = temp.GetText
For Each Line As String In theText

'find section line labels
If Line.ToUpper.Contains("SX_SEG_START_LETTER_ATTR") Or Line.ToUpper.Contains("SX_SEG_END_LETTER_ATTR") Then
Dim hasAssociatedOrigin As Boolean = temp.HasAssociativeOrigin

Dim origin As Point3d
Dim originData As Annotations.Annotation.AssociativeOriginData = temp.GetAssociativeOrigin(origin)
If hasAssociatedOrigin And originData.OriginType = Annotations.AssociativeOriginType.RelativeToGeometry Then
sectionLineLabels.Add(temp)
Exit For
End If
End If

Next

Next

Dim fontIndex1 As Integer
fontIndex1 = workPart.Fonts.AddFont("blockfont")

Dim newTextSize As Double = 0.5

For Each temp As Annotations.Note In sectionLineLabels

Dim letteringPreferences1 As Annotations.LetteringPreferences
letteringPreferences1 = temp.GetLetteringPreferences()

Dim generalText1 As Annotations.Lettering
generalText1.Size = newTextSize
generalText1.CharacterSpaceFactor = 1.0
generalText1.AspectRatio = 1.0
generalText1.LineSpaceFactor = 1.0
generalText1.Cfw.Color = 125
generalText1.Cfw.Font = fontIndex1
generalText1.Cfw.Width = Annotations.LineWidth.Thin
letteringPreferences1.SetGeneralText(generalText1)

temp.SetLetteringPreferences(letteringPreferences1)

letteringPreferences1.Dispose()
Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.DoUpdate(markId1)

Next

lw.Close()

End Sub

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

I already found this method
If Text.contains ("SX_SEG") then
'Do Anything
End if
But I felt like this is not the correct way to filter the things.. Anyhow we have stick with this method..... This is my entire code... but still unable to fix things like view label and style (only the views with existing label )

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

' NX Font Update
' Journal created by Alto on 20-05-2015

Module NXJournal
Dim ufs As UFSession = UFSession.GetUFSession()
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Sub Main()
Dim fontIndex1 As Integer
fontIndex1 = workPart.Fonts.AddFont("ideas_iso")

'Update Note Dimension
For Each note1 As Annotations.Note In workPart.Notes

Dim lineAndArrowPreferences1 As Annotations.LineAndArrowPreferences
lineAndArrowPreferences1 = note1.GetLineAndArrowPreferences()

Dim letteringPreferences1 As Annotations.LetteringPreferences
letteringPreferences1 = note1.GetLetteringPreferences()

Dim generalText1 As Annotations.Lettering
generalText1.Size = 0.1
generalText1.CharacterSpaceFactor = 1.0
generalText1.AspectRatio = 1.0
generalText1.LineSpaceFactor = 1.0
generalText1.Cfw.Color = 6
generalText1.Cfw.Font = fontIndex1
generalText1.Cfw.Width = Annotations.LineWidth.Thin
letteringPreferences1.SetGeneralText(generalText1)

note1.SetLetteringPreferences(letteringPreferences1)
note1.RedisplayObject()

Next

'Update Special Notes of BE
For Each note2 As Annotations.Note In workPart.Notes

Dim Text1(0) As String
Text1 = note2.GetText

If Text1(0) = "" Then

Dim lineAndArrowPreferences2 As Annotations.LineAndArrowPreferences
lineAndArrowPreferences2 = note2.GetLineAndArrowPreferences()

Dim letteringPreferences2 As Annotations.LetteringPreferences
letteringPreferences2 = note2.GetLetteringPreferences()

Dim generalText2 As Annotations.Lettering
generalText2.Size = 0.06
generalText2.CharacterSpaceFactor = 1.0
generalText2.AspectRatio = 1.0
generalText2.LineSpaceFactor = 1.0
generalText2.Cfw.Color = 2
generalText2.Cfw.Font = fontIndex1
generalText2.Cfw.Width = Annotations.LineWidth.Thin
letteringPreferences2.SetGeneralText(generalText2)

note2.SetLetteringPreferences(letteringPreferences2)
note2.RedisplayObject()

ElseIf Text1(0) = "" Or Text1(0) = " " Then

Dim lineAndArrowPreferences3 As Annotations.LineAndArrowPreferences
lineAndArrowPreferences3 = note2.GetLineAndArrowPreferences()

Dim letteringPreferences3 As Annotations.LetteringPreferences
letteringPreferences3 = note2.GetLetteringPreferences()

Dim generalText3 As Annotations.Lettering
generalText3.Size = 0.09
generalText3.CharacterSpaceFactor = 1.0
generalText3.AspectRatio = 1.0
generalText3.LineSpaceFactor = 1.0
generalText3.Cfw.Color = 2
generalText3.Cfw.Font = fontIndex1
generalText3.Cfw.Width = Annotations.LineWidth.Thin
letteringPreferences3.SetGeneralText(generalText3)

note2.SetLetteringPreferences(letteringPreferences3)
note2.RedisplayObject()

ElseIf Text1(0) = "" Then

Dim lineAndArrowPreferences4 As Annotations.LineAndArrowPreferences
lineAndArrowPreferences4 = note2.GetLineAndArrowPreferences()

Dim letteringPreferences4 As Annotations.LetteringPreferences
letteringPreferences4 = note2.GetLetteringPreferences()

Dim generalText3 As Annotations.Lettering
generalText3.Size = 0.125
generalText3.CharacterSpaceFactor = 1.0
generalText3.AspectRatio = 1.0
generalText3.LineSpaceFactor = 1.0
generalText3.Cfw.Color = 2
generalText3.Cfw.Font = fontIndex1
generalText3.Cfw.Width = Annotations.LineWidth.Thin
letteringPreferences4.SetGeneralText(generalText3)

note2.SetLetteringPreferences(letteringPreferences4)
note2.RedisplayObject()

ElseIf Text1(0).Contains("SX_SEG") Then

Dim lineAndArrowPreferences7 As Annotations.LineAndArrowPreferences
lineAndArrowPreferences7 = note2.GetLineAndArrowPreferences()

Dim letteringPreferences7 As Annotations.LetteringPreferences
letteringPreferences7 = note2.GetLetteringPreferences()

Dim generalText2 As Annotations.Lettering
generalText2.Size = 0.25
generalText2.CharacterSpaceFactor = 1.0
generalText2.AspectRatio = 1.0
generalText2.LineSpaceFactor = 1.0
generalText2.Cfw.Color = 6
generalText2.Cfw.Font = fontIndex1
generalText2.Cfw.Width = Annotations.LineWidth.Thin
letteringPreferences7.SetGeneralText(generalText2)

note2.SetLetteringPreferences(letteringPreferences7)
note2.RedisplayObject()

End If

Next

'Update Dimension and appended text
Dim Dimension1 As Dimension

For Each Dimension1 In workPart.Dimensions
Dim dimensionPreferences1 As Annotations.DimensionPreferences
dimensionPreferences1 = Dimension1.GetDimensionPreferences()

Dim letteringPreferences5 As Annotations.LetteringPreferences
letteringPreferences5 = Dimension1.GetLetteringPreferences()

Dim dimensionText1 As Annotations.Lettering
dimensionText1.Size = 0.1
dimensionText1.CharacterSpaceFactor = 2.0
dimensionText1.AspectRatio = 1.0
dimensionText1.LineSpaceFactor = 1.0
dimensionText1.Cfw.Color = 6
dimensionText1.Cfw.Font = fontIndex1
dimensionText1.Cfw.Width = Annotations.LineWidth.Thin
letteringPreferences5.SetDimensionText(dimensionText1)
letteringPreferences5.SetAppendedText(dimensionText1)
letteringPreferences5.SetToleranceText(dimensionText1)

Dimension1.SetLetteringPreferences(letteringPreferences5)

Dim lineAndArrowPreferences1 As Annotations.LineAndArrowPreferences
lineAndArrowPreferences1 = Dimension1.GetLineAndArrowPreferences()

dimensionPreferences1.Dispose()
letteringPreferences5.Dispose()
Dimension1.RedisplayObject()
Next

'Update all Id symbols Line and Arrow preferences not included as User need different Arrowheads
For Each Idsymbol1 As Annotations.IdSymbol In workPart.Annotations.IdSymbols
Dim symbolPreferences1 As Annotations.SymbolPreferences
symbolPreferences1 = Idsymbol1.GetSymbolPreferences()

Dim lineAndArrowPreferences1 As Annotations.LineAndArrowPreferences
lineAndArrowPreferences1 = Idsymbol1.GetLineAndArrowPreferences()

Dim letteringPreferences6 As Annotations.LetteringPreferences
letteringPreferences6 = Idsymbol1.GetLetteringPreferences()
Dim generalText4 As Annotations.Lettering
generalText4.Size = 0.1
generalText4.CharacterSpaceFactor = 1.0
generalText4.AspectRatio = 1.0
generalText4.LineSpaceFactor = 1.0
generalText4.Cfw.Color = 6
generalText4.Cfw.Font = fontIndex1
generalText4.Cfw.Width = Annotations.LineWidth.Thin
letteringPreferences6.SetGeneralText(generalText4)
Idsymbol1.SetLetteringPreferences(letteringPreferences6)
symbolPreferences1.IdSymbolSize = 0.35
Idsymbol1.SetSymbolPreferences(symbolPreferences1)
letteringPreferences6.Dispose()
lineAndArrowPreferences1.Dispose()
symbolPreferences1.Dispose()
Idsymbol1.RedisplayObject()
Next
'Update Label Font for all the Labels not letter size factor

Dim NULL_TAG As NXOpen.Tag = NXOpen.Tag.Null
Dim obj As NXOpen.Tag = NULL_TAG

Do
obj = ask_next_drf_entity(obj)
If obj = NULL_TAG Then
GoTo end1
End If
' Check whether returned Tag is UF_draft_label_subtype
Dim type As Integer = Nothing
Dim subtype As Integer = Nothing
ufs.Obj.AskTypeAndSubtype(obj, type, subtype)
Dim nxobj As NXObject = NXObjectManager.Get(obj)
If nxobj.GetType().ToString() <> "NXOpen.Annotations.Label" Then
Continue Do
ElseIf nxobj.GetType().ToString() <> "NXOpen.Annotations.Labelonparent" Then
Dim Label1 As Annotations.Label = nxobj
Dim letteringPreferences7 As Annotations.LetteringPreferences
letteringPreferences7 = Label1.GetLetteringPreferences()

Dim generalText5 As Annotations.Lettering
generalText5.Size = 0.2
generalText5.CharacterSpaceFactor = 1.0
generalText5.AspectRatio = 1.0
generalText5.LineSpaceFactor = 1.0
generalText5.Cfw.Color = 6
generalText5.Cfw.Font = fontIndex1
generalText5.Cfw.Width = Annotations.LineWidth.Thin
letteringPreferences7.SetGeneralText(generalText5)
Label1.SetLetteringPreferences(letteringPreferences7)
letteringPreferences7.Dispose()

Label1.RedisplayObject()
Continue Do

Else

Dim Label1 As Annotations.Label = nxobj
Dim letteringPreferences7 As Annotations.LetteringPreferences
letteringPreferences7 = Label1.GetLetteringPreferences()

Dim generalText5 As Annotations.Lettering
generalText5.Size = 0.2
generalText5.CharacterSpaceFactor = 1.0
generalText5.AspectRatio = 1.0
generalText5.LineSpaceFactor = 1.0
generalText5.Cfw.Color = 6
generalText5.Cfw.Font = fontIndex1
generalText5.Cfw.Width = Annotations.LineWidth.Thin
letteringPreferences7.SetGeneralText(generalText5)
Label1.SetLetteringPreferences(letteringPreferences7)
letteringPreferences7.Dispose()

Label1.RedisplayObject()

End If

Loop Until obj = NULL_TAG
End1:

'Update All table cells
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
ufs.Tabnot.AskNmRows(tableNote, numRows)

Dim numCols As Integer
ufs.Tabnot.AskNmColumns(tableNote, numCols)

Dim tableOrigin(2) As Double
Dim tableSectionTag As Tag
ufs.Tabnot.AskNthSection(tableNote, 0, tableSectionTag)

For i As Integer = 0 To numRows - 1
Dim rowTag As Tag
ufs.Tabnot.AskNthRow(tableNote, i, rowTag)

For j As Integer = 0 To numCols - 1
Dim colTag As Tag
ufs.Tabnot.AskNthColumn(tableNote, j, colTag)

Dim cellTag As Tag
ufs.Tabnot.AskCellAtRowCol(rowTag, colTag, cellTag)

'get the current cell preferences
Dim cellPrefs1 As UFTabnot.CellPrefs
ufs.Tabnot.AskCellPrefs(cellTag, cellPrefs1)

'change the font preference setting

cellPrefs1.format = UFTabnot.Format.FormatText
cellPrefs1.text_font = fontIndex1
cellPrefs1.text_height = 0.06
cellPrefs1.text_aspect_ratio = 1.0 '
cellPrefs1.text_angle = 0.0
cellPrefs1.text_slant = 0.0
cellPrefs1.line_space_factor = 1.0
cellPrefs1.char_space_factor = 1.0
cellPrefs1.text_color = 6
'cellPrefs1.text_density = "Thin"

'apply the new settings to the cell
ufs.Tabnot.SetCellPrefs(cellTag, cellPrefs1)

Next

Next

Next

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
ufs.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
ufs.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 ask_next_drf_entity(ByRef obj As NXOpen.Tag) As NXOpen.Tag
Dim part As NXOpen.Tag = workPart.Tag
ufs.Obj.CycleObjsInPart(part, UFConstants.UF_drafting_entity_type, obj)
Return obj
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

Regards,

Joe

To find the view labels, you could use a similar strategy and look for the text:
"VWLETTER"
and/or
"VWSCALE"

it worked Perfectly.... But I am still trying to figure out the manually placed label...since they don't offer anything to string I will try anyhow...

For Each note3 As Annotations.Note In workPart.Notes

Dim Text2(0) As String
Text2 = note3.GetText
If Text2(0).Contains("VWLETTER") Then
Dim Mytag As NXOpen.Tag = note3.Tag
Dim Labelparms1 As UFDraw.ViewLabelParms = Nothing
ufs.Draw.AskViewLabelParms(Mytag, Labelparms1)
Labelparms1.letter_size_factor = 4.0
ufs.Draw.SetViewLabelParms(Mytag, Labelparms1)
End If

Next

Regards,

Joe

What do you mean by "manually placed label"?
Are you creating your own view labels instead of using the "view label" option in the view style?

In some of the company's old Drawings they used note for labeling on parent so it will not have any string info Tag only it will have the letter for example "A" as a note ... It will be hard to track anyhow its fine as it need to be fixed in our change, So let's user do the change to fix the things...

One more help! Is there anyway to tag the section view by position of section line If it is interfering with solid or it is taken outside from a parent view (like projection).

Regards,

Joe

The journal below illustrates one method to query if anything in the section view is actually sectioned.

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module Module1

Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession()
Dim lw As ListingWindow = theSession.ListingWindow

Sub Main()

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

Dim workPart As Part = theSession.Parts.Work
lw.Open()

Const undoMarkName As String = "NXJ journal"
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)

For Each tempView As Drawings.DraftingView In workPart.DraftingViews
If TypeOf (tempView) Is Drawings.SectionView Then
If IsSectioned(tempView) Then
lw.WriteLine(tempView.Name & " is sectioned")
Else
lw.WriteLine(tempView.Name & " is NOT sectioned")
End If
End If

Next

lw.Close()

End Sub

Function IsSectioned(ByVal sectionView As Drawings.SectionView) As Boolean

Dim sxSolidTags() As Tag
Dim numSxSolids As Integer
theUfSession.Draw.AskSxsolidsOfSxview(sectionView.Tag, Nothing, numSxSolids, sxSolidTags)

'lw.WriteLine("num section solids: " & numSxSolids.ToString)

Return numSxSolids > 0

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