Hello ,
I try to write a macro to rename all instances and references in an assembly.
I find some subjects in this forum about the same problem but I can't rename all the assembly tree.
This is the macro :
***************
Sub CATMain()
Dim Input1 , Input2 As string
Set productDocument1 = CATIA.ActiveDocument
If InStr(CATIA.ActiveDocument.Name, ".CATProduct") < 1 Then
MsgBox "Error: Active CATIA Document is not a Product", , msgboxtext
Exit Sub
End If
Input1 = InputBox("Old string ","Modify name")
If (Input1=False) Then
Exit Sub
Else
Input2= InputBox("Replace <"&Input1&"> with :","Modify name")
End If
If (Input2=False) Then
Exit Sub
Else
Call ReplaceString(productDocument1.Product)
End If
End Sub
Sub ReplaceString(actif_prod)
If actif_prod.Products.Count > 0 Then
actif_prod.ReferenceProduct.PartNumber = Replace(actif_prod.ReferenceProduct.PartNumber,Input1,Input2)
actif_prod.Name = Replace(actif_prod.Name,Input1,Input2)
For i = 1 To actif_prod.Products.Count
Call ReplaceString(actif_prod.Products.Item(i))
Next
Else
actif_prod.ReferenceProduct.PartNumber = Replace(actif_prod.ReferenceProduct.PartNumber,Input1,Input2)
actif_prod.Name = Replace(actif_prod.Name,Input1,Input2)
End If
End Sub
***********************
I have a tree like this :
1.documentname
--1.1.PartNumber (partname 1) ---> simple part
-----1.1.1 PartNumber
--1.2.PartNumber (Name) ---> product (sub-assembly)
-----1.2.1PartNumber (partName 2)
---------3.1.1 PartNumber
The macro can't rename partName 2. It can rename all others.
Can someone help me please ?
Thanks a lot.
I try to write a macro to rename all instances and references in an assembly.
I find some subjects in this forum about the same problem but I can't rename all the assembly tree.
This is the macro :
***************
Sub CATMain()
Dim Input1 , Input2 As string
Set productDocument1 = CATIA.ActiveDocument
If InStr(CATIA.ActiveDocument.Name, ".CATProduct") < 1 Then
MsgBox "Error: Active CATIA Document is not a Product", , msgboxtext
Exit Sub
End If
Input1 = InputBox("Old string ","Modify name")
If (Input1=False) Then
Exit Sub
Else
Input2= InputBox("Replace <"&Input1&"> with :","Modify name")
End If
If (Input2=False) Then
Exit Sub
Else
Call ReplaceString(productDocument1.Product)
End If
End Sub
Sub ReplaceString(actif_prod)
If actif_prod.Products.Count > 0 Then
actif_prod.ReferenceProduct.PartNumber = Replace(actif_prod.ReferenceProduct.PartNumber,Input1,Input2)
actif_prod.Name = Replace(actif_prod.Name,Input1,Input2)
For i = 1 To actif_prod.Products.Count
Call ReplaceString(actif_prod.Products.Item(i))
Next
Else
actif_prod.ReferenceProduct.PartNumber = Replace(actif_prod.ReferenceProduct.PartNumber,Input1,Input2)
actif_prod.Name = Replace(actif_prod.Name,Input1,Input2)
End If
End Sub
***********************
I have a tree like this :
1.documentname
--1.1.PartNumber (partname 1) ---> simple part
-----1.1.1 PartNumber
--1.2.PartNumber (Name) ---> product (sub-assembly)
-----1.2.1PartNumber (partName 2)
---------3.1.1 PartNumber
The macro can't rename partName 2. It can rename all others.
Can someone help me please ?
Thanks a lot.