Assembly Attribute Modifier

Hello all this is my first post and my second attempt at creating a Journal for NX. The first one I created is below, what I need help with follows; also I am not an experienced VB coder so please bear with me. Any help would be greatly appreciated.


Option Strict Off
Imports System
Imports NXOpen

Module NXJournal
Sub Main()

Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display

Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Delete Attributes")

workPart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_EXPORT_CLASSIFICATION")
workPart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_EXPORT_JURISDICTION")
workPart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_ICLASS_CATEGORY")
workPart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_ICLASS_TYPE")
workPart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_INITIAL_MODEL")
workPart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_IP_SENSITIVE")
workPart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_OWNED")
workPart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_REASONS_FOR_CONTROL")
workPart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_SEED_PART_USED")
workPart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_UNITS")

'===========================================================================================================

Dim message, title, defaultValue As String
Dim PartNo As Object
' Set prompt.
message = "Please input the part number in the box below." & vbcrlf & "Do NOT run this unless the drawing format has been removed from all sheets!"
' Set title.
title = "Attribute Modifier"
defaultValue = "CHANGE ME!" ' Set default value.

' Display message, title, and default value.
PartNo = InputBox(message, title, defaultValue)
' If user has clicked Cancel, set myValue to defaultValue
If PartNo = "CHANGE ME!" Then Exit Sub

Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Edit Properties")

workPart.SetAttribute("DB_CAGECODE", "XXXXX")
workPart.SetAttribute("DB_PART_NAME", PartNo)
workPart.SetAttribute("DB_PART_NO", PartNo)
workPart.SetAttribute("DB_PART_REV", "-")
workPart.SetAttribute("DB_PART_TYPE", "ITEM")

Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.DoUpdate(markId2)
End Sub
End Module

however I want to automate this stepping though an assembly and I tried to integrate into the code provided here on this site, however, I am not having those attributes deleted in the rest of the assembly. See below


'Journal to recursively walk through the assembly structure
' will run on assemblies or piece parts
' will step through all components of the displayed part
'NX 7.5, native
'NXJournaling.com February 24, 2012

Option Strict Off

Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Assemblies

Module NXJournal

Public theSession As Session = Session.GetSession()
Public ufs As UFSession = UFSession.GetUFSession()
Public lw As ListingWindow = theSession.ListingWindow

Sub Main()
Dim workPart As Part = theSession.Parts.Work
Dim dispPart As Part = theSession.Parts.Display

lw.Open
Try
Dim c As ComponentAssembly = dispPart.ComponentAssembly
'to process the work part rather than the display part,
' comment the previous line and uncomment the following line
'Dim c As ComponentAssembly = workPart.ComponentAssembly
if not IsNothing(c.RootComponent) then
'*** insert code to process 'root component' (assembly file)
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Delete Attributes")

workPart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_EXPORT_CLASSIFICATION")
workPart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_EXPORT_JURISDICTION")
workPart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_ICLASS_CATEGORY")
workPart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_ICLASS_TYPE")
workPart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_INITIAL_MODEL")
workPart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_IP_SENSITIVE")
workPart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_OWNED")
workPart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_REASONS_FOR_CONTROL")
workPart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_SEED_PART_USED")
workPart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_UNITS")

'===========================================================================================================

Dim message, title, defaultValue As String
Dim PartNo As Object
' Set prompt.
message = "Please input the part number in the box below." & vbcrlf & "Do NOT run this unless the drawing format has been removed from all sheets!"
' Set title.
title = "Attribute Modifier"
defaultValue = "CHANGE ME!" ' Set default value.

' Display message, title, and default value.
PartNo = InputBox(message, title, defaultValue)
' If user has clicked Cancel, set myValue to defaultValue
If PartNo = "CHANGE ME!" Then Exit Sub

Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Edit Properties")

workPart.SetAttribute("DB_CAGECODE", "XXXXX")
workPart.SetAttribute("DB_PART_NAME", PartNo)
workPart.SetAttribute("DB_PART_NO", PartNo)
workPart.SetAttribute("DB_PART_REV", "-")
workPart.SetAttribute("DB_PART_TYPE", "ITEM")

Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.DoUpdate(markId2)

