Select All Suppressed Components and Delete

Hello all,

I'm currently searching for a way to automatically select and then delete all suppressed components in an assembly. The suppressed components can change so selecting components by name is not an option. There are suppressed components at the main assembly level and in some sub-assemblies.
Thanks!

The following code will delete suppressed components in the assembly:

Option Strict Off

Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Assemblies

Module Module1

Public theSession As Session = Session.GetSession()
Public ufs As UFSession = UFSession.GetUFSession()
Public lw As ListingWindow = theSession.ListingWindow

Sub Main()

lw.Open()

Dim componentsToDelete As New List(Of Component)

Try
Dim c As ComponentAssembly = theSession.Parts.Display.ComponentAssembly
If Not IsNothing(c.RootComponent) Then
reportComponentChildren(c.RootComponent, componentsToDelete)
Else
'*** insert code to process piece part
lw.WriteLine("Display part has no components")
End If
Catch e As Exception
theSession.ListingWindow.WriteLine("Failed: " & e.ToString)
End Try

theSession.UpdateManager.ClearErrorList()

Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Delete")

Dim nErrs1 As Integer

'add component constraints to delete list
For Each tempComp As Component In componentsToDelete
nErrs1 = theSession.UpdateManager.AddToDeleteList(tempComp.GetConstraints)
Next

nErrs1 = theSession.UpdateManager.AddToDeleteList(componentsToDelete.ToArray)

Dim nErrs3 As Integer
nErrs3 = theSession.UpdateManager.DoUpdate(markId2)

lw.Close()

End Sub

Sub reportComponentChildren(ByVal comp As Component, ByRef suppressedComps As List(Of Component))

For Each child As Component In comp.GetChildren()
If child.IsSuppressed Then
suppressedComps.Add(child)
End If
reportComponentChildren(child, suppressedComps)
Next
End Sub

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

End Module

Thank you! The journal works perfectly!

What will be the est way to do the above for a Part by deleting all the features except the features named 'Body'? Thanks.

Regards

Regards,
MFJ

Do the other features modify the existing bodies? If so, do you want to undo the changes when the features are deleted or do you want to keep the changes but get rid of the features from the part history?

If you want to get rid of the changes, simply delete the features; any change made to the body will be rolled back when the feature is deleted.

If you want to keep the change, but get rid of the feature from the part history; you can use edit -> feature -> remove parameters. This will keep the changes made to the body but remove the feature parameters.

The features named 'Body' are independent bodies and does not have relationship with the features needed to be deleted. From all the features in the part my goal was to remove everything but the dumb Solid bodies, which does not have any relationship with anything. It can be done by moving all the features to a layer other than layer 1 and remove all the features under those layers (keeping the Body / Bodies in layer 1). Please suggest the codes similar to above. Thanks.

Regards,
MFJ

Iterate through the part's feature collection; if the feature is not a body feature, add it to a list. After you have found all the non-body features, delete them.

Option Strict Off
Imports System
Imports System.Collections.Generic
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, "remove non-body features")

lw.Open()

Dim nonBodyFeatures As New List(Of Features.Feature)

For Each temp As Features.Feature In theSession.Parts.Work.Features
If Not TypeOf (temp) Is NXOpen.Features.Brep Then
nonBodyFeatures.Add(temp)
End If
Next

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

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

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 a lot! That works exactly how I was looking for.

Regards,
MFJ