NX Journal 選択したコンポーネントに含まれるボディの密度を取得
2019/12/06 categories:NX Journal| tags:NX Journal|VB|
NXジャーナルでコンポーネントを選択してそれに含まれるボディの密度を取得するプログラムを作成しました。
VBコード
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()
' コンポーネントの選択
If SelectObjects("コンポーネントを選択してください", mySelectedComponents) <> Selection.Response.Ok Then
return
End If
lw.open()
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
Next
Next
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(
prompt,
"Select objects", ' title
Selection.SelectionScope.AnyInAssembly, ' SelectionScope
Selection.SelectionAction.ClearAndEnableSpecific, ' SelectionAction
False, ' includeFeatures
False, ' keepHighlighted
selectionMask_array,
selObj)
If resp = Selection.Response.Ok Then
For Each item As NXObject In selObj
dispObj.Add(CType(item, DisplayableObject))
Next
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If
End Function
End Module