Sorry been out on holidays. Couple of things that were going wrong.
1. your code needs to be "if n_baffles >= 1 then" or if n_baffles > 0 then". Your description of your problem had your answer right in it.
2. when you have zero n_baffles your pattern fails because d17 = "360 / n_baffles" or "360/0" not good. This "360 deg / abs(n_baffles + ( 1 ul - sign(n_baffles) ))" will ensure that d17 always = 1 or more
3. Here is a list of all the components in your assembly...
_Weldbead:1 <-----this guy won't let you change his BOMStructure to reference
baffle:1
support:1
repad:1
support:2
repad:2
ISO 4017 - M20 x 40 - ISO:1
ISO 4032 - M20 - ISO:1
ISO 4032 - M20 - ISO:2
ISO 7089 - 20 - 140 HV(1):1
ISO 4017 - M20 x 40 - ISO:2
ISO 4032 - M20 - ISO:3
ISO 4032 - M20 - ISO:4
ISO 7089 - 20 - 140 HV(1):2
ISO 4017 - M20 x 40 - ISO:3
ISO 4032 - M20 - ISO:5
ISO 4032 - M20 - ISO:6
ISO 7089 - 20 - 140 HV(1):3
ISO 4017 - M20 x 40 - ISO:4
ISO 4032 - M20 - ISO:7
ISO 4032 - M20 - ISO:8
ISO 7089 - 20 - 140 HV(1):4
3.1 I had code to skip just that one part but then found that if all the parts in the model are gone the BOM won't update... I assume that other parts come into this in some way because there is no point in having an empty drawing... at any rate my fix was to only look if the part is a pattern member to do the hiding.
In the end my code looks like this...
'InventorVb.DocumentUpdate() 'moved to bottom
Dim doc As AssemblyDocument = ThisDoc.Document
Dim comp As ComponentOccurrence
If n_baffles >0 Then
For Each comp In doc.ComponentDefinition.Occurrences
comp.Excluded = False
comp.Visible = True
comp.BOMStructure = BOMStructureEnum.kDefaultBOMStructure
Next
Else
For Each comp In doc.ComponentDefinition.Occurrences
If comp.IsPatternElement Then
comp.Visible = False
comp.BOMStructure = BOMStructureEnum.kReferenceBOMStructure
comp.Excluded = True
End If
Next
End If
InventorVb.DocumentUpdate()
don't forget to fix d17 too.