lw.WriteLine("Assembly: " & c.RootComponent.DisplayName)
lw.WriteLine(" + Active Arrangement: " & c.ActiveArrangement.Name)
'*** end of code to process root component
ReportComponentChildren(c.RootComponent, 0)
else
'*** insert code to process piece part

Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Delete Attributes")

workPart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_EXPORT_CLASSIFICATION")
workPart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_EXPORT_JURISDICTION")
workPart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_ICLASS_CATEGORY")
workPart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_ICLASS_TYPE")
workPart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_INITIAL_MODEL")
workPart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_IP_SENSITIVE")
workPart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_OWNED")
workPart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_REASONS_FOR_CONTROL")
workPart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_SEED_PART_USED")
workPart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_UNITS")

'===========================================================================================================

Dim message, title, defaultValue As String
Dim PartNo As Object
' Set prompt.
message = "Please input the part number in the box below." & vbcrlf & "Do NOT run this unless the drawing format has been removed from all sheets!"
' Set title.
title = "Attribute Modifier"
defaultValue = "CHANGE ME!" ' Set default value.

' Display message, title, and default value.
PartNo = InputBox(message, title, defaultValue)
' If user has clicked Cancel, set myValue to defaultValue
If PartNo = "CHANGE ME!" Then Exit Sub

Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Edit Properties")

workPart.SetAttribute("DB_CAGECODE", "XXXXX")
workPart.SetAttribute("DB_PART_NAME", PartNo)
workPart.SetAttribute("DB_PART_NO", PartNo)
workPart.SetAttribute("DB_PART_REV", "-")
workPart.SetAttribute("DB_PART_TYPE", "ITEM")

Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.DoUpdate(markId2)

lw.WriteLine("Part has no components")
end if
Catch e As Exception
theSession.ListingWindow.WriteLine("Failed: " & e.ToString)
End Try
lw.Close

End Sub

'**********************************************************
Sub reportComponentChildren( ByVal comp As Component, _
ByVal indent As Integer)

For Each child As Component In comp.GetChildren()
'*** insert code to process component or subassembly

child.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_EXPORT_CLASSIFICATION")
child.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_EXPORT_JURISDICTION")
child.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_ICLASS_CATEGORY")
child.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_ICLASS_TYPE")
child.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_INITIAL_MODEL")
child.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_IP_SENSITIVE")
child.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_OWNED")
child.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_REASONS_FOR_CONTROL")
child.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_SEED_PART_USED")
child.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_UNITS")

lw.WriteLine(New String(" ", indent * 2) & child.DisplayName())
'*** end of code to process component or subassembly
if child.GetChildren.Length <> 0 then
'*** this is a subassembly, add code specific to subassemblies
child.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_EXPORT_CLASSIFICATION")
child.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_EXPORT_JURISDICTION")
child.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_ICLASS_CATEGORY")
child.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_ICLASS_TYPE")
child.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_INITIAL_MODEL")
child.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_IP_SENSITIVE")
child.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_OWNED")
child.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_REASONS_FOR_CONTROL")
child.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_SEED_PART_USED")
child.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_UNITS")

lw.WriteLine(New String(" ", indent * 2) & _
"* subassembly with " & _
child.GetChildren.Length & " components")
lw.WriteLine(New String(" ", indent * 2) & _
" + Active Arrangement: " & _
child.OwningPart.ComponentAssembly.ActiveArrangement.Name)
'*** end of code to process subassembly
else
'this component has no children (it is a leaf node)
'add any code specific to bottom level components

child.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_EXPORT_CLASSIFICATION")
child.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_EXPORT_JURISDICTION")
child.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_ICLASS_CATEGORY")
child.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_ICLASS_TYPE")
child.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_INITIAL_MODEL")
child.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_IP_SENSITIVE")
child.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_OWNED")
child.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_REASONS_FOR_CONTROL")
child.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_SEED_PART_USED")
child.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_UNITS")

end if
reportComponentChildren(child, indent + 1)
Next
End Sub
'**********************************************************
Public Function GetUnloadOption(ByVal dummy As String) As Integer
Return Session.LibraryUnloadOption.Immediately
End Function
'**********************************************************

End Module

Thank you.

What version of NX are you using? Are you using Teamcenter?

