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!

Instance Renumbering

Status
Not open for further replies.

weagan22

Aerospace
Joined
Aug 27, 2015
Messages
81
Location
US
I have been working on a macro to change the instance names in an assembly to be the "Part Number" + sequential numbering. I already have a script that returns and array of all the part numbers (pastrPartDoc) and product numbers (pastrProdDoc). The macro is working fine, except that it doesn't change the instance name of parts within another assembly even though the part is selected. The part instance is orange and it blinks but the instance name doesn't change. Any ideas why this is?

9-8-2015_6-52-23_PM_d6mg1a.jpg



Sub InstanceRenumber(pastrProdDoc() As String, pastrPartDoc () As String)
Dim q As Integer
For q = 0 To UBound(pastrProdDoc) 'loop through each unique product

Dim selection1 As Selection
Set selection1 = CATIA.ActiveDocument.Selection

Dim sProd As String
sProd = pastrProdDoc(q)

Dim p As Integer
For p = 0 To UBound(pastrPartDoc) 'loop through each unique part

Dim sPart As String
sPart = pastrPartDoc(p)

selection1.Search "CATAsmSearch.Product.PartNumber=" & sProd & ",all"

Do While selection1.Count > 1 'remove multiple instances of product from selection
selection1.Remove2 (2)
Loop

selection1.Search "CATAsmSearch.Part.PartNumber=" & sPart & ",sel"

Dim iInstance As Integer
For iInstance = 1 To selection1.Count 'loop through all sParts within assembly


Dim newName As String
newName = selection1.Item2(iInstance).Value.PartNumber & "." & iInstance

selection1.Item2(iInstance).Value.Name = newName 'not working for parts under sub products

Next 'iInstance
Next 'p
Next 'q
End Sub
 
why would you pass pastrProdDoc as a string ?

in my recursive sub i pass the product and check the product.products

Eric N.
indocti discant et ament meminisse periti
 
I found this code that seems to work. Idk if it is as robust as yours.

Sub InstanceRename()

Dim Documents As Documents
Set Documents = CATIA.Documents

Dim Item As Object
For Each Item In Documents

If Right(Item.Name, 10) = "CATProduct" Then
Dim CurrentProduct As Products
Set CurrentProduct = Item.Product.Products

Dim i As Integer
For i = 1 To CurrentProduct.Count
Dim CurrentPartNumber As String
CurrentPartNumber = CurrentProduct.Item(i).PartNumber
Dim k As Integer
k = 1

Dim j As Integer
For j = 1 To CurrentProduct.Count
Dim CurrentLine As String
CurrentLine = CurrentProduct.Item(j).PartNumber

If CurrentLine = CurrentPartNumber Then
CurrentProduct.Item(j).Name = CurrentPartNumber & "." & k
k = k + 1

End If
Next
Next
End If
Next

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top