Creating Custom iProperty to Combine two others

Creating Custom iProperty to Combine two others

dylanmartin1989
Participant Participant
472 Views
8 Replies
Message 1 of 9

Creating Custom iProperty to Combine two others

dylanmartin1989
Participant
Participant

Hello all, 

 

I'd like to create a a new custom iproperty named "Balloon" that combines the "Category" iproperty and the Item Number from the BOM. So for example, if the category for a part or assembly is listed as "B" and the current item number in the BOM is number 7, then the custom iproperty "Balloon" would read "B7". I would like for this iLogic code to run through every item in the structured BOM and run accordingly. My structured BOM is a combination of parts and assemblies. 

 

Thanks in advance!

0 Likes
Accepted solutions (2)
473 Views
8 Replies
Replies (8)
Message 2 of 9

dalton98
Collaborator
Collaborator
Accepted solution

I threw this together. Let me know if you need any help/changes.

Sub Main
Dim oAssDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oBOM As BOM = oAssDoc.ComponentDefinition.BOM
oBOM.StructuredViewEnabled = True
oBOM.StructuredViewFirstLevelOnly = False
Dim oBOMView As BOMView = oBOM.BOMViews.Item("Structured")
Call BOMRows(oBOMView.BOMRows)
End Sub

Sub BOMRows(oRows As BOMRowsEnumerator)
Dim oRow As BOMRow
For Each oRow In oRows
	Dim oDoc As Document
	oDoc = oRow.ComponentDefinitions.Item(1).Document
	Dim oCategory As String = oDoc.PropertySets.Item(2).Item("Category").Value
	Dim oItemNo As String = oRow.ItemNumber
	
	Try
	oDoc.PropertySets.Item(4).Item("Balloon").Value = oCategory & oItemNo
	Catch
	oDoc.PropertySets.Item(4).Add(oCategory & oItemNo, "Balloon")
	End Try
	
	If Not oRow.ChildRows Is Nothing
		Call BOMRows(oRow.ChildRows)
	End If
Next
End Sub
0 Likes
Message 3 of 9

dylanmartin1989
Participant
Participant

@dalton98 It doesn't seem to be working for me. Does this error code make sense to you?

 

dmartinKJAF8_0-1663705353656.pngdmartinKJAF8_1-1663705371615.png

 

0 Likes
Message 4 of 9

dalton98
Collaborator
Collaborator
Accepted solution

Line 14 gets the document for that row item. It could be throwing an error bc its a phantom component? I would need more info to make sure. Add these two lines to hopefully resolve:

For Each oRow In oRows.....
	If Not oRow.ComponentDefinitions.Count = 1 Then Continue For
	If Not oRow.ComponentDefinitions.Item(1).BOMStructure = BOMStructureEnum.kNormalBOMStructure Then Continue For
'''''''''''''''''''
'''''''
''''''''''
Next

 

0 Likes
Message 5 of 9

dylanmartin1989
Participant
Participant

That did it! Thanks man I really appreciate it

 

0 Likes
Message 6 of 9

dylanmartin1989
Participant
Participant

@dalton98 It works but the code is skipping items that have like Part Numbers. For instance, I have 10 different parts in my inventor assembly that all have different file names, but all of which contain the same manufactures part number. My BOM combines this items since they have the same part number, but I still need them to display as one "Balloon" number. Do you have a solution for this? 

0 Likes
Message 7 of 9

dalton98
Collaborator
Collaborator

Ahhh. You can loop through each part in the row. I added it to the below code:

Sub BOMRows(oRows As BOMRowsEnumerator)
Dim oRow As BOMRow
For Each oRow In oRows
	Dim oCompDef As ComponentDefinition
	For Each oCompDef In oRow.ComponentDefinitions
		If Not oCompDef.BOMStructure = kNormalBOMStructure Then Continue For
		Dim oDoc As Document
		oDoc = oCompDef.Document
		Dim oCategory As String = oRow.ComponentDefinitions.Item(1).Document.PropertySets.Item(2).Item("Category").Value
		Dim oItemNo As String = oRow.ItemNumber
	
		Try
		oDoc.PropertySets.Item(4).Item("Balloon").Value = oCategory & oItemNo
		Catch
		oDoc.PropertySets.Item(4).Add(oCategory & oItemNo, "Balloon")
		End Try
	Next
	
	If Not oRow.ChildRows Is Nothing
		Call BOMRows(oRow.ChildRows)
	End If
Next
End Sub

Also you might want to have it automatically renumber your BOM using 'oBOMView.Renumber()' in the main sub

0 Likes
Message 8 of 9

dylanmartin1989
Participant
Participant

@dalton98 That appears to have worked! Just for my education purposes, the numerical values that you have on line 18,22, and 24, do those represent the tabs for the iproperty dialog box?

0 Likes
Message 9 of 9

dalton98
Collaborator
Collaborator
0 Likes