Imports NXOpenImports NXOpen.AssembliesImports NXOpen.UIImports NXOpen.SelectionModule NXJournal    Sub Main()        Dim theSession As Session = Session.GetSession()        Dim workPart As Part = theSession.Parts.Work        Dim ui As UI = UI.GetUI()        ' コンポーネント選択用フィルタ        Dim selMask(0) As Selection.MaskTriple        selMask(0).Type = UFConstants.UF_component_type        Dim selectedObjects As TaggedObject() = Nothing        Dim response As Selection.Response = ui.SelectionManager.SelectObjects("コンポーネントを選択してください", _                                                    Selection.SelectionScope.AnyInAssembly, _                                                    Selection.SelectionAction.ClearAndEnableSpecific, _                                                    False, False, selMask, selectedObjects)        If response = Selection.Response.Ok AndAlso selectedObjects IsNot Nothing Then            theSession.ListingWindow.Open()            For Each obj As TaggedObject In selectedObjects                If TypeOf obj Is Component Then                    Dim comp As Component = CType(obj, Component)                    Dim path As String = GetComponentPath(comp)                    ' 保存ファイルのフルパス取得                    Dim partPath As String = "(未保存)"                    Dim part As Part = TryCast(comp.Prototype, Part)                    If part IsNot Nothing Then                        partPath = part.FullPath                    End If                    ' 出力                    theSession.ListingWindow.WriteLine("コンポーネントパス: " & path)                    theSession.ListingWindow.WriteLine("ファイルパス    : " & partPath)                    theSession.ListingWindow.WriteLine("")                End If            Next        Else            theSession.ListingWindow.Open()            theSession.ListingWindow.WriteLine("コンポーネントが選択されませんでした。")        End If    End Sub    ' アセンブリ階層のパスを取得    Function GetComponentPath(comp As Component) As String        Dim names As New List(Of String)        Dim current As Component = comp        While current IsNot Nothing            names.Insert(0, current.Name)            current = current.OwningComponent        End While        Return String.Join("/", names.ToArray())    End FunctionEnd Module

コメント

タイトルとURLをコピーしました