Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Renaming the instances in CATIA using macro

Status
Not open for further replies.

metipradeep

Aerospace
Apr 22, 2013
14
GB
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 ?
 
Replies continue below

Recommended for you

Hi,

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

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top