Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

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

Macro to change partname and instance name

Status
Not open for further replies.

vikt

Mechanical
Joined
Mar 13, 2013
Messages
52
Location
US
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.
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top