Select all the bodies in Current displayed assembly

Hi I found this Function in Forum, Is it possible to do it in assembly level. I basically want to collect all the visible bodies from the current displayed part regardless assembly or part. I can use this following one for part. Is there anyway to do it in assembly?

PS: I want to measure all bodies volume, and create bound box around it as I earlier requested in bound box Topic
http://nxjournaling.com/content/creating-bounding-box-arround-solid
For part level I am able to create boxes for individual bodies and unite them then get the overall bounding dimension. It is working well.

Function AskAllBodies(ByVal thePart As Part) As Body()
Dim theBodies As New System.Collections.ArrayList()

Dim aBodyTag As Tag = Tag.Null
Do
ufs.Obj.CycleObjsInPart(thePart.Tag, _
UFConstants.UF_solid_type, aBodyTag)
If aBodyTag = Tag.Null Then
Exit Do
End If

Dim theType As Integer, theSubtype As Integer
ufs.Obj.AskTypeAndSubtype(aBodyTag, theType, theSubtype)
If theSubtype = UFConstants.UF_solid_body_subtype Then
theBodies.Add(theSession.GetObjectManager.GetTaggedObject(aBodyTag))
End If
Loop While True

Return DirectCast(theBodies.ToArray(GetType(Body)), Body())
End Function

This function should work on an assembly part; just pass in the assembly part as an argument to the function.

Does it select the bodies of lower level parts from the current assembly as displayed part? I want to tag all the lower level parts bodies.

Regards,

Joe

The function should return all the occurrence bodies of the specified assembly.

I have been trying for days to do what should be fairly simple. I would like to get a collection of bodies in an assembly with multiple assemblies. This example looks like my best option to get bodies from a part, but how do I iterate through the all of the components and pass them to this function?

When I try the passing the Prototype part or the OwningPart it does not find the bodies that are present. I have also tried to get the bodies using _workPart.Views.WorkView.AskVisibleObjects() and that works but I need to capture bodies that are blanked as well. Any help is appreciated, I am appending to this topic to avoid opening yet another topic, on the same issue.

Thomas

The code above will get all the occurrence bodies if you pass the assembly part to it (assuming the components are at least partially loaded).

I found that it will locate the bodies if I use the method:part.LoadThisPartFully(); but otherwise it just skips them. On really large assemblies this may be a performance hit, but we will have to live with that.

Since the internet is full of this same question, it would be nice to have an example of this with assemblies, and the code used to iterate the components. The examples I have found demonstrate how to get component information using recursion, but an example of how to put those concepts together would be very valuable. I believe as many people who have asked this exact question is proof it is confusing.

Thank you for mentioning the partial loading, that got me on the correct path.

Thomas

I ran a test on an assembly that was "partially loaded" and the bodies were found correctly. I suspect the bodies may not be found if a "lightweight" representation is used in the assembly; in this case, NX uses a different body type.

That was my problem the whole time. I was using lightweight representations. Now everything is working great. Thank you!!!

Thomas