NX Journal 選択したコンポーネントに含まれるボディの密度を取得

Share on:

NXジャーナルでコンポーネントを選択してそれに含まれるボディの密度を取得するプログラムを作成しました。

VBコード

 1Option Strict Off
 2Imports System
 3Imports System.Collections.Generic
 4Imports NXOpen
 5
 6Module NXJournal
 7
 8    Sub Main()
 9
10        Dim theSession As Session = Session.GetSession()
11        Dim workPart As Part = theSession.Parts.Work
12        Dim displayPart As Part = theSession.Parts.Display
13        Dim lw As ListingWindow = theSession.ListingWindow
14        Dim mySelectedComponents As New List(Of Assemblies.Component)
15        Dim theUI As UI = UI.GetUI()
16
17        ' コンポーネントの選択
18        If SelectObjects("コンポーネントを選択してください", mySelectedComponents) <> Selection.Response.Ok Then
19            return
20        End If
21
22        lw.open()
23
24        For Each theComponent As Assemblies.Component in mySelectedComponents
25            Dim myPart As Part = CType(theComponent.Prototype.OwningPart, Part)
26            For Each myBody As Body In myPart.Bodies
27                If myBody.IsSolidBody() Then
28                    lw.writeline( myBody.Density )
29                End If
30            Next
31        Next
32
33    End Sub
34
35    Function SelectObjects(prompt As String, ByRef dispObj As List(Of Assemblies.Component)) As Selection.Response
36
37        Dim selObj As NXObject()
38        Dim selectionMask_array(0) As Selection.MaskTriple
39
40        With selectionMask_array(0)
41            .Type = UF.UFConstants.UF_component_type
42            .Subtype = UF.UFConstants.UF_component_subtype
43        End With
44
45        Dim resp As Selection.Response = UI.GetUI.SelectionManager.SelectObjects(
46            prompt, 
47            "Select objects", ' title
48            Selection.SelectionScope.AnyInAssembly, ' SelectionScope
49            Selection.SelectionAction.ClearAndEnableSpecific, ' SelectionAction
50            False, ' includeFeatures
51            False, ' keepHighlighted
52            selectionMask_array, 
53            selObj)
54
55        If resp = Selection.Response.Ok Then
56            For Each item As NXObject In selObj
57                dispObj.Add(CType(item, DisplayableObject))
58            Next
59            Return Selection.Response.Ok
60        Else
61            Return Selection.Response.Cancel
62        End If
63
64    End Function
65
66End Module

関連記事