cancel
Showing results for 
Search instead for 
Did you mean: 

Bodies in assembly

Creator
Creator

Hello,

 

I'm trying to create a list of all the bodies I have in an assembly (because some of these solid bodies have attributes), but don't know how to achieve this.

I worked like this: workpart - rootcomponent - childcomponents - owningpart - bodies
I thought id would give me a bodycollection, but it always returns "nothing" for the collection.

It has to be in VB.NET (or C# which I then will try to translate to VB.NET)
Does anybody know a solution to get all the bodies from an assembly.

 

Thanks in advance.

Laurens

6 REPLIES

Re: Bodies in assembly

Siemens Phenom Siemens Phenom
Siemens Phenom

The BodyCollection will only provide bodies that actually live in the part from which you ask for it.

 

To find all of the bodies in the assembly, from the top leve, cycle for bodies.

 

For each body you find, ask whether it is an occurrence.

 

If it is an occurrence, then ask for its prototype.  That will represent the original body, in whatever part it was created.

 

I'll check to see if we have any relevant examples that might help.

Re: Bodies in assembly

Siemens Phenom Siemens Phenom
Siemens Phenom

This should be available on the Solution Center sometime tomorrow morning:


Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.NXObject
Imports NXOpen.UF
Imports NXOpen.Utilities

Module report_object_attributes_of_bodies_in_assembly

    Dim theSession As Session = Session.GetSession()
    Dim theUFSession As UFSession = UFSession.GetUFSession()

    Sub Main()

        Dim dispPart As Part = theSession.Parts.Display
        Dim nextBody As NXOpen.Tag = NXOpen.Tag.Null
        Dim bodyToQuery As Body = Nothing

        Do
            Dim t As Integer, st As Integer
            Dim isOcc As Boolean = False

            theUFSession.Obj.CycleTypedObjsInPart(dispPart.Tag, UFConstants.UF_solid_type, nextBody)

            If nextBody.Equals(NXOpen.Tag.Null) Then
                Exit Do
            End If

            theUFSession.Obj.AskTypeAndSubtype(nextBody, t, st)
            If st <> UFConstants.UF_solid_body_subtype Then
                Continue Do
            End If

            isOcc = theUFSession.Assem.IsOccurrence(nextBody)

            If isOcc.Equals(True) Then
                bodyToQuery = CType(NXObjectManager.Get(theUFSession.Assem.AskPrototypeOfOcc(nextBody)), Body)
            Else
                bodyToQuery = CType(NXObjectManager.Get(nextBody), Body)
            End If

            report_body_attrs(bodyToQuery)

        Loop Until nextBody.Equals(NXOpen.Tag.Null)

    End Sub

    Sub report_body_attrs(ByVal theBody As Body)

        Echo("Body lives in " & theBody.OwningPart.Name)

        Dim bodyAttrs() As AttributeInformation = theBody.GetUserAttributes()

        For Each thisattrInfo As AttributeInformation In bodyAttrs
            Echo("  Title: " & thisattrInfo.Title)
        Next

        Echo(" ")

    End Sub

    Sub Echo(ByVal output As String)

        theSession.ListingWindow.Open()
        theSession.ListingWindow.WriteLine(output)
        theSession.LogFile.WriteLine(output)

    End Sub

    Public Function GetUnloadOption(ByVal dummy As String) As Integer
        Return Session.LibraryUnloadOption.Immediately
    End Function

End Module

Re: Bodies in assembly

Phenom
Phenom

@SteveLabout,

Echo("Body lives in " & theBody.OwningPart.Name)

I ran the code on an assembly that I have open and the .Name property returns an empty string. I changed the above line to:

Echo("Body lives in " & theBody.OwningPart.Leaf)

And it seems to work well.

Re: Bodies in assembly

Phenom
Phenom

Also of note:

Promoted bodies and deformed components are handled a bit differently in NX. They will report that they "live in" the assembly file (because they do); which may not be helpful if you are looking for the model file that the geometry originated from. There are commands in the API to query these type of bodies, but perhaps that is beyond what is needed here...

Re: Bodies in assembly

Siemens Phenom Siemens Phenom
Siemens Phenom

 

That's odd - In NX11.0.1 I get the same result whether I use Name or Leaf. 

 

But I just tested in NX10.0.3, and I see the result you described.  I will change it in the Solution Center example for people who are using the earlier versions.  Thanks!!

Re: Bodies in assembly

Phenom
Phenom

I should have mentioned that I'm currently working with NX 9.0.3.4 (MP 14).