Option Strict Off
Imports System
Imports System.IO
Imports NXOpen
Imports NXOpen.Assemblies
Imports NXOpen.UF
Module report_component_attributes
' Set allComponents below to True to report attributes for all the components
' and subcomponenets in the displayed part.
Dim allComponents As Boolean = True
Dim theSession As Session = Session.GetSession()
Dim ufs As UFSession = UFSession.GetUFSession()
Dim lw As ListingWindow = theSession.ListingWindow
Dim dispPart As Part = theSession.Parts.Display()
Dim wrtPath As String = Path.GetDirectoryName(dispPart.FullPath)
Sub Main
Dim modified As Boolean
modified = ufs.Part.IsModified(theSession.Parts.Display.Tag)
lw.SelectDevice(ListingWindow.DeviceType.Window, "")
' Open the listing Window to display information to user
lw.Open()
Dim fullFileName As String = System.IO.Path.Combine( _
Path.GetDirectoryName(dispPart.FullPath), _
Path.GetFileNameWithoutExtension( _
dispPart.FullPath))
lw.WriteLine(fullFileName & _
" modified = " & modified.ToString)
reportAttributes(wrtPath, dispPart)
Dim root As Component = _
theSession.Parts.Display.ComponentAssembly.RootComponent
reportComponentChildren(root, 1)
End Sub
Sub reportComponentChildren(ByVal comp As Component, _
ByVal indent As Integer)
Dim child As Component = Nothing
Dim space As String = Nothing
Dim c_part As Part = Nothing
Dim loaded As Integer
Dim modified As Boolean
For ii As Integer = 1 To indent
space = space & " "
Next
For Each child In comp.GetChildren()
loaded = ufs.Part.IsLoaded(child.DisplayName())
If loaded = 0 Then
lw.WriteLine(space & child.DisplayName() & " (unloaded)")
Else
c_part = child.Prototype()
modified = ufs.Part.IsModified(c_part.Tag)
' lw.WriteLine(space & (CType(c_part, Part)).FullPath & _
' " modified = " & modified.ToString)
Dim fullFileName As String = System.IO.Path.Combine( _
Path.GetDirectoryName(c_part.FullPath), _
Path.GetFileNameWithoutExtension( _
c_part.FullPath))
lw.WriteLine(space & fullFileName & _
" modified = " & modified.ToString)
reportAttributes(wrtPath, c_part)
End If
if allComponents Then
reportComponentChildren(child, indent + 1)
End If
Next
End Sub
Sub reportAttributes(ByRef wrtPath As String, ByVal dispPart As Part)
Dim attr_info() As NXObject.AttributeInformation
attr_info = dispPart.GetAttributeTitlesByType(NXObject.AttributeType.String)
Dim title As String = ""
Dim inx As Integer = 0
Dim count As Integer = attr_info.Length()
Dim attrVal As String
If count <= 0 Then
lw.WriteLine("No Attributes ...")
' No Attributes
Else
Dim fName As String = System.IO.Path.Combine(wrtPath, String.Concat(Path.GetFileNameWithoutExtension(dispPart.FullPath), ".txt"))
Dim f As File
Dim filewrite As IO.StreamWriter
'create file and write to it....
filewrite = f.CreateText(fName)
lw.WriteLine("Part attributes written to ... " & fName)
filewrite.WriteLine("Part attributes for " & dispPart.FullPath)
Do Until inx = count
Dim result As Integer = 0
title = attr_info(inx).Title.ToString
attrVal = dispPart.GetStringAttribute(title)
' lw.WriteLine(title & " = " & attrVal)
filewrite.WriteLine(title & " = " & attrVal)
inx += 1
Loop
filewrite.Close()
End If
End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
Return Session.LibraryUnloadOption.Immediately
End Function
End Module