The first journal you posted works the way you want it to and now you want to extend it to process each part in an assembly?

I am currently using NX7.5 and Teamcenter is not in the picture. Yes, I want the first journal I created to extend to the whole assy.

I see that you are using an input box to prompt for a part number. Will this part number be used for each component in the assembly, or do we need to prompt for a number for each unique part, or something else?

That is only for the top level assembly part. The other parts are to keep their part number attributes.

This isn't heavily tested, but I think it is a good starting point.

'Journal to recursively walk through the assembly structure
' will run on assemblies or piece parts
' will step through all components of the displayed part
'NX 7.5, native
'NXJournaling.com February 24, 2012

Option Strict Off

Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Assemblies

Module Module1

Public theSession As Session = Session.GetSession()
Public ufs As UFSession = UFSession.GetUFSession()
Public lw As ListingWindow = theSession.ListingWindow

Sub Main()
Dim workPart As Part = theSession.Parts.Work
Dim dispPart As Part = theSession.Parts.Display

lw.Open()

Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Delete Attributes")
'delete attributes from the display part (the assembly)
DeleteAttributes(dispPart)

Dim message, title, defaultValue As String
Dim PartNo As String
' Set prompt.
message = "Please input the part number in the box below." & vbCrLf & "Do NOT run this unless the drawing format has been removed from all sheets!"
' Set title.
title = "Attribute Modifier"
defaultValue = "CHANGE ME!" ' Set default value.

' Display message, title, and default value.
PartNo = InputBox(message, title, defaultValue)
' If user has clicked Cancel, set myValue to defaultValue
If PartNo = "CHANGE ME!" Then Exit Sub

Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Edit Properties")

AddAttributes(PartNo)

Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.DoUpdate(markId2)

Dim c As ComponentAssembly = dispPart.ComponentAssembly
'to process the work part rather than the display part,
' comment the previous line and uncomment the following line
'Dim c As ComponentAssembly = workPart.ComponentAssembly
If Not IsNothing(c.RootComponent) Then
'*** insert code to process 'root component' (assembly file)

'lw.WriteLine("Assembly: " & c.RootComponent.DisplayName)
'lw.WriteLine(" + Active Arrangement: " & c.ActiveArrangement.Name)
'*** end of code to process root component
reportComponentChildren(c.RootComponent, 0)
End If

theSession.Parts.SetWork(workPart)

lw.Close()

End Sub

'**********************************************************
Sub reportComponentChildren(ByVal comp As Component, _
ByVal indent As Integer)

For Each child As Component In comp.GetChildren()
'*** insert code to process component or subassembly
MakeWorkPart(child)
DeleteAttributes(theSession.Parts.Work)

lw.WriteLine(New String(" ", indent * 2) & child.DisplayName())
'*** end of code to process component or subassembly
If child.GetChildren.Length <> 0 Then
'*** this is a subassembly, add code specific to subassemblies

lw.WriteLine(New String(" ", indent * 2) & _
"* subassembly with " & _
child.GetChildren.Length & " components")
lw.WriteLine(New String(" ", indent * 2) & _
" + Active Arrangement: " & _
child.OwningPart.ComponentAssembly.ActiveArrangement.Name)
'*** end of code to process subassembly
Else
'this component has no children (it is a leaf node)
'add any code specific to bottom level components

End If
reportComponentChildren(child, indent + 1)
Next
End Sub

Sub DeleteAttributes(ByVal thePart As part)

thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_EXPORT_CLASSIFICATION")
thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_EXPORT_JURISDICTION")
thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_ICLASS_CATEGORY")
thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_ICLASS_TYPE")
thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_INITIAL_MODEL")
thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_IP_SENSITIVE")
thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_OWNED")
thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_REASONS_FOR_CONTROL")
thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_SEED_PART_USED")
thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_UNITS")

End Sub

Sub AddAttributes(ByVal thePartNumber As String)

theSession.Parts.Display.SetAttribute("DB_CAGECODE", "XXXXX")
theSession.Parts.Display.SetAttribute("DB_PART_NAME", thePartNumber)
theSession.Parts.Display.SetAttribute("DB_PART_NO", thePartNumber)
theSession.Parts.Display.SetAttribute("DB_PART_REV", "-")
theSession.Parts.Display.SetAttribute("DB_PART_TYPE", "ITEM")

