Showing results for 
Search instead for 
Did you mean: 

Report Length Of Tube Feature Returns Circular Centerline Instead of Normal Certerline

Valued Contributor
Valued Contributor

I try the code below to create the the centerline for tubes but for some reasons, the program creates the centerline as circular ones for tubes with short lengths. For example, I want to create a single centerline for most right tubes and the result: I have a line (which is good) and a circule centerline (which is bad).





'NX 7.5
' journal to limit selection to single tube feature
' and return total length of the tube
' April 5, 2012
Option Strict Off
Imports System
Imports NXOpen
Module Tube_Length
    Dim ufs As UF.UFSession = UF.UFSession.GetUFSession()
    '”pointers” to custom filter functions
    Dim init_proc_ref As UF.UFUi.SelInitFnT = AddressOf init_proc_body
    Dim filter_proc_ref As UF.UFUi.SelFilterFnT = AddressOf tube_feature_filter
    Sub Main()
       Dim theSession As Session = Session.GetSession()
       Dim tubePrompt As String = "Select tube feature"
       Dim totalLength As Double
       Dim tubeParents() As NXObject
       Dim tubeCurves() As NXObject
       Dim myTubeFeature As Features.Feature = select_tube_feature(tubePrompt)
       If myTubeFeature IsNot Nothing Then
           tubeParents = myTubeFeature.GetSections
           For i As Integer = 0 To tubeParents.Length - 1
               For Each objSec As Section In tubeParents
                   For Each objCurve As Curve In tubeCurves
                       totalLength += objCurve.GetLength()
           'do something with the calculated total length
           MsgBox("Total Length: " & totalLength)
       End If
    End Sub
    Public Function select_tube_feature(ByRef prompt As String) As Features.Feature
       Dim response As Integer = 0
       Dim objs() As Tag = Nothing
       Dim user_data As System.IntPtr
       Dim selTube As Tag = Nothing
       Dim cursor(2) As Double
       Dim view As Tag = Nothing
           ufs.Ui.SelectWithSingleDialog("Select Tube: ", prompt, _
               UF.UFConstants.UF_UI_SEL_SCOPE_ANY_IN_ASSEMBLY, init_proc_ref, _
               user_data, response, selTube, cursor, view)
       End Try
       If Not selTube.Equals(Tag.Null) Then
           'the SelectWithSingleDialog method returns a tag,
           'return the feature from the given tag
           Dim myTube As Features.Feature
           ufs.Disp.SetHighlight(selTube, 0)
           myTube = Utilities.NXObjectManager.Get(selTube)
           Return myTube
           Return Nothing
       End If
    End Function
    Public 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 features
       Dim num_triples As Integer = 1
       Dim mask_triples As UF.UFUi.Mask() = New UF.UFUi.Mask(0) {}
       mask_triples(0).object_type = UF.UFConstants.UF_feature_type
       mask_triples(0).object_subtype = 0
       mask_triples(0).solid_type = 0
       ufs.Ui.SetSelMask(select_, _
                         UF.UFUi.SelMaskAction.SelMaskClearAndEnableSpecific, _
                         num_triples, mask_triples)
       'filter_proc_ref is the pointer to tube_feature_filter, which filters the features for tube features
       ufs.Ui.SetSelProcs(select_, filter_proc_ref, Nothing, userdata)
       Return UF.UFConstants.UF_UI_SEL_SUCCESS
    End Function
   Public Function tube_feature_filter(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, but this function must have
       'the same signature as UFUi.SelFilterFnT Delegate
       Dim myFeature As Features.Feature = Nothing
       myFeature = Utilities.NXObjectManager.Get(_object)
       If myFeature.FeatureType = "SWP104" Then
           Return UF.UFConstants.UF_UI_SEL_ACCEPT
           Return UF.UFConstants.UF_UI_SEL_REJECT
       End If
    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

 Any suggestion to resolve this problem? 


Re: Report Length Of Tube Feature Returns Circular Centerline Instead of Normal Certerline

Gears Esteemed Contributor Gears Esteemed Contributor
Gears Esteemed Contributor

The code that you have posted does not create any curve objects; it simply looks at the tube feature picked and sums up the length of the curves that drive the tube feature.


If you need to extract the centerline of an unparameterized tube, have a look at: