Run a rule in every row include subassembly

Run a rule in every row include subassembly

WilcoLP
Participant Participant
328 Views
2 Replies
Message 1 of 3

Run a rule in every row include subassembly

WilcoLP
Participant
Participant

Hello everyone,

 

I would like my rule looks to every line include subassemble's
So that the answer becomes 16

 

Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument
Dim oBOM As BOM
oBOM = oDoc.ComponentDefinition.BOM
    ' Set the structured view to 'all levels'
oBOM.StructuredViewFirstLevelOnly = False
    ' Make sure that the structured view is enabled.
oBOM.StructuredViewEnabled = True
	
Dim oBOMView As BOMView
oBOMView = oBOM.BOMViews.Item("Structured")

i = 0

bRows = oBOMView.BOMRows
For Each bRow In bRows
	i = i + 1
Next

MessageBox.Show("There are " &  i & " rows")

 

Naamloos.pngNaamloos2.png

0 Likes
Accepted solutions (1)
329 Views
2 Replies
Replies (2)
Message 2 of 3

WCrihfield
Mentor
Mentor
Accepted solution

Hi @WilcoLP.  It sounds to me like you may need a 'recursive' sub routine to handle all possible levels of rows and child rows in the BOM.  Here is something that may work for that situation.  Give this a try and let me know how it works for you.

Sub Main
	Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument
	Dim oBOM As BOM = oDoc.ComponentDefinition.BOM
	' Set the structured view to 'all levels'
	oBOM.StructuredViewFirstLevelOnly = False
	' Make sure that the structured view is enabled.
	oBOM.StructuredViewEnabled = True
	Dim oBOMView As BOMView = oBOM.BOMViews.Item("Structured")
	Dim oRowsTotal As Integer = 0
	CountAllRows(oBOMView.BOMRows, oRowsTotal)
	MessageBox.Show("There are " & oRowsTotal & " rows")
End Sub

Sub CountAllRows(oRows As BOMRowsEnumerator, ByRef oRowsTotal As Integer)
	If oRows.Count > 0 Then
		oRowsTotal = oRowsTotal + oRows.Count
		For Each oRow As BOMRow In oRows
			If oRow.ChildRows IsNot Nothing Then
				CountAllRows(oRow.ChildRows, oRowsTotal)
			End If
		Next
	End If
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) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡 or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 3

WilcoLP
Participant
Participant
Thank you
That's a little more work than I thought but I'll get there
0 Likes