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!

Copy and change instance name. Catia (catscript).

Status
Not open for further replies.

towerback

Computer
Apr 6, 2011
3
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
 
Replies continue below

Recommended for you

Here is a modification to the RenameInstance script from the CATIA Portable Script Center by ferdo that should do what you want:

Code:
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

There is an index added to the instance name to prevent duplicates.

Let me know if that works for you.

Jeff

 
Just change the line:

Code:
ItemToRename.Name = ItemToRenamePartNumber & "." & k

to

Code:
ItemToRename.Name = ItemToRenamePartNumber

I don't know if it will work if you have more than one instance of the same part, though.

Jeff
 
Hi Jeff,

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
 
 http://files.engineering.com/getfile.aspx?folder=d044d948-70ad-49fa-b3f9-6ac5055fec6c&file=instance_number_of_the_same_parts.jpg
Lukas,

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
 
HELP!!!!

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
 
Even if you copy and paste it into Word or Wordpad?

Jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor