Date: 19-DEC-2008 Subject: Sample NX Open .NET Visual Basic program : batch cleanup all parts in specified directory Note: GTAC provides programming examples for illustration only, and assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. GTAC support professionals can help explain the functionality of a particular procedure, but we will not modify these examples to provide added functionality or construct procedures to meet your specific needs. ' ' This can be built as a Console Application, or it can be executed ' without compiling by using the run_journal utility. ' ' batch_cleanup.exe D:\Your\Full\Path\To\NXPartFiles ' ' Note that while it screens for files whose names end in ' '.prt', 'PRT' and '.Prt', it does NOT check all possible ' upper- and lower-case combinations of these letters. Also, ' if the directory contains files that have a .prt extension, and that ' are NOT NX part files, an error will result. ' ' To use this code with the run_journal utility, ' ' the syntax looks like this: ' ' run_journal batch_cleanup.vb -args D:\Your\Full\Path\To\NXPartFiles ' ' Option Strict Off Imports System Imports System.Collections Imports NXOpen Imports NXOpen.UF Imports NXOpen.Utilities Module batch_cleanup_all_parts_in_specified_directory Dim s As Session = Session.GetSession() Dim ufs As UFSession = UFSession.GetUFSession() Dim lw As ListingWindow = s.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 loadStatus As NXOpen.PartLoadStatus = Nothing Dim extension As String = Right$(fileName, 4) If extension = ".prt" Or _ extension = ".PRT" Or _ extension = ".Prt" Then Dim currentPart As Part = _ s.Parts.OpenBaseDisplay(fileName, loadStatus) If loadStatus.NumberUnloadedParts < 1 Then lw.WriteLine(" Processing Part File: " & fileName) '######### your desired cleanup options here ######### ' ' add or delete cleanup options as required Dim partCleanup1 As PartCleanup partCleanup1 = s.NewPartCleanup() partCleanup1.TurnOffHighlighting = True partCleanup1.DeleteUnusedObjects = True partCleanup1.DeleteUnusedExpressions = True partCleanup1.CleanupDraftingObjects = True partCleanup1.CleanupFeatureData = True partCleanup1.FixOffplaneSketchCurves = True partCleanup1.DeleteSpreadSheetData = True partCleanup1.DeleteVisualEditorData = True partCleanup1.CleanupMatingData = True partCleanup1.DeleteUnusedFonts = True partCleanup1.CleanupCAMObjects = True partCleanup1.DeleteBrokenInterpartLinks = True partCleanup1.DoCleanup() partCleanup1.Dispose() lw.WriteLine("Saving....") Dim partSaveStatus1 As PartSaveStatus partSaveStatus1 = _ currentPart.Save(BasePart.SaveComponents.True, _ BasePart.CloseAfterSave.False) partSaveStatus1.Dispose() '####################################################### Else ' #### some parts did not open ' ' add your own code here to deal with these as desired lw.WriteLine("Some parts FAILED to open.") End If ' Close any open part files Dim partCount As Integer = ufs.Part.AskNumParts() If partCount > 0 Then s.Parts.CloseAll(BasePart.CloseModified.CloseModified, _ Nothing) lw.WriteLine(" ") End If End If Next Catch ex As Exception Console.OpenStandardOutput() Console.WriteLine(ex.ToString) Console.WriteLine() End Try End Sub End Module -- End of document -- http://uganswer.ugs.com