How to not add child assembly's component to parent assembly

Hello there,

I have an issue since using feature to create my BOM. In fact, when i go through my assembly with my recursive method to add those sweets components to my BOM. However, when i come across a sub-assembly I'm calling my  recursive method again but this create an issue. From that point i'm adding every NextFeature in my sub-Assembly even though it is not the right parent. Then when it went all the way down,  I come back to my "head assembly" last added and it will be adding AGAIN the same features to it.

I tried to getParents() from my feature or getParent() from my component to be sure to add the component to right assembly but it's either ones is always Null.

I added as attachment something similar of what i m using.

Of course i know it is logical because next step in assembly call recursively and when done we are going back where we were. but i don t know how to fix this if you guys have an idea.

Thank you.

SolidworksApi macros