End Sub

Sub MakeWorkPart(ByVal theComp As Component)

Dim partLoadStatus1 As PartLoadStatus
theSession.Parts.SetWorkComponent(theComp, PartCollection.RefsetOption.Current, PartCollection.WorkComponentOption.Visible, partLoadStatus1)
partLoadStatus1.Dispose()

End Sub

'**********************************************************
Public Function GetUnloadOption(ByVal dummy As String) As Integer
Return Session.LibraryUnloadOption.Immediately
End Function
'**********************************************************

End Module

Thank you for that, however, I am still not receiving the desired result. Below is what I have. All of the attributes of the components are staying the same


'Journal to recursively walk through the assembly structure
' will run on assemblies or piece parts
' will step through all components of the displayed part
'NX 7.5, native
'NXJournaling.com February 24, 2012

Option Strict Off

Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Assemblies
Imports System.IO

Module Module1

Public theSession As Session = Session.GetSession()
Public ufs As UFSession = UFSession.GetUFSession()
Public lw As ListingWindow = theSession.ListingWindow

Sub Main()
Dim workPart As Part = theSession.Parts.Work
Dim dispPart As Part = theSession.Parts.Display

lw.Open()

Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Delete Attributes")
'delete attributes from the display part (the assembly)
DeleteAttributes(dispPart)

Dim fileName As String = workPart.FullPath
Dim result As String
result = Path.GetFileName(fileName)
Console.WriteLine("GetFileName('{0}') returns '{1}'", fileName, result)
Dim result0 As String
Dim result1 As String
result0 = result.Replace("D_", "")
result1 = result0.Replace("_-.prt", "")

Dim message, title, defaultValue As String
Dim PartNo As String
' Set prompt.
message = "Please VERIFY the part number below is correct!" & vbCrLf & "Do NOT run this unless the drawing format has been removed from all sheets!"
' Set title.
title = "Attribute Modifier"
defaultValue = result1 ' Set default value.

' Display message, title, and default value.
PartNo = InputBox(message, title, defaultValue)

Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Edit Properties")

AddAttributes(PartNo)

Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.DoUpdate(markId2)

Dim c As ComponentAssembly = dispPart.ComponentAssembly
'to process the work part rather than the display part,
' comment the previous line and uncomment the following line
'Dim c As ComponentAssembly = workPart.ComponentAssembly
If Not IsNothing(c.RootComponent) Then
'*** insert code to process 'root component' (assembly file)

lw.WriteLine("Assembly: " & c.RootComponent.DisplayName)
lw.WriteLine(" + Active Arrangement: " & c.ActiveArrangement.Name)
'*** end of code to process root component
reportComponentChildren(c.RootComponent, 0)
End If

theSession.Parts.SetWork(workPart)

lw.Close()

End Sub

'**********************************************************
Sub reportComponentChildren(ByVal comp As Component, _
ByVal indent As Integer)

For Each child As Component In comp.GetChildren()
'*** insert code to process component or subassembly
MakeWorkPart(child)
DeleteAttributes(theSession.Parts.Work)

lw.WriteLine(New String(" ", indent * 2) & child.DisplayName())
'*** end of code to process component or subassembly
If child.GetChildren.Length <> 0 Then
'*** this is a subassembly, add code specific to subassemblies

lw.WriteLine(New String(" ", indent * 2) & _
"* subassembly with " & _
child.GetChildren.Length & " components")
lw.WriteLine(New String(" ", indent * 2) & _
" + Active Arrangement: " & _
child.OwningPart.ComponentAssembly.ActiveArrangement.Name)
'*** end of code to process subassembly
Else
'this component has no children (it is a leaf node)
'add any code specific to bottom level components

End If
reportComponentChildren(child, indent + 1)
Next
End Sub

Sub DeleteAttributes(ByVal thePart As part)

thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_EXPORT_CLASSIFICATION")
thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_EXPORT_JURISDICTION")
thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_ICLASS_CATEGORY")
thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_ICLASS_TYPE")
thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_INITIAL_MODEL")
thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_IP_SENSITIVE")
thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_OWNED")
thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_REASONS_FOR_CONTROL")
thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_SEED_PART_USED")
thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_UNITS")
thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "XX_CAGECODE")
thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "XX_ICLASS_CONNECTED_SITE")
thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "XX_MODEL")
thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "XX_PARTNUMBER")
thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "ITEMREV_DESC")
thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "ITEMREV_DESC1")
thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "ITEMREV_NAME")
thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "MATERIAL")
thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "MOD_DATE")
thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "NX_NON_MASTER")
thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "REM-SPEC")
thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "SIMILAR_TO")
thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "STATUS")
thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_DATASET_ID")
thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_DATASET_REV")
thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_SYNCHRONISATION_DATE")
thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "UGII_VERSION")
thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "XX_PART_NO")
thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "XX PART NO")
thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "CALLOUT")
thePart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "DB_SYNCHRONIZED_PARTS_LIST")

End Sub

Sub AddAttributes(ByVal thePartNumber As String)

theSession.Parts.Display.SetAttribute("DB_CAGECODE", "XXXXX")
theSession.Parts.Display.SetAttribute("DB_PART_NAME", thePartNumber)
theSession.Parts.Display.SetAttribute("DB_PART_NO", thePartNumber)
theSession.Parts.Display.SetAttribute("DB_PART_REV", "-")
theSession.Parts.Display.SetAttribute("DB_PART_TYPE", "ITEM")

End Sub

Sub MakeWorkPart(ByVal theComp As Component)

Dim partLoadStatus1 As PartLoadStatus
theSession.Parts.SetWorkComponent(theComp, PartCollection.RefsetOption.Current, PartCollection.WorkComponentOption.Visible, partLoadStatus1)
partLoadStatus1.Dispose()

End Sub

'**********************************************************
Public Function GetUnloadOption(ByVal dummy As String) As Integer
Return Session.LibraryUnloadOption.Immediately
End Function
'**********************************************************

End Module

Do you have the proper file permissions to save the component parts? They will need to be saved after running the journal; otherwise, the changes made to the attributes won't "stick".

Also, the code that I posted assumes the assembly of interest is the currently displayed part. If this is not the case, then it won't work.

I have it working now, I needed to make a small tweak to a variable name. I do have one question though, how can I make the journal enter the part into modeling mode because I need to run this on some drawing files too. I tried to record a journal, no code was displayed for the transition.

With a few exceptions, a journal can be run from any application (modeling, drafting, sheet metal, etc) and achieve the same results. What is important is that you have the proper license for the commands used in the journal; i.e. you won't be able to create routing objects if you don't have a routing application license.

Have you tried running it from the drafting application? Did you get error messages or undesired results?

Runs great in modeling mode, however, any other mode and I get this error. I also have the proper licenses applied.

Runtime error:
NXOpen.NXException: Must Be In Modeling To Perform This Operation
at NXOpen.PartCollection.SetWorkComponent(Component workComponent, RefsetOption refsetOption, WorkComponentOption visibility, PartLoadStatus& loadStatus)
at Module1.MakeWorkPart(Component theComp) in C:\Users\XXXXXX\AppData\Local\Temp\NXJournals3760\journal.vb:line 178
at Module1.reportComponentChildren(Component comp, Int32 indent) in C:\Users\XXXXXX\AppData\Local\Temp\NXJournals3760\journal.vb:line 88
at Module1.Main() in C:\Users\XXXXXX\AppData\Local\Temp\NXJournals3760\journal.vb:line 73

...and that's one of the exceptions!

We might not need to make it the work part to change the part attributes. I've run into issues when dealing with a part that wasn't the work or displayed part, but I don't remember the details. I'll do some testing...

Ok, this seems to work. Rather than making the component the work part and passing the work part to the DeleteAttributes subroutine, pass in a reference to the component's parent part.

.
.
.
Sub reportComponentChildren(ByVal comp As Component, _
ByVal indent As Integer)

For Each child As Component In comp.GetChildren()
'*** insert code to process component or subassembly
'MakeWorkPart(child)
'DeleteAttributes(theSession.Parts.Work)

DeleteAttributes(child.Prototype.OwningPart)
.
.
.

Again, not heavily tested, but seemed to run correctly when started from the drafting application.