Remove all round faces / surfaces from the part / body

Hi, I was trying to remove all round/non planar faces from the body. There are no edge blend in the dumb solid part. But there are some round faces or fillet. Was trying to use below code. But I know it is wrong in below line:


If Not TypeOf (temp) Is NXOpen.Face Then

I couldn't find a better way to select planar faces for nottype of . Anyone have any idea please?


Imports System
Imports NXOpen
Imports System.Collections.Generic
Imports NXOpen.UF
Imports NXOpenUI

Module NXJournal
Sub Main(ByVal args() As String)

Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
Dim workPart As NXOpen.Part = theSession.Parts.Work

Dim displayPart As NXOpen.Part = theSession.Parts.Display
Dim lw As ListingWindow = theSession.ListingWindow

' ----------------------------------------------
' Menu: Edit->Delete...
' ----------------------------------------------

Dim markId4 As Session.UndoMarkId
markId4 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "remove round and nonplaner faces")

lw.Open()

Dim Nonplanerfaces As New List(Of Face)

For Each temp As NXOpen.Face In theSession.Parts.Work.Features

If Not TypeOf (temp) Is NXOpen.Face Then
'If TypeOf (temp) Is NXOpen.Features.EdgeBlend Then
Nonplanerfaces.Add(temp)
End If
Next

Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.AddToDeleteList(Nonplanerfaces.ToArray)

Dim nErrs2 As Integer
nErrs2 = theSession.UpdateManager.DoUpdate(markId4)

lw.Close()

End Sub
End Module

You need something like this:

For Each body In Snap.Globals.WorkPart.Bodies

For Each face In body.Faces

If face.ObjectSubType <> NX.ObjectTypes.SubType.FacePlane
NonPlanarFaceList.Add(face)
End If

Next face

Next body

This uses SNAP functions, but the idea would be the same using NX/Open functions.

I agree with ciao.

Also note that you cannot delete certain faces from a body by adding the faces to the delete list; try the "delete face" command instead.

I believe as I was using NxOpen, and not using snap, below code is not working


If face.ObjectSubType <> NX.ObjectTypes.SubType.FacePlane

I was trying to find a way to define a planar face as not type and .faceplane is not a subtype in Nxopen I believe. Any idea what can I use for NXOpen?

As I am using below, Nxobject.faceplane is not a valid way to find planar face


If Not TypeOf (Face) Is NXObject.faceplane Then

Regards,
MFJ

Nxjournaling, I have also recorded a journal using deleteface command, but same problem i can't find a way to define a planar face to keep or nonplanar face to delete

Regards,
MFJ

The following code illustrates how to find the face type of a given face. It will report the face type of each face in the first body found in the current work part.

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module Module1

Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession()

Dim theUI As UI = UI.GetUI()
Dim lw As ListingWindow = theSession.ListingWindow

Sub Main()

Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "NXJ")

lw.Open()

'check faces of the first body found in the work part
For Each tempFace As Face In theSession.Parts.Work.Bodies.ToArray(0).GetFaces
lw.WriteLine("face tag: " & tempFace.Tag.ToString & " face type: " & tempFace.SolidFaceType.ToString)
If tempFace.SolidFaceType <> Face.FaceType.Planar Then
lw.WriteLine(" Non planar face!")
End If
Next

lw.Close()

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

Thanks. It worked as below:


Dim Nonplanerfaces As New List(Of NXOpen.Face)
For Each tempFace In theSession.Parts.Work.Bodies.ToArray(0).GetFaces
lw.WriteLine("face tag: " & tempFace.Tag.ToString & " face type: " & tempFace.SolidFaceType.ToString)
' If Not TypeOf (Face) Is NXOpen.Face Then
If tempFace.SolidFaceType <> Face.FaceType.Planar Then
'If TypeOf (temp) Is NXOpen.Features.EdgeBlend Then
Nonplanerfaces.Add(tempFace)
lw.WriteLine(" Non planar face!")
End If
Next

Regards,
MFJ