Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

iLogic apply value to items with same part number

12 REPLIES 12
SOLVED
Reply
Message 1 of 13
Brian.Price
1471 Views, 12 Replies

iLogic apply value to items with same part number

In our BOM's we have frame generated parts that use "Part Number" to show they are the same, because they are determined by size not just the item description. 

I currently use a rule that counts all the components in an assembly and puts that into a BOM field. However it only puts the value into one of them the rest are left blank.

How can I get the value to populate the other items as well? The only way I have seen is by them having the same file name but because these all have different file names I need to do it by part number.

 

Part number example: ANGLE 3" X 3" X 3/8" X 40' A36 C.S. X 49.742 - 002-01

Here is the rule another user posted that I modified and am currently using.

Thanks,

 

Class ThisRule
	Dim rDoc As Document, oDoc As Document
	Dim oQty As Integer

	Sub Main()
		On Error Resume Next
		Dim oAssem As AssemblyDocument = ThisDoc.Document
		Dim oBOM As BOM = oAssem.ComponentDefinition.BOM

		oBOM.StructuredViewFirstLevelOnly = False
		oBOM.StructuredViewEnabled = True
		oBOM.PartsOnlyViewEnabled = True
		oBOM.SetPartNumberMergeSettings(True, )

		For Each oDoc In oAssem.AllReferencedDocuments
			oQty = 0
			If oDoc.DocumentType = 12291 Then Call ListItems(oBOM.BOMViews.Item(1).BOMRows, 0, oDoc)
			If oDoc.DocumentType = 12290 Then Call ListItems(oBOM.BOMViews.Item(3).BOMRows, 0, oDoc)
		Next
	End Sub

	Sub ListItems(Rows As BOMRowsEnumerator, indent As Integer, oDoc As Document)
		For Each oBOMRow As BOMRow In Rows
			rDoc = oBOMRow.ComponentDefinitions.Item(1).Document
			If rDoc IsNot oDoc Then
				If Not oBOMRow.ChildRows Is Nothing Then
					Call ListItems(oBOMRow.ChildRows, indent + 1, oDoc)
				End If
			Else
				oQty = oQty + oBOMRow.ItemQuantity
				iProperties.Value(rDoc.DisplayName, "Summary", "Title") = "MASTER BOM QTY " & oQty
			End If
		Next
	End Sub

End Class

 

12 REPLIES 12
Message 2 of 13
DRoam
in reply to: Brian.Price

See my added code below.

 

Class ThisRule
	Dim rDoc As Document, oDoc As Document
	Dim oQty As Integer

	Sub Main()
		On Error Resume Next
		Dim oAssem As AssemblyDocument = ThisDoc.Document
		Dim oBOM As BOM = oAssem.ComponentDefinition.BOM

		oBOM.StructuredViewFirstLevelOnly = False
		oBOM.StructuredViewEnabled = True
		oBOM.PartsOnlyViewEnabled = True
		oBOM.SetPartNumberMergeSettings(True, )

		For Each oDoc In oAssem.AllReferencedDocuments
			oQty = 0
			If oDoc.DocumentType = 12291 Then Call ListItems(oBOM.BOMViews.Item(1).BOMRows, 0, oDoc)
			If oDoc.DocumentType = 12290 Then Call ListItems(oBOM.BOMViews.Item(3).BOMRows, 0, oDoc)
			
			'=====================================================================================
			'==============================ADDED CODE=============================================
			'=====================================================================================
			' At this point in your rule, you need to iterate through all referenced docs again, and apply
			' the quantity of this doc to all docs with the same Part Number. Something like this:
			Dim oDocPN As String = iProperties.Value(oDoc.DisplayName, "Project", "Part Number")
			
			If oDocPN <> "" Then
				For Each oDoc2 As Document In oAssem.AllReferencedDocuments
					If oDoc2 Is oDoc Then Continue For ' Skip current document
					
					Dim oDoc2PN As String = iProperties.Value(oDoc2.DisplayName, "Project", "Part Number")
					
					If oDoc2PN = oDocPN Then
						' This doc has the same PN as the current document. Set its quantity to the same value.
						iProperties.Value(oDoc2.DisplayName, "Summary", "Title") = "MASTER BOM QTY " & oQty
					End If
				Next
			End If
			'=====================================================================================
			'==============================END ADDED CODE=========================================
			'=====================================================================================
		Next
	End Sub

	Sub ListItems(Rows As BOMRowsEnumerator, indent As Integer, oDoc As Document)
		For Each oBOMRow As BOMRow In Rows
			rDoc = oBOMRow.ComponentDefinitions.Item(1).Document
			If rDoc IsNot oDoc Then
				If Not oBOMRow.ChildRows Is Nothing Then
					Call ListItems(oBOMRow.ChildRows, indent + 1, oDoc)
				End If
			Else
				oQty = oQty + oBOMRow.ItemQuantity
				iProperties.Value(rDoc.DisplayName, "Summary", "Title") = "MASTER BOM QTY " & oQty
			End If
		Next
	End Sub

End Class
Message 3 of 13
Brian.Price
in reply to: DRoam

I'm afraid this rule doesn't work. It runs but never stops. 

After 30 min I restarted Inventor.

Message 4 of 13
Brian.Price
in reply to: DRoam

I made some modifications and added the clean up after the initial parameter changes.

 

Class ThisRule
	Dim rDoc As Document, oDoc As Document
	Dim oQty As Integer

	Sub Main()
		On Error Resume Next
		Dim oAssem As AssemblyDocument = ThisDoc.Document
		Dim oBOM As BOM = oAssem.ComponentDefinition.BOM

		oBOM.StructuredViewFirstLevelOnly = False
		oBOM.StructuredViewEnabled = True
		oBOM.PartsOnlyViewEnabled = True
		oBOM.SetPartNumberMergeSettings(False, )

		For Each oDoc In oAssem.AllReferencedDocuments
			oQty = 0
			If oDoc.DocumentType = 12291 Then Call ListItems(oBOM.BOMViews.Item(1).BOMRows, 0, oDoc)
			If oDoc.DocumentType = 12290 Then Call ListItems(oBOM.BOMViews.Item(3).BOMRows, 0, oDoc)
		Next
		Call Sub() CopyPaste
	End Sub

	Sub ListItems(Rows As BOMRowsEnumerator, indent As Integer, oDoc As Document)
		For Each oBOMRow As BOMRow In Rows
			rDoc = oBOMRow.ComponentDefinitions.Item(1).Document
			If rDoc IsNot oDoc Then
				If Not oBOMRow.ChildRows Is Nothing Then
					Call ListItems(oBOMRow.ChildRows, indent + 1, oDoc)
				End If
			Else
				oQty = oQty + oBOMRow.ItemQuantity
				iProperties.Value(rDoc.DisplayName, "Summary", "Title") = "MASTER BOM QTY " & oQty
			End If
		Next
	End Sub

	Sub CopyPaste
		On Error Resume Next
		Dim rDoc As Document, oDoc As Document
		Dim oQty As Integer
		Dim oAssem As AssemblyDocument = ThisDoc.Document
		Dim oBOM As BOM = oAssem.ComponentDefinition.BOM
		Dim oBOMRow As BOMRow
		For Each oDoc In oAssem.AllReferencedDocuments
			If iProperties.Value(rDoc.DisplayName, "Summary", "Title") <> " " Then 
			rDoc = oBOMRow.ComponentDefinitions.Item(1).Document
		End If 
			If iProperties.Value(rDoc.DisplayName, "Summary", "Title") = "" Then
			oDoc2 = oBOMRow.ComponentDefinitions.Item(1).Document
		End If 
		Next
		For Each oDoc In oAssem.AllReferencedDocuments
			iProperties.Value(oDoc2.DisplayName, "Summary", "Title") = iProperties.Value(rDoc.DisplayName, "Summary", "Title")
		Next
	End Sub
End Class
Message 5 of 13
Brian.Price
in reply to: Brian.Price

And that didn't work either.

Message 6 of 13

@Brian.Price  & @DRoam 

 

I had a quick look and I think we just needed to add a For/Each to look through the BOMRow references(comp. defs), when there are more than one (which is the case when the row has merged PNs) ...

 

