Hi guys. Could anyone please help me with a problem... This macro does not go trough and I don't know what I'm doing wrong. I'm running it on a structure attached in post. The macro does not rename Product2/Part2 (Part2.2) to (Part2-temp.4).
Thanks
Roman
Option Explicit
Sub CATMain()
Dim productDocument1 As Document
Set productDocument1 = CATIA.ActiveDocument
If InStr(CATIA.ActiveDocument.Name, ".CATProduct") < 1 Then
MsgBox ("Active CATIA Document is not a Product. Open a Product file and run this script again.")
Exit Sub
End If
Call reorder_item(productDocument1.Product)
End Sub
Sub reorder_item(oproduct)
Dim i, j, k As Integer
Dim oproducts As Products
Set oproducts = oproduct.Products
For i = 1 To oproducts.Count
If oproducts.Item(i).Products.Count > 0 Then
Call reorder_item(oproducts.Item(i))
End If
k = 0
For j = 1 To i
If oproducts.Item(j).PartNumber = oproducts.Item(i).PartNumber Then
k = k + 1
End If
Next
If i <> oproducts.Count Then
For j = i + 1 To oproducts.Count
If oproducts.Item(j).PartNumber = oproducts.Item(i).PartNumber Then
If oproducts.Item(j).Name = oproducts.Item(i).PartNumber & "." & k Then
oproducts.Item(j).Name = oproducts.Item(i).PartNumber & "-temp." & j
MsgBox (oproducts.Item(j).Name & " " & j)
End If
End If
Next
End If
oproducts.Item(i).Name = oproducts.Item(i).PartNumber & "." & k
Next
End Sub
Thanks
Roman
Option Explicit
Sub CATMain()
Dim productDocument1 As Document
Set productDocument1 = CATIA.ActiveDocument
If InStr(CATIA.ActiveDocument.Name, ".CATProduct") < 1 Then
MsgBox ("Active CATIA Document is not a Product. Open a Product file and run this script again.")
Exit Sub
End If
Call reorder_item(productDocument1.Product)
End Sub
Sub reorder_item(oproduct)
Dim i, j, k As Integer
Dim oproducts As Products
Set oproducts = oproduct.Products
For i = 1 To oproducts.Count
If oproducts.Item(i).Products.Count > 0 Then
Call reorder_item(oproducts.Item(i))
End If
k = 0
For j = 1 To i
If oproducts.Item(j).PartNumber = oproducts.Item(i).PartNumber Then
k = k + 1
End If
Next
If i <> oproducts.Count Then
For j = i + 1 To oproducts.Count
If oproducts.Item(j).PartNumber = oproducts.Item(i).PartNumber Then
If oproducts.Item(j).Name = oproducts.Item(i).PartNumber & "." & k Then
oproducts.Item(j).Name = oproducts.Item(i).PartNumber & "-temp." & j
MsgBox (oproducts.Item(j).Name & " " & j)
End If
End If
Next
End If
oproducts.Item(i).Name = oproducts.Item(i).PartNumber & "." & k
Next
End Sub