Renaming the instances in CATIA using macro
Renaming the instances in CATIA using macro
(OP)
Hi,
I have a requirement where in, I want to rename the instances automatically using MACRO, when I replace a part in Assembly.
Can anyone please provide a code or programme for it. Below is one code I got in this website itself, Does it serve my purpose?
Sub CATMain()
Dim documentlist
Dim MainProduct As Product
Dim MainDocument As ProductDocument
Set documentlist = CATIA.Documents
Set MainDocument = CATIA.ActiveDocument
Set oTopProduct = MainDocument.Product
If (InStr(MainDocument.Name, "CATProduct") <> 0) Then
Call RenameSingleLevelProduct(oTopProduct)
Else
MsgBox "Active document should be a Product"
Exit Sub
End If
End Sub
Sub RenameSingleLevelProduct(oTopProduct)
Dim ItemToRename As Product
Dim ItemToRenamePartNumber As String
Dim lNumberOfItems As Long
Dim myArray(4000) As String
Dim i, j, k As Integer
lNumberOfItems = oTopProduct.Products.Count
For i = 1 to lNumberOfItems
myArray(i) = ""
Next
For i = 1 to lNumberOfItems
Set ItemToRename = oTopProduct.Products.Item(i)
k = 0
'Rename Instance
ItemToRenamePartNumber = ItemToRename.PartNumber
myArray(i) = ItemToRenamePartNumber
For j = 1 to i
If myArray(j) = ItemToRenamePartNumber Then
k = k + 1
End If
Next
ItemToRename.Name = ItemToRenamePartNumber & "." & k
If (ItemToRename.Products.Count <> 0) Then
Call RenameSingleLevelProduct(ItemToRename.ReferenceProduct)
End If
Next
End Sub
How to incorporate the code into catia in the form of macro ?
I have a requirement where in, I want to rename the instances automatically using MACRO, when I replace a part in Assembly.
Can anyone please provide a code or programme for it. Below is one code I got in this website itself, Does it serve my purpose?
Sub CATMain()
Dim documentlist
Dim MainProduct As Product
Dim MainDocument As ProductDocument
Set documentlist = CATIA.Documents
Set MainDocument = CATIA.ActiveDocument
Set oTopProduct = MainDocument.Product
If (InStr(MainDocument.Name, "CATProduct") <> 0) Then
Call RenameSingleLevelProduct(oTopProduct)
Else
MsgBox "Active document should be a Product"
Exit Sub
End If
End Sub
Sub RenameSingleLevelProduct(oTopProduct)
Dim ItemToRename As Product
Dim ItemToRenamePartNumber As String
Dim lNumberOfItems As Long
Dim myArray(4000) As String
Dim i, j, k As Integer
lNumberOfItems = oTopProduct.Products.Count
For i = 1 to lNumberOfItems
myArray(i) = ""
Next
For i = 1 to lNumberOfItems
Set ItemToRename = oTopProduct.Products.Item(i)
k = 0
'Rename Instance
ItemToRenamePartNumber = ItemToRename.PartNumber
myArray(i) = ItemToRenamePartNumber
For j = 1 to i
If myArray(j) = ItemToRenamePartNumber Then
k = k + 1
End If
Next
ItemToRename.Name = ItemToRenamePartNumber & "." & k
If (ItemToRename.Products.Count <> 0) Then
Call RenameSingleLevelProduct(ItemToRename.ReferenceProduct)
End If
Next
End Sub
How to incorporate the code into catia in the form of macro ?





RE: Renaming the instances in CATIA using macro
First you should look at the thread where you copied this code and see what is written there, is a code for catvba or for CATScript, there are limitations or not. If you will point us with a link to that thread we could help more, no one will give an answer loosing time to try different solutions for you.
We can help but you need to give us as much details you can.
Regards
Fernando
https://picasaweb.google.com/102257836106335725208
https://picasaweb.google.com/103462806772634246699...