' This program will walk an assembly structure. For each component it will ' delete all reference sets (except for "Empty" and "Entire Part") and all facetted bodies. ' Once all reference sets are deleted the user can save the assembly structure ' which will cause NX to create the users default reference sets, based on the ' Customer Defaults for "Model Reference Set", "Lightweight Reference Set", ' "Additional Model Reference Set", "Simplified Reference Set", etc. Option Strict On Imports System Imports System.IO Imports System.Collections Imports NXOpen Imports NXOpen.Assemblies Imports NXOpen.Drawings Imports NXOpen.UF '.Net wrapped User Function Module NXJournal ' Declare module variables. These are available to all subroutines. Dim theSession As Session = Session.GetSession() Dim ufSession As UFSession = ufSession.GetUFSession() Dim alreadyProcessed As Hashtable Dim prototype As Part Dim knt As Integer = 0 Sub Main() ' Program entry point theSession.ListingWindow.Open() theSession.ListingWindow.WriteLine("Listing child components") ' An alternative to walking is to do all files in a directory 'For Each fName As String In Directory.GetFiles(Directory.GetCurrentDirectory, "*.prt") ' Console.WriteLine(fName) ' Next Try Dim part1 As Part = theSession.Parts.Work Dim origPart As Part = part1 theSession.ListingWindow.WriteLine("Work part: " & part1.FullPath) theSession.ListingWindow.WriteLine(part1.Name) ' Initialize a hash table to store components that have been processed. ' This will prevent components from being processed twice alreadyProcessed = New Hashtable Dim c As ComponentAssembly = part1.ComponentAssembly Walk(c.RootComponent, 0) ' Change the Displayed part back to what it was at the beginning Dim partLoadStat As PartLoadStatus Dim displayPart As Part theSession.Parts.SetDisplay(origPart, False, False, partLoadStat) Catch e As Exception theSession.ListingWindow.WriteLine("Error running application: " & e.Message) End Try End Sub Sub Walk(ByVal c As Component, ByVal level As Integer) Dim children As Component() = c.GetChildren() Dim child As Component prototype = CType(c.Prototype, Part) If Not alreadyProcessed.Contains(prototype) Then ' Add this prototype to the hash table so that we don't process it again alreadyProcessed.Add(prototype, prototype) knt = knt + 1 ' Change the Displayed part Dim partLoadStat As PartLoadStatus Dim displayPart As Part theSession.Parts.SetDisplay(prototype, False, False, partLoadStat) displayPart = theSession.Parts.Display Dim returnMsg As String returnMsg = do_this() theSession.ListingWindow.WriteLine(knt & New String(" "c, (level * 4)) & c.Name & " - " & returnMsg) End If For Each child In children Walk(child, level + 1) Next End Sub Function do_this() As String Dim returnString As String Dim refset As Tag = Tag.Null Dim objectTag As Tag = Tag.Null Dim list As ArrayList = New ArrayList Dim objList As ArrayList = New ArrayList Dim undoMark As Session.UndoMarkId Do ' Delete all reference sets ufSession.Obj.CycleObjsInPart(prototype.Tag, UFConstants.UF_reference_set_type, refset) If refset <> Tag.Null Then Dim name As String ufSession.Obj.AskName(refset, name) If (name <> "Empty") And (name <> "Entire Part") Then list.Add(refset) End If End If Loop While refset <> Tag.Null For Each refset In list ufSession.Obj.DeleteObject(refset) Next returnString = "Deleted " & list.Count & " reference sets; " Return returnString End Function End Module