Community
Inventor Forum
Welcome to Autodesk’s Inventor Forums. Share your knowledge, ask questions, and explore popular Inventor topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Counting parts in an assembly with Ilogic

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
Anonymous
3761 Views, 6 Replies

Counting parts in an assembly with Ilogic

Hello,

 

I would like to count all my parts in the main assembly and assign that amount to each part.

 

Example: Main assembly has: 10 Parts A and 5 Parts B. I would like to run a rule that "sends" that "10" to Part A.ipt and the "5" to Part B.ipt

I would like to assign it to iProperties.Status.Status.

 

Has anyone any thought about this?

 

I start to understand iLogic more and more but it is nice to get a little boost in the right direction.

 

Thanks.

6 REPLIES 6
Message 2 of 7
jletcher
in reply to: Anonymous

Here you go

 

This will not count the main assembly if you have two main assemblies and want the parts count to be correct you have to run this from a dummy assembly with two main assemblies. After running the rule you have to save and then you can delete the dummy assembly and the part count will be correct.

 

 

 

Dim openDoc As Document
openDoc = ThisDoc.Document
Dim docFile As Document
If openDoc.DocumentType = 12291 Then    
	For Each docFile In openDoc.AllReferencedDocuments
		Dim FNamePos As Long
		Dim docFName As String
		
		FNamePos = InStrRev(docFile.FullFileName, "\", -1)		
		docFName = Mid(docFile.FullFileName, FNamePos + 1, Len(docFile.FullFileName) - FNamePos)
		
		If docFile.IsModifiable = True Then
			Dim assemblyDoc As AssemblyDocument
			Dim assemblyDef As AssemblyComponentDefinition
			Dim partQty As ComponentOccurrencesEnumerator
			
			assemblyDoc = openDoc			
			assemblyDef = assemblyDoc.ComponentDefinition			
			partQty = assemblyDef.Occurrences.AllReferencedOccurrences(docFile)
			If IsNumeric(partQty.Count) = True Then
			
				If IsNumeric(iProperties.Value(docFName, "Status", "Status")) = False Then
					iProperties.Value(docFName, "Status", "Status") = 0
				End If 			
				
				If partQty.Count <>  iProperties.Value(docFName, "Status", "Status") Then				
					iProperties.Value(docFName, "Status", "Status") = partQty.Count
				End If 					 
			End If 
		End If
	Next
Else
MessageBox.Show("You must have a valid Assembly document open before using this code!", "File Type Mismatch!",MessageBoxButtons.OK,MessageBoxIcon.Exclamation)
End If 

 

Message 3 of 7
Anonymous
in reply to: jletcher

Hello James,

 

It works like a charm. Can I ask you for one more thing.

 

Could you be so kind and write remarks between the codelines so I can understand/learn what they do.

 

Thanks again.

 

Toon

Message 4 of 7
Anonymous
in reply to: Anonymous

 
Message 5 of 7
jletcher
in reply to: Anonymous

I will work on that and I guess you found out it does sub-assemblies and the parts in them...

Message 6 of 7
mtopholm
in reply to: jletcher

hi james is it possibel to modify the code. to count parts with the same partnumber, like partnumber row merge in the bom, i would like to count number of frammeber occurrences, and write it to an iproperty field

 

M. TOpholm Denmark

Message 7 of 7
TPDyno
in reply to: jletcher

Hi James,

 

I have the same problem in that I need to count the number of parts by the same partnumber not the filename, is this possible. I have multiple subassemblies that have been copied with thier ilogic rule using Design Copy but some of the parts will remain unchanged even though they have unique filenames.

 

This would be a huge help to me.......

 

Thanks in Advance

 

Travis

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report