×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Copy and change instance name. Catia (catscript).

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

RE: Copy and change instance name. Catia (catscript).

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

RE: Copy and change instance name. Catia (catscript).

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

RE: Copy and change instance name. Catia (catscript).

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

RE: Copy and change instance name. Catia (catscript).

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

RE: Copy and change instance name. Catia (catscript).

Even if you copy and paste it into Word or Wordpad?

Jeff

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources