NX Journal Get the density of the body contained in the selected component

2019/12/06 categories:NX Journal| tags:NX Journal|VB|

I have created a program to select a component in the NX journal and get the density of the bodies contained in it.

VB Code

Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen

Module NXJournal

    Sub Main()

        Dim theSession As Session = Session.GetSession()
        Dim workPart As Part = theSession.Parts.Work
        Dim displayPart As Part = theSession.Parts.Display
        Dim lw As ListingWindow = theSession.ListingWindow
        Dim mySelectedComponents As New List(Of Assemblies.Component)
        Dim theUI As UI = UI.GetUI()

        ' Component selection
        If SelectObjects("Please select a component", mySelectedComponents) <> Selection.Response.Ok Then
        End If


        For Each theComponent As Assemblies.Component in mySelectedComponents
            Dim myPart As Part = CType(theComponent.Prototype.OwningPart, Part)
            For Each myBody As Body In myPart.Bodies
                If myBody.IsSolidBody() Then
                    lw.writeline( myBody.Density )
                End If

    End Sub

    Function SelectObjects(prompt As String, ByRef dispObj As List(Of Assemblies.Component)) As Selection.Response

        Dim selObj As NXObject()
        Dim selectionMask_array(0) As Selection.MaskTriple

        With selectionMask_array(0)
            .Type = UF.UFConstants.UF_component_type
            .Subtype = UF.UFConstants.UF_component_subtype
        End With

        Dim resp As Selection.Response = UI.GetUI.SelectionManager.SelectObjects(
            "Select objects", ' title
            Selection.SelectionScope.AnyInAssembly, ' SelectionScope
            Selection.SelectionAction.ClearAndEnableSpecific, ' SelectionAction
            False, ' includeFeatures
            False, ' keepHighlighted

        If resp = Selection.Response.Ok Then
            For Each item As NXObject In selObj
                dispObj.Add(CType(item, DisplayableObject))
            Return Selection.Response.Ok
            Return Selection.Response.Cancel
        End If

    End Function

End Module

Share post

Related Posts