Hope this iLogic rule does what you need.
It will look for a custom parameter named "Level" in each assembly/part, add it if it doesn't exist and set its value to the BOM level of that item.
Let me know if you want this behaviour altered, you may not want the iProperty to be added to every item in your BOM, in which case can be easily fixed.
Sub Main TraverseAssembly()
' Get the active assembly.
Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim Level As Integer = 1
Dim myStr = Level.ToString("D3")
Try
'try to set iProperty value
oAsmDoc.PropertySets.Item("Inventor User Defined Properties").Item("Level").Value = myStr
Catch
'catch error when iProperty doesn't exist and create it
oAsmDoc.PropertySets.Item("Inventor User Defined Properties").Add("","Level")
'set iProperty value
oAsmDoc.PropertySets.Item("Inventor User Defined Properties").Item("Level").Value = myStr
End Try
' Call the function that does the recursion.
Call TraverseAssembly(oAsmDoc.ComponentDefinition.Occurrences, Level + 1)
End Sub
Private Sub TraverseAssembly(Occurrences As ComponentOccurrences, Level As Integer)
' Iterate through all of the occurrence in this collection. This
' represents the occurrences at the top level of an assembly.
Dim oOcc As ComponentOccurrence
For Each oOcc In Occurrences
'define custom property collection
oCustomPropertySet = oOcc.Definition.Document.PropertySets.Item("Inventor User Defined Properties")
Dim myStr = Level.ToString("D3")
Try
'try to set iProperty value
oCustomPropertySet.Item("Level").Value = myStr
Catch
'catch error when iProperty doesn't exist and create it
oCustomPropertySet.Add("","Level")
'set iProperty value
oCustomPropertySet.Item("Level").Value = myStr
End Try
' Check to see if this occurrence represents a subassembly
' and recursively call this function to traverse through it.
If oOcc.DefinitionDocumentType = kAssemblyDocumentObject Then
Call TraverseAssembly(oOcc.SubOccurrences, Level + 1)
End If
Next
End Sub