Automated wavelink creation

I am trying to create a wave link of a solid body. The journal record creates a command similar to this one:

Dim workPart As Part = theSession.Parts.Work

Dim waveLinkBuilder1 As Features.WaveLinkBuilder
waveLinkBuilder1 = workPart.BaseFeatures.CreateWaveLinkBuilder(nullFeatures_Feature)

Dim selectObjectList1 As SelectObjectList
selectObjectList1 = extractFaceBuilder1.BodyToExtract

Dim body1 As Body = CType(component5.FindObject("PARTIAL_PROTO#.Bodies|Body10"), Body)

Dim added1 As Boolean
added1 = selectObjectList1.Add(body1)

Dim nXObject1 As NXObject
nXObject1 = waveLinkBuilder1.Commit()

This code executes fine, and creates a wave link.

I am processing a significant number of bodies and would like to change this line

Dim body1 As Body = CType(component5.FindObject("PARTIAL_PROTO#.Bodies|Body10"), Body)

to something that would allow me to change it programatically during run time. Again, I am processing a lot of bodies with this operation, so user selection isn’t an option. I’ve written a recursive algorithm that steps through an assmebly and identifies each component.

So far I have tried a lot, but I think the closest I’ve gotten is this:

Dim ppart as part = component5.Prototype
Dim body1 as Body = CType(ppart.Bodies.ToArray(0), Body)

But when I execute this code, I get this error:
Failed: NXOpen.NXException: The linked feature could not be created because the selected object is within the work part.
at NXOpen.Builder.Commit()
at NXJournal.Main(String[] args) in C:\path_to_journals\journal.vb:line 149

There must be some way to grab the bodies inside a component. I’ve also thought about continuing to use the “Find Object” routine if I could get the name “Body10” associated with the body from the prototype method I used above. i.e. FindObject("PARTIAL_PROTO#.Bodies” & body.ToString). But body.ToString isn’t “Body10”. There must be something obvious I’m missing here.

When you have a reference to a component, you can get the corresponding part object with the {component}.Prototype property. Now that you have a reference to a part object, you can iterate through the body collection with the {part}.Bodies property. The bodies returned here will be the "prototype" body objects. To find the component occurrence body, you use the {component}.FindOccurrence(prototype object) method.

Note that promoted bodies and deformed components are special cases. These bodies will be owned by the assembly rather than the part file that defines them.

That works! Thank you. I had seen this command before but apparently you can't spell "occurrence" with one 'r'. I couldn't have got it working without you. Thanks again!