Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.UI
Imports NXOpen.Utilities
Imports NXOpen.Assemblies
Module simplify_component_expressions
Dim s As Session = Session.GetSession()
Dim lw As ListingWindow = s.ListingWindow
Dim uniqueParts As New Collections.Generic.List(Of Part)
Dim enUS As System.Globalization.CultureInfo = New System.Globalization.CultureInfo("en-US")
Sub getUniqueParts(ByVal theComponent As Component)
Dim children As Component() = theComponent.GetChildren()
For Each child As Component In children
If child.IsSuppressed Then
Dim deleteComponentUndoMark As Session.UndoMarkId = s.SetUndoMark(Session.MarkVisibility.Visible, "Delete Component")
Try
lw.WriteLine(child.JournalIdentifier + " is suppressed and will be deleted.")
s.UpdateManager.AddToDeleteList(CType(child, NXObject))
s.UpdateManager.DoUpdate(deleteComponentUndoMark)
Catch ex As Exception
End Try
Else
If Not child.Prototype Is Nothing Then
Dim childPart As Part = CType(child.Prototype.OwningPart, Part)
If Not uniqueParts.Contains(childPart) Then
uniqueParts.Add(childPart)
End If
End If
getUniqueParts(child)
End If
Next
End Sub
Sub deleteSupressedFeatures(ByVal thePart As Part)
Dim featuresToDelete As New Collections.Generic.List(Of NXObject)
For Each theFeature As Features.Feature In thePart.Features
If theFeature.Suppressed Then
lw.WriteLine(" " + theFeature.JournalIdentifier + " is supressed and will be deleted.")
If TypeOf theFeature Is Features.FeatureGroup Then
CType(theFeature, Features.FeatureGroup).AllowDeleteMembers = True
End If
featuresToDelete.Add(theFeature)
End If
Next
Try
Dim featureDeleteUndoMarkId As Session.UndoMarkId = s.SetUndoMark(Session.MarkVisibility.Visible, "Features Deleted")
s.UpdateManager.AddToDeleteList(featuresToDelete.ToArray())
s.UpdateManager.DoUpdate(featureDeleteUndoMarkId)
Catch ex As Exception
End Try
End Sub
Sub simplifyExpressions(ByVal thePart As Part)
For Each exp As Expression In thePart.Expressions
If exp.Type.Contains("Number") Then
Dim debugString As String = " " + exp.Equation + " -> " + exp.Value.ToString(enUS)
thePart.Expressions.Edit(exp, exp.Value.ToString(enUS))
lw.WriteLine(debugString)
End If
Next
End Sub
Sub Main()
lw.Open()
Try
s.UpdateManager.ClearErrorList()
Dim rootComponent As Component = s.Parts.Display.ComponentAssembly.RootComponent
uniqueParts.Add(s.Parts.Display)
getUniqueParts(rootComponent)
For Each PartItem As Part In uniqueParts
lw.WriteLine("Working on part " + PartItem.JournalIdentifier)
deleteSupressedFeatures(PartItem)
simplifyExpressions(PartItem)
lw.WriteLine("Finished processing part ")
Next
Catch ex As Exception
lw.WriteLine(ex.Message)
End Try
End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
Return Session.LibraryUnloadOption.Immediately
End Function
End Module