Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Member Login

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips now!
  • 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!

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

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...I've learned more from your forums in 3 days than 3 months at school and on the job combined..."

Geography

Where in the world do Eng-Tips members come from?
towerback (Computer)
15 Jun 12 6:05
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
jmarkus (Mechanical)
15 Jun 12 8:22
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

towerback (Computer)
15 Jun 12 8:51
Hi Jeff,

It's work fine but I want to remove this instance value (red frame). Please see the attachment.

Best regards,
Lukas
jmarkus (Mechanical)
15 Jun 12 8:54
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
towerback (Computer)
16 Jun 12 2:27
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
jmarkus (Mechanical)
18 Jun 12 8:16
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
jewely (Automotive)
14 Dec 12 8:18
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
jmarkus (Mechanical)
14 Dec 12 8:40
Even if you copy and paste it into Word or Wordpad?

Jeff

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!

Back To Forum

Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close