See if this works, and be on the look out of anything I might have broke (I didn't spend much time testing, etc)

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

Class ThisRule
	Dim rDoc As Document, oDoc As Document
	Dim oQty As Integer

	Sub Main()
		On Error Resume Next
		Dim oAssem As AssemblyDocument = ThisDoc.Document
		Dim oBOM As BOM = oAssem.ComponentDefinition.BOM

		oBOM.StructuredViewFirstLevelOnly = False
		oBOM.StructuredViewEnabled = True
		oBOM.PartsOnlyViewEnabled = True
		oBOM.SetPartNumberMergeSettings(True, )

		For Each oDoc In oAssem.AllReferencedDocuments
		
			oQty = 0
			If oDoc.DocumentType = 12291 Then Call ListItems(oBOM.BOMViews.Item(1).BOMRows, 0, oDoc) 'assembly
			If oDoc.DocumentType = 12290 Then Call ListItems(oBOM.BOMViews.Item(3).BOMRows, 0, oDoc) 'part
		Next
	End Sub

	Sub ListItems(Rows As BOMRowsEnumerator, indent As Integer, oDoc As Document)
		
		For Each oBOMRow As BOMRow In Rows
			rDoc = oBOMRow.ComponentDefinitions.Item(1).Document
			Trace.WriteLine(rDoc.fullfilename, "iLogic") 'debug
				
			If rDoc IsNot oDoc Then
			
				If Not oBOMRow.ChildRows Is Nothing Then
					Call ListItems(oBOMRow.ChildRows, indent + 1, oDoc)
				End If
			Else	
				oQty = oQty + oBOMRow.ItemQuantity
				i=1
				For Each kDoc in  oBOMRow.ComponentDefinitions					
					rDoc = oBOMRow.ComponentDefinitions.Item(i).Document
					iProperties.Value(rDoc.DisplayName, "Summary", "Title") = "MASTER BOM QTY " & oQty
					i=i+1
				Next
			
			End If

		Next
	End Sub

End Class 

 

Message 7 of 13

Thanks again for the help.

It seems to be working except for the occasional anomaly. For some reason it doesn't change the property on a few of the BOM items. They aren't library parts and don't have any write protections so I am confused as to why they aren't updating.

 

They are old Frame generated parts. All of them are of the same part but different lengths. Some get updated but a few don't. Perhaps it's because these parts are several years old?

Message 8 of 13

Hi @Brian.Price ,

 

If you open one of those frame parts and save, do you get any notices about the part needing to be migrated to the current version of Inventor, etc? If so, does saving it then allow it to be updated with the ilogic rule?

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

Message 9 of 13

Well this got weird. 

The parts have been migrated to the newest edition of Inventor.

 

When I ran the rule without the error skip it gives me an error that says it can't find the file

None of the files are named the same as what is in the error. I also removed the edited part of the name file so it was the same as the error, and it still didn't find the file.

 

 

2.JPG`.JPG

Message 10 of 13

Hi @Brian.Price .

 

Okay that makes sense.... it has to do with the fact that the file is in a subassembly (frame sub assembly in this case)... so as written its looking at the top level for it and not finding it, I'll look at this in a bit and provide and update (I'm in the middle of something at the moment).

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

Message 11 of 13

Hi @Brian.Price 

 

Give this a try and report back if it doesn't work... the issue was partially what I mentioned earlier, but partially the use of "displayname", this version just uses the API call to look at the document file  to set the iproperty (rather than trying to set the iproperty via the occurrence, which is how the ilogic call does it).

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

Class ThisRule
	Dim rDoc As Document, oDoc As Document
	Dim oQty As Integer

	Sub Main()
		On Error Resume Next
		Dim oAssem As AssemblyDocument = ThisDoc.Document
		Dim oBOM As BOM = oAssem.ComponentDefinition.BOM

		oBOM.StructuredViewFirstLevelOnly = False
		oBOM.StructuredViewEnabled = True
		oBOM.PartsOnlyViewEnabled = True
		oBOM.SetPartNumberMergeSettings(True, )

		For Each oDoc In oAssem.AllReferencedDocuments
		
			oQty = 0
			If oDoc.DocumentType = 12291 Then Call ListItems(oBOM.BOMViews.Item(1).BOMRows, 0, oDoc) 'assembly
			If oDoc.DocumentType = 12290 Then Call ListItems(oBOM.BOMViews.Item(3).BOMRows, 0, oDoc) 'part
		Next
	End Sub

	Sub ListItems(Rows As BOMRowsEnumerator, indent As Integer, oDoc As Document)
		
		For Each oBOMRow As BOMRow In Rows
			rDoc = oBOMRow.ComponentDefinitions.Item(1).Document
				
			If rDoc IsNot oDoc Then
			
				If Not oBOMRow.ChildRows Is Nothing Then
					Call ListItems(oBOMRow.ChildRows, indent + 1, oDoc)
				End If
			Else	
				oQty = oQty + oBOMRow.ItemQuantity
				i=1
				For Each kDoc In  oBOMRow.ComponentDefinitions					
					rDoc = oBOMRow.ComponentDefinitions.Item(i).Document
					rDoc.PropertySets("Summary Information").Item("Title").value _
						= "MASTER BOM QTY " & oQty
					i=i+1
				Next
			
			End If

		Next
	End Sub

End Class 
Message 12 of 13

Great! That got them all. Thanks so much for the help

Message 13 of 13

Curtis,

Thanx a lot for this code.

It's exactly what I need.

I just changed the targeted iProperty and it's perfect!

Took 2 full days to work through examples in this forum to try to adjust them to my needs, but nothing worked.

The problem is, all the codes samples I found don't handle multiple c/c parts w/the same Mark#, so the total qty's were wrong for many of the parts. I'm just not smart enough in this stuff (yet) to figure it out. But then today I found your code.

Many thanx!

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator

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

Post to forums  

Autodesk Design & Make Report