NX Journals
Free VB.NET scripts for Siemens NX automation. Copy or download.
List All Tools in Part
Exports a list of all tools used in the current part file to a text file. Useful for tool audits and documentation.
ListAllTools.vb
1Option Strict Off2Imports System3Imports NXOpen4Imports NXOpen.UF56Module ListAllTools7 Dim theSession As Session = Session.GetSession()8 Dim theUFSession As UFSession = UFSession.GetUFSession()9 Dim lw As ListingWindow = theSession.ListingWindow()1011 Sub Main()12 Dim workPart As Part = theSession.Parts.Work13 14 If workPart Is Nothing Then15 lw.Open()16 lw.WriteLine("No part is currently open.")17 Return18 End If19 20 lw.Open()21 lw.WriteLine("=== Tool List for: " & workPart.Name & " ===")22 lw.WriteLine("")23 24 Dim toolCount As Integer = 025 26 For Each obj As NXObject In workPart.CAMSetup.CAMGroupCollection27 If TypeOf obj Is CAM.Tool Then28 Dim tool As CAM.Tool = CType(obj, CAM.Tool)29 toolCount += 130 lw.WriteLine("Tool " & toolCount.ToString() & ": " & tool.Name)31 lw.WriteLine(" Type: " & tool.GetType().Name)32 lw.WriteLine("")33 End If34 Next35 36 lw.WriteLine("=== Total Tools: " & toolCount.ToString() & " ===")37 38 End Sub3940 Public Function GetUnloadOption(ByVal dummy As String) As Integer41 Return CInt(Session.LibraryUnloadOption.Immediately)42 End Function4344End ModuleExport Operation Names to CSV
Loops through all operations in the current setup and exports their names, tool references, and estimated cycle times to a CSV file.
ExportOperationsCSV.vb
1Option Strict Off2Imports System3Imports System.IO4Imports NXOpen5Imports NXOpen.UF6Imports NXOpen.CAM78Module ExportOperationsCSV9 Dim theSession As Session = Session.GetSession()10 Dim theUFSession As UFSession = UFSession.GetUFSession()11 Dim lw As ListingWindow = theSession.ListingWindow()1213 Sub Main()14 Dim workPart As Part = theSession.Parts.Work15 16 If workPart Is Nothing Then17 lw.Open()18 lw.WriteLine("No part is currently open.")19 Return20 End If21 22 Dim csvPath As String = Path.Combine(23 Path.GetDirectoryName(workPart.FullPath),24 workPart.Name & "_operations.csv"25 )26 27 Using writer As New StreamWriter(csvPath)28 writer.WriteLine("Operation Name,Tool Name,Method,Status")29 30 For Each ncGroup As NCGroup In workPart.CAMSetup.CAMGroupCollection31 If TypeOf ncGroup Is Operation Then32 Dim op As Operation = CType(ncGroup, Operation)33 Dim toolName As String = "N/A"34 35 Try36 If op.GetParent(CAMSetup.View.MachineTool) IsNot Nothing Then37 toolName = op.GetParent(CAMSetup.View.MachineTool).Name38 End If39 Catch ex As Exception40 toolName = "Error"41 End Try42 43 writer.WriteLine(String.Format("{0},{1},{2},{3}",44 op.Name,45 toolName,46 op.Method.ToString(),47 op.Status.ToString()48 ))49 End If50 Next51 End Using52 53 lw.Open()54 lw.WriteLine("Operations exported to: " & csvPath)55 56 End Sub5758 Public Function GetUnloadOption(ByVal dummy As String) As Integer59 Return CInt(Session.LibraryUnloadOption.Immediately)60 End Function6162End Module