Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

NX Journal - Select ALL Planar Faces on a Body

Status
Not open for further replies.

jmarkus

Mechanical
Jul 11, 2001
377
I found this code which allows filtering by planar faces:

Code:
Function select_a_planar_face(ByRef face As NXOpen.Tag) As Selection.Response

        Dim message As String = "Planar Face:"
        Dim title As String = "Select a PLANAR FACE"
        Dim scope As Integer = UFConstants.UF_UI_SEL_SCOPE_ANY_IN_ASSEMBLY
        Dim response As Integer
        Dim view As NXOpen.Tag
        Dim cursor(2) As Double
        Dim mask_face As UFUi.SelInitFnT = AddressOf mask_for_planar_faces

        ufs.Ui.LockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)

        Try
            ufs.Ui.SelectWithSingleDialog(message, title, scope, mask_face, Nothing, response, face, cursor, view)
        Finally
            ufs.Ui.UnlockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)
        End Try

        If response <> UFConstants.UF_UI_OBJECT_SELECTED And response <> UFConstants.UF_UI_OBJECT_SELECTED_BY_NAME Then
            Return Selection.Response.Cancel
        Else
            Return Selection.Response.Ok
        End If
    End Function

    Function mask_for_planar_faces(ByVal select_ As IntPtr, ByVal userdata As IntPtr) As Integer

        Dim num_triples As Integer = 1
        Dim mask_triples(0) As UFUi.Mask
        mask_triples(0).object_type = UFConstants.UF_solid_type
        mask_triples(0).object_subtype = UFConstants.UF_solid_face_subtype
        mask_triples(0).solid_type = UFConstants.UF_UI_SEL_FEATURE_PLANAR_FACE
		
        ufs.Ui.SetSelMask(select_, UFUi.SelMaskAction.SelMaskClearAndEnableSpecific, num_triples, mask_triples)
        Return UFConstants.UF_UI_SEL_SUCCESS

    End Function

But what I really want to do is select all planar faces on a layer, or all planar faces on a body.

How do I "trap" that selection and reuse it in other functions?

Thanks,
Jeff
 
Replies continue below

Recommended for you

Below is a simple program.

Option Strict Off
Imports NXOpen
Imports NXOpen.UF

Module PlanarFaces
Sub Main()
Dim s As Session = Session.GetSession()
Dim ufs As UFSession = UFSession.GetUFSession()
Dim workPart As Part = s.Parts.Work
Dim bodies As BodyCollection = workPart.Bodies
Dim bodyCount As Integer = bodies.ToArray.Length
Dim facetype As Integer = Nothing
Dim layerno As Integer = Nothing
Dim faces1() As Face
Dim layerno1 As Integer = 1

If bodyCount > 0 Then
For Each thisBody As Body In bodies
layerno = thisBody.Layer
If thisBody.IsSolidBody.Equals(True) And layerno = layerno1 Then
faces1 = thisBody.GetFaces()
For Each faceObject As Face In faces1
ufs.Modl.AskFaceType(faceObject.Tag, facetype)
If facetype = 22 Then
' process planar face
' ufs.Disp.SetHighlight(faceObject.Tag, 1)
End If
Next
End If
Next
Else
MsgBox("No Bodies in part")
End If
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

Note the line that sets the layer which you want to check. Also I have added a commented out line to highligth the planar faces.

Frank Swinkels
 
Thanks, I tried your code on its own and I can see how it works, but when I put the code:

Code:
faces2(k) = faceObject

To collect only the planar faces into an array, in place of the line 'process planar face, where k is an integer starting at 0, it complains that "object reference not set to an instance of object".

What am I missing?

Thanks,
Jeff
 
You need to have three lines of code to add them to an array list (the array list is easier to use).

The lines of code are

Imports System.Collections

Dim faces2 As ArrayList = New ArrayList

and in the loop add

faces2.Add(faceObject)

hope this helps

frank swinkels
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor