×
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

Instance Renumbering

Instance Renumbering

Instance Renumbering

(OP)
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?




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

RE: Instance Renumbering

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

RE: Instance Renumbering

(OP)
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

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