×
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

Macro to change partname and instance name

Macro to change partname and instance name

Macro to change partname and instance name

(OP)
Hi Friends,
I have written a code for renaming all part's name and instance inside a product.
For eg. if it is part1(part1.1), part2(part2.2)
it will change the number and instance to say vik1(vik1.1),vik2(vik2.2)
I have just started with automation, need suggestion, wht other things i can add or change to make it better.
PFB the code.



*************************

Sub CATMain()

Dim iCount As Integer
Dim sPoint As String
sPoint = "."

Dim productDocument1 As ProductDocument
Set productDocument1 = CATIA.ActiveDocument

Dim product1 As Product
Set product1 = productDocument1.Product

Dim products1 As Products
Set products1 = product1.Products

For iCount = 1 To products1.Count
products1.Item(iCount).PartNumber = "vikas" & iCount
products1.Item(iCount).Name = products1.Item(iCount).PartNumber & sPoint & iCount
Next iCount
End Sub
****************************************************************************


All suggestion and comments are welcome.
Thanks.

RE: Macro to change partname and instance name

It depends on Products structure, if its flat, this macro fulfill Your needs, but if it's more complex, and yours company rules allows same instance names inside two different products, more suitable will be Recursive approach (I and others have posted different approaches for recursive product's tree scan)

Also You should consider to rename only documents that are Parts, not Products (then You need to create other variable for instance number)

LukaszSz. Poland, Warsaw University of Technology, Faculty of Power and Aeronautical Engineering : MEchanical Engineering. BsC - 2013

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