Let user select a symbolic thread

Hi
I'm looking for a journal that will make a user select a symbolic thread.

I only found a code that reads data from every symbolic thread in work part.

Here’s the code:

Thank you


Imports System
Imports NXOpen
Imports NXOpen.UF

Public Class NXJournal
Shared theSession As Session = Session.GetSession()
Shared theUFSession As UFSession = UFSession.GetUFSession()
Shared workPart As Part = theSession.Parts.Work

Private Shared Sub DoIt()
For Each aFeature As NXOpen.Features.Feature In workPart.Features

If aFeature.FeatureType.Equals("SYMBOLIC_THREAD") Then
Echo(aFeature.GetFeatureName())
Dim data As UFModl.SymbThreadData = New UFModl.SymbThreadData()
theUFSession.Modl.AskSymbThreadParms(aFeature.Tag, data)
' Echo(" Angle: " & data.angle)
' Echo(" Axis: " & data.axis_direction(0) & " " + data.axis_direction(1) & " " + data.axis_direction(2))

If data.callout.Length > 1 Then
Echo(" Callout: " & data.callout)
Else
Echo(" Callout: None (manual input)")
End If

Echo(" CylFace: " & data.cyl_face.ToString())
Echo(" Form: " & data.form)
Echo(" IncludeInstances: " & data.include_instances.ToString())
Echo(" InternalThread: " & data.internal_thread.ToString())
Echo(" Length: " & data.length)
Echo(" LengthFlag: " & data.length_flag.ToString())
Echo(" MajorDia: " & data.major_dia)
Echo(" Method: " & data.method)
Echo(" MinorDia: " & data.minor_dia)
Echo(" NumStarts: " & data.num_starts.ToString())
Echo(" Pitch: " & data.pitch)
Echo(" Rotation: " & data.rotation)
Echo(" StartFace: " & data.start_face.ToString())
Echo(" Tapered: " & data.tapered.ToString())
Echo(" TappedDia: " & data.tapped_dia)
End If
Next
End Sub

Public Shared Sub Main(ByVal args As String())
If workPart IsNot Nothing Then
DoIt()
Return
End If

Dim loadStatus As PartLoadStatus

For ii As Integer = 0 To args.Length - 1
Echo("Processing: " & args(ii))
workPart = CType(theSession.Parts.OpenBaseDisplay(args(ii), loadStatus), Part)
reportPartLoadStatus(loadStatus)

If workPart IsNot Nothing Then
DoIt()
workPart.Close(BasePart.CloseWholeTree.[True], BasePart.CloseModified.CloseModified, Nothing)
End If
Next
End Sub

Private Shared Sub Echo(ByVal output As String)
theSession.ListingWindow.Open()
theSession.ListingWindow.WriteLine(output)
theSession.LogFile.WriteLine(output)
End Sub

Private Shared Sub reportPartLoadStatus(ByVal load_status As PartLoadStatus)
If load_status.NumberUnloadedParts = 0 Then Return
Echo(" Load notes:")

For ii As Integer = 0 To load_status.NumberUnloadedParts - 1
Echo(" " & load_status.GetPartName(ii) & " - " + load_status.GetStatusDescription(ii))
Next
End Sub

Public Shared Function GetUnloadOption(ByVal arg As String) As Integer
Return System.Convert.ToInt32(Session.LibraryUnloadOption.Immediately)
End Function
End Class

Here' something that I come up with. The problem is that the journal lets me choose every feature and if I uncomment the:
" If selFeat.FeatureType.Equals("SYMBOLIC_THREAD") "
it ignores thread within hole feature.

Option Strict Off
Imports System
Imports System.Collections

Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Features
Imports NXOpen.Utilities

Module delete_all_features_after_selected_feature

Dim theSession As Session = Session.GetSession()
Dim theUFSession As UFSession = UFSession.GetUFSession()

Sub Main()

Dim workPart As Part = theSession.Parts.Work
theSession.EnableRedo(False)

Dim selFeat As Feature = SelectAFeature("Feature:")

' If selFeat.FeatureType.Equals("SYMBOLIC_THREAD") Then

Dim data As UFModl.SymbThreadData = New UFModl.SymbThreadData()

theUFSession.Modl.AskSymbThreadParms(selFeat.Tag, data)

Echo(" CylFace: " & data.cyl_face.ToString())
Echo(" Form: " & data.form)
Echo(" IncludeInstances: " & data.include_instances.ToString())
Echo(" InternalThread: " & data.internal_thread.ToString())
Echo(" Length: " & data.length)
Echo(" LengthFlag: " & data.length_flag.ToString())
Echo(" MajorDia: " & data.major_dia)
Echo(" Method: " & data.method)
Echo(" MinorDia: " & data.minor_dia)
Echo(" NumStarts: " & data.num_starts.ToString())
Echo(" Pitch: " & data.pitch)
Echo(" Rotation: " & data.rotation)
Echo(" StartFace: " & data.start_face.ToString())
Echo(" Tapered: " & data.tapered.ToString())
Echo(" TappedDia: " & data.tapped_dia)

' End If

If selFeat Is Nothing Then
Return
End If

End Sub

Function SelectAFeature(ByRef prompt As String) As Features.Feature

Dim mask() As Selection.SelectionType = {Selection.SelectionType.Features}
Dim cursor As Point3d = Nothing
Dim sel_obj As TaggedObject = Nothing

UI.GetUI.SelectionManager.SelectTaggedObject(prompt,
"Select a Feature", Selection.SelectionScope.WorkPart, False,
mask, sel_obj, cursor)

Return CType(sel_obj, Features.Feature)

End Function

Sub Echo(ByVal output As String)

theSession.ListingWindow.Open()
theSession.ListingWindow.WriteLine(output)
theSession.LogFile.WriteLine(output)

End Sub

Public Function GetUnloadOption(ByVal dummy As String) As Integer
Return Session.LibraryUnloadOption.Immediately
End Function

End Module

The following journal will allow the user to select a symbolic thread arc from the modeling application then it will write the thread information to the listing window (as in your code). This really only works from the modeling application, if you want to select symbolic thread curves from a drafting view, the code would need to be re-written.

'NXJournaling.com
'January 8, 2019

'Allows the user to select a symbolic thread curve from the modeling application.
'This simple example will work for a threaded hole feature; not tested on a mirrored or patterned hole feature.
'These cases would probably require additional coding to handle them correctly.

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module Module2

Dim theSession As Session = Session.GetSession()
Dim theUFSession As UFSession = UFSession.GetUFSession
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow

Sub Main()

lw.Open()

Dim myGeo As Features.Feature
Dim cancel As Boolean = False

Do Until cancel
myGeo = SelectSymbolicThread("Select symbolic thread")
If myGeo Is Nothing Then
cancel = True
Exit Sub
End If

If myGeo.FeatureType.Equals("SYMBOLIC_THREAD") Then
lw.WriteLine(myGeo.GetFeatureName())
Dim data As UFModl.SymbThreadData = New UFModl.SymbThreadData()
theUFSession.Modl.AskSymbThreadParms(myGeo.Tag, data)
' Echo(" Angle: " & data.angle)
' Echo(" Axis: " & data.axis_direction(0) & " " + data.axis_direction(1) & " " + data.axis_direction(2))

If data.callout.Length > 1 Then
lw.WriteLine(" Callout: " & data.callout)
Else
lw.WriteLine(" Callout: None (manual input)")
End If

