Copy and change instance name. Catia (catscript).
Copy and change instance name. Catia (catscript).
(OP)
Hi,
I would like Copy value of the "Part Number" and raplace old value to new in "Instance name" field.
Search all parts and automatic replace this value. Please see the attachments.
It is macro to doing this work?
Best regards,
Lukas
I would like Copy value of the "Part Number" and raplace old value to new in "Instance name" field.
Search all parts and automatic replace this value. Please see the attachments.
It is macro to doing this work?
Best regards,
Lukas





RE: Copy and change instance name. Catia (catscript).
CODE
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
There is an index added to the instance name to prevent duplicates.
Let me know if that works for you.
Jeff
RE: Copy and change instance name. Catia (catscript).
It's work fine but I want to remove this instance value (red frame). Please see the attachment.
Best regards,
Lukas
RE: Copy and change instance name. Catia (catscript).
CODE
to
CODE
I don't know if it will work if you have more than one instance of the same part, though.
Jeff
RE: Copy and change instance name. Catia (catscript).
Solution:
ItemToRename.Name = ItemToRenamePartNumber
It's doesn't work. Yes, I have more than one instance of the same part, example: 1, 2, 3, 4 values. Please see the attachment.
Best regards,
Lukas
RE: Copy and change instance name. Catia (catscript).
As I suspected, it wont work if you have multiple instances of the same name. CATIA doesn't allow that, so you have to have an index (.1) or something to make each instance description unique.
Jeff
RE: Copy and change instance name. Catia (catscript).
the code in this thread is perfect for what i need. unfortunately, my browser will delivers it in one loooooong line with know line breaks. can anyone send it to me as a word document or notepad????
jewely
RE: Copy and change instance name. Catia (catscript).
Jeff