×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

NX Journal - Select ALL Planar Faces on a Body

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:

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

RE: NX Journal - Select ALL Planar Faces on a Body

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
 

RE: NX Journal - Select ALL Planar Faces on a Body

(OP)
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

RE: NX Journal - Select ALL Planar Faces on a Body

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources