Hi @carlos.manteigas. I just wrote an iLogic rule for you that may do what you are asking, but since I still don't have the answers to the questions from my last post, I'm not sure if it is doing it the way you want it done yet. Basically, when you have that main assembly open/active, then run this rule, it should start recursively iterating through all of the components looking for an 'instance' iProperty named "Serial Number", then use its value to rename the component it was within. I put the main task into its own Sub routine, so that it would be easily transferable, if needed. I also encapsulated the whole process within a single transaction, so that it could simply click 'UNDO' once to undo it all, if needed.
Here is the iLogic rule's code:
Sub Main
oADoc = ThisAssembly.Document
oADef = oADoc.ComponentDefinition
oOccs = oADef.Occurrences
oTrans = ThisApplication.TransactionManager.StartTransaction(oADoc, "Rename Components W/ SN")
RecusivelyIterateComponents(oOccs)
oTrans.End
End Sub
Sub RecusivelyIterateComponents(oComps As ComponentOccurrences)
If IsNothing(oComps) OrElse oComps.Count = 0 Then Exit Sub
For Each oComp As ComponentOccurrence In oComps
Try
If oComp.OccurrencePropertySetsEnabled Then
Dim oInstPSet As PropertySet = oComp.OccurrencePropertySets.Item(1)
Dim oInstP As Inventor.Property = oInstPSet.Item("Serial Number")
Dim oSN As String = oInstP.Value.ToString
If oSN <> "" Then oComp.Name = oSN
End If
Catch
End Try
If oComp.SubOccurrences.Count > 0 Then
RecusivelyIterateComponents(oComp.SubOccurrences)
End If
Next
End Sub
If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS)
.
If you want and have time, I would appreciate your Vote(s) for My IDEAS :bulb: or you can Explore My CONTRIBUTIONS
Wesley Crihfield

(Not an Autodesk Employee)