Cancel
Showing results for 
Search instead for 
Did you mean: 

Selecting Points close to surface

Creator
Creator

Hello all,

 

NX 11

 

I will describe the problem. I have a 3D component. I also have imported a set of points using import->point file. Hence I now have a bunch of points overlaid on a 3D solid. What I would like to do is select a face from the 3D solid and extract those points that are within a specific distance. Is this possible? How would you go about it. Thank you for your help.

3 REPLIES 3
Highlighted

Re: Selecting Points close to surface

Phenom
Phenom

Below is the quickly hashed code that asks for a face, reports points within specified range and reports if the point is inside or out side the solid.  Also it names the points so they can be selected by name.

 

Imports System

Imports NXOpen
Imports NXOpen.UF

Module report_distance_between_all_points_in_range_and_face

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

    Sub Main()
        Dim lw As ListingWindow = theSession.ListingWindow
        lw.Open()

        Dim a_face As Face = Nothing
        Dim a_body As Body = Nothing
        Dim dist_required As Double = 0.5
        Dim acc As Double = 0
        Dim dist As Double = 0
        Dim cp1 As Point3d = Nothing
        Dim cp2 As Point3d = Nothing
        Dim loc() As Double
        Dim pt_status As Integer
        '1 = point is inside the body
        '2 = point is outside the body
        '3 = point is on the body
        Dim status_flag() As String = {" ", "In ", "Out", "On"}

        If select_a_face(a_face) = Selection.Response.Ok Then

            a_body = a_face.GetBody()

            For Each a_point As Point In theSession.Parts.Work.Points
                dist = theSession.Measurement.GetMinimumDistance(a_face, Nothing,
                    a_point.Coordinates, cp1, cp2, acc)

                If (dist <= dist_required) Then

                    'name points so we can select them by name interactively
                    a_point.SetName("POINT_IN_RANGE")

                    loc = convertPoint3dToDoubleArray(a_point.Coordinates)
                    If a_body.IsSheetBody Then
                        lw.WriteLine("point " & a_point.Name & ", " &
                            dist.ToString("F4"))
                    Else
                        theUFSession.Modl.AskPointContainment(loc, a_body.Tag, pt_status)
                        lw.WriteLine("point " & a_point.Name & ", " &
                            dist.ToString("F4") & ", " & status_flag(pt_status))
                    End If
                End If
            Next
        End If

    End Sub

    Public Function select_a_face(ByRef face As Face) As Selection.Response
        Dim selobj As NXObject = Nothing
        Dim cursor As Point3d
        Dim typeArray() As Selection.SelectionType =
         {Selection.SelectionType.Faces}

        Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObject("Select face",
           "Select face", Selection.SelectionScope.WorkPart, False, typeArray, selobj, cursor)
        If ((resp = Selection.Response.ObjectSelected) _
                    OrElse (resp = Selection.Response.ObjectSelectedByName)) Then
            face = CType(selobj, Face)
            Return Selection.Response.Ok
        Else
            Return Selection.Response.Cancel
        End If
    End Function

    Function convertPoint3dToDoubleArray(ByVal pt As Point3d) As Double()
        Dim da As Double() = {pt.X, pt.Y, pt.Z}
        Return da
    End Function


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

End Module
Suresh
Technisites Australia
Production: NX10.0.3 Developing: NX11.0.2.7, NX12.0.2, NX1847,
Development: C++, C# .Net, VB .Net, Python, KF

Re: Selecting Points close to surface

Creator
Creator

Hello,

 

Thank you for your response. The program outlined above worked as intended. I have one more inquiry. How would you go about writing the coordinates of the selected points to a separate text file?

Re: Selecting Points close to surface

Siemens Phenom Siemens Phenom
Siemens Phenom
How to write text files is a question about VB and .NET, really, not about NX. But, anyway, if you search this site or the GTAC site, you will find many examples that show you how to do it.
山田
yamada