I have been working on a macro to change the instance names in an assembly to be the "Part Number" + sequential numbering. I already have a script that returns and array of all the part numbers (pastrPartDoc) and product numbers (pastrProdDoc). The macro is working fine, except that it doesn't change the instance name of parts within another assembly even though the part is selected. The part instance is orange and it blinks but the instance name doesn't change. Any ideas why this is?
Sub InstanceRenumber(pastrProdDoc() As String, pastrPartDoc () As String)
Dim q As Integer
For q = 0 To UBound(pastrProdDoc) 'loop through each unique product
Dim selection1 As Selection
Set selection1 = CATIA.ActiveDocument.Selection
Dim sProd As String
sProd = pastrProdDoc(q)
Dim p As Integer
For p = 0 To UBound(pastrPartDoc) 'loop through each unique part
Dim sPart As String
sPart = pastrPartDoc(p)
selection1.Search "CATAsmSearch.Product.PartNumber=" & sProd & ",all"
Do While selection1.Count > 1 'remove multiple instances of product from selection
selection1.Remove2 (2)
Loop
selection1.Search "CATAsmSearch.Part.PartNumber=" & sPart & ",sel"
Dim iInstance As Integer
For iInstance = 1 To selection1.Count 'loop through all sParts within assembly
Dim newName As String
newName = selection1.Item2(iInstance).Value.PartNumber & "." & iInstance
selection1.Item2(iInstance).Value.Name = newName 'not working for parts under sub products
Next 'iInstance
Next 'p
Next 'q
End Sub
Sub InstanceRenumber(pastrProdDoc() As String, pastrPartDoc () As String)
Dim q As Integer
For q = 0 To UBound(pastrProdDoc) 'loop through each unique product
Dim selection1 As Selection
Set selection1 = CATIA.ActiveDocument.Selection
Dim sProd As String
sProd = pastrProdDoc(q)
Dim p As Integer
For p = 0 To UBound(pastrPartDoc) 'loop through each unique part
Dim sPart As String
sPart = pastrPartDoc(p)
selection1.Search "CATAsmSearch.Product.PartNumber=" & sProd & ",all"
Do While selection1.Count > 1 'remove multiple instances of product from selection
selection1.Remove2 (2)
Loop
selection1.Search "CATAsmSearch.Part.PartNumber=" & sPart & ",sel"
Dim iInstance As Integer
For iInstance = 1 To selection1.Count 'loop through all sParts within assembly
Dim newName As String
newName = selection1.Item2(iInstance).Value.PartNumber & "." & iInstance
selection1.Item2(iInstance).Value.Name = newName 'not working for parts under sub products
Next 'iInstance
Next 'p
Next 'q
End Sub