Hiding Bodies in an Assembly with Specific Attribute Values

Hello,

I hope this message finds you well. I have a question regarding hiding bodies in an assembly based on specific attribute values.

I am looking to hide certain bodies within an assembly, including those belonging to components, based on a particular attribute value. Is there a way to achieve this using NXJournal? I want to programmatically identify bodies with a specific attribute value and then hide them.

############################################################

Imports System
Imports NXOpen
Imports NXOpen.Assemblies

Module NXJournal
Sub Main(ByVal args() As String)

Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
Dim workPart As NXOpen.Part = theSession.Parts.Work

Dim displayPart As NXOpen.Part = theSession.Parts.Display

' ----------------------------------------------
' Menu: Edit->Properties...
' ----------------------------------------------
Dim markId1 As NXOpen.Session.UndoMarkId = Nothing
markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start")

Dim c As ComponentAssembly = displayPart.ComponentAssembly

Dim topassy As Component = c.RootComponent

For Each a_child As Component In topassy.GetChildren
Dim part As NXObject = a_child.Prototype
If TypeOf part Is NXOpen.Part Then
Dim partBody As NXOpen.Part = CType(part, NXOpen.Part)
Dim bodies() As Body = partBody.Bodies.ToArray()

Dim bodyArray(bodies.Length - 1) As DisplayableObject
For i As Integer = 0 To bodies.Length - 1
bodyArray(i) = CType(bodies(i), DisplayableObject)
Next

theSession.DisplayManager.BlankObjects(bodyArray)

End If
Next

End Sub
End Module

############################################################

When I used this sample source code, bodies were not hidden in the assembly; they were only hidden when the sub-components became the displayed part.

Any guidance or examples on how to accomplish this task would be greatly appreciated.

Thank you for your assistance.

This is a situation where it is important to distinguish between a "prototype" body and an "occurrence" body (also sometimes called a component body). I'll give a brief example below; for a more detailed explanation, see the assemblies chapter in the "SNAP getting started guide" (found in the NX programming help).

Create a new part named "wheel", draw a circle and extrude it, save the file. The cylindrical body created in the file is the prototype body. Create a new part named "axle", use "add component" to add 2 wheels to the axle assembly. The wheel geometry you see in the axle assembly are occurrence bodies that are owned by the axle assembly, but are linked back to the prototype geometry. As changes are made to the prototype geometry, these changes are reflected in the occurrence geometry at the assembly level. The occurrence bodies will inherit any attributes assigned to the prototype geometry.

I think of a "component" as an invisible box that packages up a copy of the geometry from the part file for use in an assembly. It is common that a component represents a single solid body, but it can represent many bodies or other geometries. If your components each represent a single body, it will be easier to assign your attribute to the part (components inherit part attributes), check the component attribute and hide/show the component as necessary. However, if your component represents multiple bodies and you only want to hide certain ones within the component, you will need to query the occurrence bodies at the desired assembly level and hide/show them as necessary.

The good news is that the occurrence bodies are available to you in the assembly. The bad news is that they do NOT show up in the .Bodies collection. You must use one of the UF cycle functions to find the occurrence bodies. There is a journal in this thread that shows one way of doing it.
https://nxjournaling.com/comment/3487#comment-3487