Code:
Public Class die_rename
Public CATIA As INFITF.Application
CATIA = System.Runtime.InteropServices.Marshal.GetActiveObject("CATIA.Application")
Dim oldstring As String = txttoreplace.Text
Dim newstring As String = txtnewstring.Text
Dim Aktprod As Product
Aktprod = CATIA.ActiveDocument.Product
' Die Rekursive suche wird aufgerufen um alle Parts und Produkte umzubenennen
SPSRenaming(Aktprod, oldstring, newstring)
'---------------------------------------------------------------------------------------------
' Scanning all the Product Structure, all levels
'---------------------------------------------------------------------------------------------
Sub SPSRenaming(ByVal Aktprod As Product, ByVal oldstring As String, ByVal newstring As String)
On Error Resume Next
Dim currentprod As Product
Dim i As Integer
For i = 1 To Aktprod.Products.Count
Err.Clear()
currentprod = Aktprod.Products.Item(i)
'Wenn der zähler größer 0 ist handelt es sich um ein Produkt
If currentprod.Products.Count > 0 Then
If InStr(currentprod.Name, oldstring) Then
currentprod.Name = Replace(currentprod.Name, oldstring, newstring)
End If
If InStr(currentprod.PartNumber, oldstring) Then
currentprod.PartNumber = Replace(currentprod.PartNumber, oldstring, newstring)
End If
'Wenn es sich um ein Produkt handelt wird der Scanprozess direkt
'nochmal gestartet bis ein part gefunden wird
'**************************************************************
SPSRenaming(currentprod.ReferenceProduct, oldstring, newstring)
'**************************************************************
Else ' Wenn der zähler = 0 ist handelt es sich um ein Part
If InStr(currentprod.Name, oldstring) Then
currentprod.Name = Replace(currentprod.Name, oldstring, newstring)
End If
If InStr(currentprod.PartNumber, oldstring) Then
currentprod.PartNumber = Replace(currentprod.PartNumber, oldstring, newstring)
End If
End If
Next
End Sub
End Class