Get values from BOM columns

Get values from BOM columns

markoni.vts
Participant Participant
582 Views
4 Replies
Message 1 of 5

Get values from BOM columns

markoni.vts
Participant
Participant

Hello! I there any chance to get iLogic code to find part whose name (PartNumber) contains specific words ("HS folija") in BOM of assembly and get value of that part from column "QTY" and copy that value to custom iproperty caled "QTY HS folija" in assembly? 

0 Likes
Accepted solutions (1)
583 Views
4 Replies
Replies (4)
Message 2 of 5

WCrihfield
Mentor
Mentor

Hi @markoni.vts.  Yes, that does sound possible.  Below is an example iLogic rule that may work for that task.  However, if the assembly changes after you ran this rule, those values may not be correct anymore, and they will not keep themselves accurate automatically, so you would have to run this rule again, to update their values.  Also, if it finds multiple components with that text in its Part Number value, then the value may get overwritten when the second one is found.

Sub Main
	Dim oADoc As AssemblyDocument = TryCast(ThisDoc.Document, Inventor.AssemblyDocument)
	If oADoc Is Nothing Then Return
	Dim sTextToFind As String = "HS folija"
	Dim sPropertyName As String = "QTY HS folija"
	Dim oAsmCProps As PropertySet = oADoc.PropertySets.Item(4)
	Dim oBOM As BOM = oADoc.ComponentDefinition.BOM
	If oADoc.RequiresUpdate Then oADoc.Update2(True)
	Dim oBOMView As BOMView = oBOM.BOMViews.Item(1)
	For Each oRow As BOMRow In oBOMView.BOMRows
		Dim oRowDoc As Document = oRow.ComponentDefinitions.Item(1).Document
		Dim sPN As String = oRowDoc.PropertySets.Item(3).Item(2).Value 'Part Number
		If sPN.Contains(sTextToFind) Then
			Dim iQTY As Integer = oRow.ItemQuantity
			Try
				oAsmCProps.Item(sPropertyName).Value = iQTY
			Catch
				oAsmCProps.Add(iQTY, sPropertyName)
			End Try
		End If
	Next
	If oADoc.RequiresUpdate Then oADoc.Update2(True)
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) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 5

markoni.vts
Participant
Participant

Yes, it's working and give me value '3', because I have that part (with the same Title) 3 times in assembly, but...
In my case, value in column 'QTY' is value 'Item QTY' * value 'Unit QTY' and if I have parts with the same 'Title' (Folija za hotstamping bela mat 15mm') but with different Part Number (e.g 'HS folija_15x508 bela'; 'HS folija_15x708 bela'...different dimension 508; 708...) value in column 'QTY' will be *Varies* - sum of all parts with same 'Title'.

To simplify, I think is better to ilogic must find 'Title' with specific words 'folija za hotstamping' and return value from 'QTY' to 'QTY HS folija', 'NAV Šifra' to 'NAV Šifra HS folija' and 'Title' to 'Title HS folija'.

Result will be Title HS folija = 'Folija za hotstamping bela mat 15mm'; NAV Šifra HS folija = '31021946'; QTY HS folija = '1,524m'.Snimak ekrana 2024-07-31 080952.jpgSnimak ekrana 2024-07-31 090317.jpg

 

0 Likes
Message 4 of 5

WCrihfield
Mentor
Mentor
Accepted solution

Hi @markoni.vts.  We can not simply navigate the rows, columns, or cells of what you see in the BOM user interface dialog by code, as we would an Excel spreadsheet.  Some of that information must be retrieved by digging into the actual Documents being referenced by the assembly components which are being referenced by a row in the BOM.  Then, once we get the referenced document object, we must then dig into their properties and/or BOMQuantity settings/properties.

You can review the following Inventor API object help documentations for more insight.

BOM (one per assembly)

BOMView (can be 1, 2, or 3 of these per assembly, depending on settings)

BOMRow (usually 1 per unique referenced document being represented by unsuppressed components)

BOMQuantity (defined per Document and/or per assembly component)

 

I do not know how the columns being shown in your images were were created behind the scenes, so I do not know how to access the data being represented in those columns.  I can only assume that the column simply labeled 'QTY' represents the BOMRow.TotalQuantity property value, because that would be consistent with your explanation, but I can not be 100% sure.  I also do not know what the column labeled 'NAV Šifra ' represents.  Is that a custom iProperty that already exists in every component?  Some of the terms / words in there are either foreign to me, or I simply do not understand, due to not being familiar with your products/designs, so more explanation may be needed to understand what they mean.  When a cell in certain columns becomes 'Varies', that is often due to there being multiple ModelState versions of that same referenced file being represented by different assembly components within your assembly.  In those cases, one ModelState may have a different value for things like parameters and properties, so it can not show all different values in one cell of the BOMRow.

 

I did update my code a bit, but since I am still not clear about all the details mentioned above, I kind of doubt this is what you wanted.  And to be clear, I am only supposed to be 'helping you' figure things out, so you can learn and be able to do it yourself, not necessarily write 100% of the code myself.  If it is not working exactly the way you want it to, maybe attempt to fix it yourself, then post what you have, and explain what areas you need more help with.  This would be especially helpful in situations like this, where multiple pieces of super custom information is needed to be handled in different ways, that are very unique to your BOM only.

Sub Main
	Dim oADoc As AssemblyDocument = TryCast(ThisDoc.Document, Inventor.AssemblyDocument)
	If oADoc Is Nothing Then Return
	'create list of 2-factor data pairs
	Dim oNamesAndPhrases As New Dictionary(Of String, String)
	'name of custom iProperty, then text to search for in Title iProperty value
	oNamesAndPhrases.Add("QTY HS folija", "folija za hotstamping")
	oNamesAndPhrases.Add("NAV Šifra", "NAV Šifra HS folija")
	Dim oAsmCProps As PropertySet = oADoc.PropertySets.Item(4)
	Dim oBOM As BOM = oADoc.ComponentDefinition.BOM
	If oADoc.RequiresUpdate Then oADoc.Update2(True)
	Dim oBOMView As BOMView = oBOM.BOMViews.Item(1)
	For Each oRow As BOMRow In oBOMView.BOMRows
		Dim oCD As ComponentDefinition = oRow.ComponentDefinitions.Item(1)
		Dim oRowDoc As Document = oCD.Document
		Dim sTitle As String = oRowDoc.PropertySets.Item(1).Item(1).Value 'Title
		For Each oNamePhrasePair As KeyValuePair(Of String, String) In oNamesAndPhrases
			'oNamePhrasePair.Value is phrase to search for in the Title
			If sTitle.Contains(oNamePhrasePair.Value) Then
				'oNamePhrasePair.Key is the name of the iProperty to write a value to
				Try
					oAsmCProps.Item(oNamePhrasePair.Key).Value = oRow.TotalQuantity
				Catch
					oAsmCProps.Add(oRow.TotalQuantity, oNamePhrasePair.Key)
				End Try
			End If
		Next oNamePhrasePair
	Next oRow
	If oADoc.RequiresUpdate Then oADoc.Update2(True)
End Sub

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 5

markoni.vts
Participant
Participant

Hi @WCrihfield . This code is working and returns me  'QTY' value in 'QTY HS folija'. 'NAV Šifra' is a custom iProperty that already exists in every component with title 'Folija za hotstamping bela mat 15mm'.

Of course it is not necessary for you to write me the complete code, but I'm new to this, so that's why I asked for help.

I'm not here to just take advantage of other people's knowledge, in this case yours.

Thank you.

0 Likes