Rename Part numbers into the Display names of parts in an assembly

Rename Part numbers into the Display names of parts in an assembly

aflores9JTPA
Explorer Explorer
937 Views
5 Replies
Message 1 of 6

Rename Part numbers into the Display names of parts in an assembly

aflores9JTPA
Explorer
Explorer

I'm wanting to take the Display names of parts and have those names be the part numbers for all the parts in my assembly. I've looked through other forums to try to see if I can bring some iLogic code together but I'm new to it and was unsuccessful. Any ideas on how to easily do this?

0 Likes
Accepted solutions (1)
938 Views
5 Replies
Replies (5)
Message 2 of 6

James_Willo
Alumni
Alumni

Hi, I assume you mean the name plus the instance number?        "Plate:1"
Yes I think iLogic would be the only way to do this, but you would need to run the code every time a new part was added.

 



James W
Inventor UX Designer
0 Likes
Message 3 of 6

aflores9JTPA
Explorer
Explorer

Hey, I've already got all the parts in the assembly so I just need to run the iLogic rule once. And the instance wouldn't be needed since the display file names are already set. The reason I don't need instance numbers is because I've got a lot of parts and the duplicates should have the same part number so I get a quantity in the BOM automatically. 

 

I had found this post where some code was made to take the filename and make it the part name for every part in an assembly. this is very similar to I want but I just need to alter the code where instead of taking the Filename it takes the Display name and makes that the part number.

 

https://forums.autodesk.com/t5/inventor-forum/automatic-setting-filename-to-partnumber/td-p/6819654

0 Likes
Message 4 of 6

Preston_Reed
Advocate
Advocate

There's 3 "Part Names", the file path (.ipt), occurrence (what you see in the model tree) & the part number (in iProperties).   So you want to change the part number into what the occurrence is?

 

Preston_Reed_1-1712088222437.pngPreston_Reed_2-1712088277186.png

 

 

Preston_Reed_3-1712088366948.png

 

 

0 Likes
Message 5 of 6

aflores9JTPA
Explorer
Explorer

yes id want the part number to be what the occurrence is without the occurrence value at the end. Here is an example of some of the occurrence names I've got and I marked it with what values I don't want on the part number. 

0 Likes
Message 6 of 6

Preston_Reed
Advocate
Advocate
Accepted solution

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