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

here you go, i briefly tested it, it should be working ok.  Let me know if you have any issues

Sub main
	iPropPartNumbers
End Sub

Sub iPropPartNumbers
		
	Dim oAsmCompDef As AssemblyComponentDefinition
	oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
	
''' Sub Asm	
	' Iterate through all Of the occurrences
	Dim oOccurrence As ComponentOccurrence
	For Each oOccurrence In oAsmCompDef.Occurrences.AllReferencedOccurrences(oAsmCompDef)  
		' Searching through the top level assembly file in order to locate only sub assembly files
		If oOccurrence.DefinitionDocumentType = kAssemblyDocumentObject Then 
			comp = Component.InventorComponent(oOccurrence.Name)
			Dim CompStrng As String = oOccurrence.Name
            ' Split the string using ":" as delimiter and get the first element
            Dim NewName As String = CompStrng.Split(":")(0)
					' Create iprop with PS Value
					iProperties.Value("Project", "Part Number") = NewName
			
			' Write to component iprops
			On Error Resume Next 
			iProperties.Value(oOccurrence.Name, "Project", "Part Number") = _
			iProperties.Value("Project", "Part Number")
		Else
		End If 
	Next
	
''' Piece Parts
	' Iterate through all Of the occurrences
	For Each oOccurrence In oAsmCompDef.Occurrences.AllReferencedOccurrences(oAsmCompDef)  
		' Searching through the top level assembly file in order to locate only sub assembly files
		If oOccurrence.DefinitionDocumentType = kPartDocumentObject Then 
			comp = Component.InventorComponent(oOccurrence.Name)
			Dim CompStrng As String = oOccurrence.Name
            ' Split the string using ":" as delimiter and get the first element
            Dim NewName As String = CompStrng.Split(":")(0)
					' Create iprop with PS Value
					iProperties.Value("Project", "Part Number") = NewName
			
			' Write to component iprops
			On Error Resume Next 
			iProperties.Value(oOccurrence.Name, "Project", "Part Number") = _
			iProperties.Value("Project", "Part Number")
		Else
		End If 
	Next
	
End Sub