- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi! ![]()
I was recommended by @CCarreiras to ask help here with an issue i published in another part of the forum:
Re: Read "instance Properties" from Inventor - Autodesk Community - Inventor
Thank you!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
What is the name of the 'instance' iProperty which is holding this serial number? Once that serial number is found, how do you want it to effect the name of the component within the active assembly? Do you want it to become the new full name of the component, or just part of its name? If just part of its name, then which part, and how do you want the new name to be formatted?
Edit: I think I found the name "Serial Number". (If that is correct.)
Wesley Crihfield
(Not an Autodesk Employee)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report