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 Off
2Imports System
3Imports NXOpen
4Imports NXOpen.UF
5
6Module ListAllTools
7 Dim theSession As Session = Session.GetSession()
8 Dim theUFSession As UFSession = UFSession.GetUFSession()
9 Dim lw As ListingWindow = theSession.ListingWindow()
10
11 Sub Main()
12 Dim workPart As Part = theSession.Parts.Work
13
14 If workPart Is Nothing Then
15 lw.Open()
16 lw.WriteLine("No part is currently open.")
17 Return
18 End If
19
20 lw.Open()
21 lw.WriteLine("=== Tool List for: " & workPart.Name & " ===")
22 lw.WriteLine("")
23
24 Dim toolCount As Integer = 0
25
26 For Each obj As NXObject In workPart.CAMSetup.CAMGroupCollection
27 If TypeOf obj Is CAM.Tool Then
28 Dim tool As CAM.Tool = CType(obj, CAM.Tool)
29 toolCount += 1
30 lw.WriteLine("Tool " & toolCount.ToString() & ": " & tool.Name)
31 lw.WriteLine(" Type: " & tool.GetType().Name)
32 lw.WriteLine("")
33 End If
34 Next
35
36 lw.WriteLine("=== Total Tools: " & toolCount.ToString() & " ===")
37
38 End Sub
39
40 Public Function GetUnloadOption(ByVal dummy As String) As Integer
41 Return CInt(Session.LibraryUnloadOption.Immediately)
42 End Function
43
44End Module

Export 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 Off
2Imports System
3Imports System.IO
4Imports NXOpen
5Imports NXOpen.UF
6Imports NXOpen.CAM
7
8Module ExportOperationsCSV
9 Dim theSession As Session = Session.GetSession()
10 Dim theUFSession As UFSession = UFSession.GetUFSession()
11 Dim lw As ListingWindow = theSession.ListingWindow()
12
13 Sub Main()
14 Dim workPart As Part = theSession.Parts.Work
15
16 If workPart Is Nothing Then
17 lw.Open()
18 lw.WriteLine("No part is currently open.")
19 Return
20 End If
21
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.CAMGroupCollection
31 If TypeOf ncGroup Is Operation Then
32 Dim op As Operation = CType(ncGroup, Operation)
33 Dim toolName As String = "N/A"
34
35 Try
36 If op.GetParent(CAMSetup.View.MachineTool) IsNot Nothing Then
37 toolName = op.GetParent(CAMSetup.View.MachineTool).Name
38 End If
39 Catch ex As Exception
40 toolName = "Error"
41 End Try
42
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 If
50 Next
51 End Using
52
53 lw.Open()
54 lw.WriteLine("Operations exported to: " & csvPath)
55
56 End Sub
57
58 Public Function GetUnloadOption(ByVal dummy As String) As Integer
59 Return CInt(Session.LibraryUnloadOption.Immediately)
60 End Function
61
62End Module