Showing results for 
Search instead for 
Did you mean: 

NXOpen is returning an extra component

Valued Contributor
Valued Contributor

Hello all, I am hoping somebody might be able to provide some helpful insight on how to correct this problem I am having. I have some code that loops through the assembly processing individual bodies for volume and centers. The code is returning an extra component inside the assembly that is not supposed to be there. After getting all of the solid bodies in the assembly it essentially grabs an entire parent and it's children inside the assembly as a single component. So it is returning more volume (and components) than it should. I can confirm that this parent shouldn't be included as a single component because if I select the assembly in the viewport it tells me exactly how many solid bodies I should be picking up. The result of my code (a spreadsheet) tells me there is one extra component than what NX is telling. Plus this extra component throws off my total volume.


Here is a shortened version of the code I am using:


Imports System
Imports NXOpen
Imports NXOpen.UF

Module NXJournal
    Dim theSession As Session = Session.GetSession()
    Dim theUFSession As UFSession = UFSession.GetUFSession()
    Dim workPart As Part = theSession.Parts.Work

    Public Sub Main(ByVal args As String())
        Dim bodies As Body() = AskAllBodies(workPart)
        Echo("Found " & bodies.Length & " bodies")

        Dim myMeasure As MeasureManager = theSession.Parts.Display.MeasureManager()
        Dim massUnits(4) As Unit
        massUnits(0) = theSession.Parts.Display.UnitCollection.GetBase("Area")
        massUnits(1) = theSession.Parts.Display.UnitCollection.GetBase("Volume")
        massUnits(2) = theSession.Parts.Display.UnitCollection.GetBase("Mass")
        massUnits(3) = theSession.Parts.Display.UnitCollection.GetBase("Length")

        Dim totalVolume As Double = 0

        Dim mb As MeasureBodies

        For Each tempBody As Body In bodies

            mb = myMeasure.NewMassProperties(massUnits, 1, {tempBody})
            mb.InformationUnit = MeasureBodies.AnalysisUnit.PoundFoot

            Echo(tempBody.OwningComponent.Name & "; " & mb.Volume.ToString())
            totalVolume += mb.Volume

        Echo("total volume = " & totalVolume)
    End Sub

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

        Dim aBodyTag As Tag = Tag.Null
            theUFSession.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
            theUFSession.Obj.AskTypeAndSubtype(aBodyTag, theType, theSubtype)
            If theSubtype = UFConstants.UF_solid_body_subtype Then
            End If
        Loop While True

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

    Sub Echo(ByVal output As String)
    End Sub

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

End Module


Any suggestions on how to remedy this would be great! Thanks!


Re: NXOpen is returning an extra component

Gears Esteemed Contributor Gears Esteemed Contributor
Gears Esteemed Contributor

Why don't you use the body collection of the part instead of the old UF wrapper functions?


It would get rid of the tag conversion hassle and would be much easier to debug.

Stefan Pendl, Systemmanager CAx, HAIDLMAIR GmbH
Production: NX10.0.3, VERICUT 8.1, FBM, MRL 3.1.7 | TcUA 10.1 MP7 Patch 0 ( | TcVis 11.4
Development: C (ITK), .NET, Tcl/Tk Testing: NX12.0 | AWC 3.4 Preparing: NX12.0

Employees of the customers, together we are strong Smiley Wink
How to Get the Most from Your Signature in the Community
NX Customization - Best Practice Guide

Re: NXOpen is returning an extra component

Siemens Phenom Siemens Phenom
Siemens Phenom

Hi Stefan,


I think he is trying to grab the occurrence bodies that live in the assembly.  The BodyCollection will not contain any of those - it will only return original bodies - prototypes, if you will - that live in the assembly part.







Re: NXOpen is returning an extra component

Valued Contributor
Valued Contributor

The issue is that my code is returning some component bodies and also a copy of the bodies, but the copies are owned by the assembly. So I have one too many components, and this throws off my total volume. The assembly was made using the Routing application. I have been told that this issue might be related to wave links in the assembly. However if you look at the part navigator there is no sign of these. All I can see that is out of the ordinary is a fixture port, which I believe was made by the routing application. Is it possible that the routing application creates these wave links "behind the scenes"?