Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

catch the instance property and add that to the instance name

carlos.manteigas
Participant

catch the instance property and add that to the instance name

carlos.manteigas
Participant
Participant
Reply
Accepted solutions (1)
561 Views
3 Replies
Replies (3)

WCrihfield
Mentor
Mentor

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

EESignature

(Not an Autodesk Employee)

WCrihfield
Mentor
Mentor
Accepted solution

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) :thumbs_up:.

If you want and have time, I would appreciate your Vote(s) for My IDEAS :bulb: or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes

carlos.manteigas
Participant
Participant
WOW!!!!

Thank you @WCrihfield!!!
Worked like charm! :slightly_smiling_face:
0 Likes