NX Part Cleanup in Batch mode using NXOpen

2023-04-17T06:55:48Z
NX Open

Summary


Details

How to perform Part Cleanup in Batch mode using NXOpen?

Solution

Option Strict Off

Imports System

Imports System.Collections

Imports NXOpen

Imports NXOpen.UF

Imports NXOpen.Utilities

Module Module1

Dim theSession As Session = Session.GetSession()

Dim theUFSession As UFSession = UFSession.GetUFSession()

Dim workPart As NXOpen.Part = theSession.Parts.Work

Dim lw As ListingWindow = theSession.ListingWindow

Sub Main(ByVal args As String())

Try

Dim theDirectory As String = args(0)

lw.Open()

lw.WriteLine("Directory to process: " & theDirectory)

For Each fileName As String In My.Computer.FileSystem.GetFiles(

theDirectory)

Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing

Dim extension As String = Right$(fileName, 4)

If extension = ".prt" Or

extension = ".PRT" Or

extension = ".Prt" Then

Dim basePart1 As NXOpen.BasePart = Nothing

basePart1 = theSession.Parts.OpenBaseDisplay(fileName, partLoadStatus1)

If partLoadStatus1.NumberUnloadedParts < 1 Then

lw.WriteLine(" Processing Part File: " & fileName)

Dim partCount As Integer = theUFSession.Part.AskNumParts()

If partCount > 0 Then

Dim partCleanup1 As NXOpen.PartCleanup = Nothing

partCleanup1 = theSession.NewPartCleanup()

partCleanup1.TurnOffHighlighting = True

partCleanup1.DeleteUnusedObjects = True

partCleanup1.DeleteUnusedExpressions = True

partCleanup1.GroupsToDelete = NXOpen.PartCleanup.DeleteGroups.All

partCleanup1.CleanupDraftingObjects = True

partCleanup1.CleanupFeatureData = True

partCleanup1.FixOffplaneSketchCurves = True

partCleanup1.DeleteSpreadSheetData = True

partCleanup1.DeleteVisualEditorData = True

partCleanup1.DeleteMaterials = True

partCleanup1.DeleteDuplicateLights = True

partCleanup1.DeleteInvalidAttributes = True

partCleanup1.CleanupMatingData = True

partCleanup1.CleanupAssemblyConstraints = True

partCleanup1.DeleteUnusedFonts = True

partCleanup1.CleanupCAMObjects = True

partCleanup1.DeleteBrokenInterpartLinks = True

partCleanup1.CleanupRoutingData = True

partCleanup1.DeleteUnusedExtractReferences = True

partCleanup1.ResetComponentDisplay = NXOpen.PartCleanup.ResetComponentDisplayAction.RemoveAllChanges

partCleanup1.DoCleanup()

partCleanup1.Dispose()

Dim partSaveStatus1 As NXOpen.PartSaveStatus = Nothing

partSaveStatus1 = basePart1.Save(NXOpen.BasePart.SaveComponents.True, NXOpen.BasePart.CloseAfterSave.False)

partSaveStatus1.Dispose()

theSession.Parts.CloseAll(BasePart.CloseModified.CloseModified, Nothing)

Else

End If

End If

End If

Next

lw.WriteLine("Part Cleanup in Batch Done!!!")

Catch ex As Exception

Console.OpenStandardOutput()

Console.WriteLine(ex.ToString)

Console.WriteLine()

End Try

End Sub

End Module

KB Article ID# PL8700673

Contents

SummaryDetails

Associated Components

NX Open - All Languages