lw.WriteLine(" CylFace: " & data.cyl_face.ToString())
lw.WriteLine(" Form: " & data.form)
lw.WriteLine(" IncludeInstances: " & data.include_instances.ToString())
lw.WriteLine(" InternalThread: " & data.internal_thread.ToString())
lw.WriteLine(" Length: " & data.length)
lw.WriteLine(" LengthFlag: " & data.length_flag.ToString())
lw.WriteLine(" MajorDia: " & data.major_dia)
lw.WriteLine(" Method: " & data.method)
lw.WriteLine(" MinorDia: " & data.minor_dia)
lw.WriteLine(" NumStarts: " & data.num_starts.ToString())
lw.WriteLine(" Pitch: " & data.pitch)
lw.WriteLine(" Rotation: " & data.rotation)
lw.WriteLine(" StartFace: " & data.start_face.ToString())
lw.WriteLine(" Tapered: " & data.tapered.ToString())
lw.WriteLine(" TappedDia: " & data.tapped_dia)
End If

lw.WriteLine("")
Loop

End Sub

Function SelectSymbolicThread(ByVal prompt As String) As Features.Feature

Dim response As Integer = 0
Dim objs() As Tag = Nothing
Dim user_data As System.IntPtr
Dim selTag As Tag = Nothing
Dim cursor(2) As Double
Dim view As Tag = Nothing

theUFSession.Ui.LockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)

Dim cursorView As Integer
theUFSession.Ui.AskCursorView(cursorView)
theUFSession.Ui.SetCursorView(0)

Try
theUFSession.Ui.SelectWithSingleDialog("Select symbolic thread arc: ", prompt,
UFConstants.UF_UI_SEL_SCOPE_ANY_IN_ASSEMBLY, AddressOf init_proc_body,
user_data, response, selTag, cursor, view)
Finally
theUFSession.Ui.UnlockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)
theUFSession.Ui.SetCursorView(cursorView)
End Try

If Not selTag.Equals(Tag.Null) Then

'the SelectWithSingleDialog method returns a tag,
'return the object from the given tag
Dim myCurve As Curve = Utilities.NXObjectManager.Get(selTag)
Dim featTag As Tag = Tag.Null
Dim myFeature As Features.Feature = Nothing

theUFSession.Modl.AskObjectFeat(myCurve.Tag, featTag)

myFeature = Utilities.NXObjectManager.Get(featTag)

theUFSession.Disp.SetHighlight(selTag, 0)
Return myFeature
Else
Return Nothing
End If

End Function

Function init_proc_body(ByVal select_ As IntPtr,
ByVal userdata As IntPtr) As Integer
'this function must have the same signature as UFUi.SelInitFnT Delegate

'setup mask to filter for arcs, lines, and silhouette curves
Dim mask_triples As UFUi.Mask() = New UFUi.Mask(1) {}
mask_triples(0).object_type = UFConstants.UF_circle_type
mask_triples(0).object_subtype = 0
mask_triples(0).solid_type = 0

mask_triples(1).object_type = UFConstants.UF_line_type
mask_triples(1).object_subtype = 0
mask_triples(1).solid_type = 0

theUFSession.Ui.SetSelMask(select_,
UFUi.SelMaskAction.SelMaskClearAndEnableSpecific,
mask_triples.Length, mask_triples)

theUFSession.Ui.SetSelProcs(select_, AddressOf HoleFeatureFilter, Nothing, userdata)

Return UFConstants.UF_UI_SEL_SUCCESS

End Function

Function HoleFeatureFilter(ByVal _object As Tag,
ByVal type As Integer(),
ByVal user_data As IntPtr,
ByVal select_ As IntPtr) As Integer
'type, user_data, and select_ are unused (in this implementation), but this function must have
'the same signature as UFUi.SelFilterFnT Delegate

Dim myCurve As Curve = Utilities.NXObjectManager.Get(_object)
Dim featTag As Tag = Tag.Null
Dim myFeature As Features.Feature = Nothing

theUFSession.Modl.AskObjectFeat(myCurve.Tag, featTag)

myFeature = Utilities.NXObjectManager.Get(featTag)
If myFeature.FeatureType = "SYMBOLIC_THREAD" Then
Return UFConstants.UF_UI_SEL_ACCEPT
Else
Return UFConstants.UF_UI_SEL_REJECT
End If

End Function

Public Function GetUnloadOption(ByVal dummy As String) As Integer

'Unloads the image when the NX session terminates
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

End Function

End Module