NX Journal - Select ALL Planar Faces on a Body
NX Journal - Select ALL Planar Faces on a Body
(OP)
I found this code which allows filtering by planar faces:
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
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
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





RE: NX Journal - Select ALL Planar Faces on a Body
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
RE: NX Journal - Select ALL Planar Faces on a Body
CODE
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
RE: NX Journal - Select ALL Planar Faces on a Body
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