Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF
Module NXJournal
Sub Main()
Dim theSession As Session = Session.GetSession()
Dim ufs As UFSession = UFSession.GetUFSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim lw As ListingWindow = theSession.ListingWindow
Dim mySelectedObjects() As NXObject
Dim myResponse As Selection.Response
Dim tagList As New List(Of NXOpen.Tag)
Dim strParasolid As String
lw.Open()
strParasolid = workPart.FullPath
strParasolid = Left(strParasolid, Len(strParasolid) - 4)
strParasolid = strParasolid & ".x_t"
If My.Computer.FileSystem.FileExists(strParasolid) Then
Try
My.Computer.FileSystem.DeleteFile(strParasolid)
Catch ex As Exception
lw.WriteLine(ex.GetType.ToString & " : " & ex.Message)
lw.WriteLine("journal exiting")
Exit Sub
End Try
End If
myResponse = SelectObjects(mySelectedObjects)
If (myResponse = Selection.Response.Cancel) OrElse (myResponse = Selection.Response.Back) Then
'user canceled selection, exit journal
Exit Sub
End If
For Each obj As Body In mySelectedObjects
If obj.IsOccurrence Then
If obj.OwningComponent.DisplayName.Length > 30 Then
obj.SetName(obj.OwningComponent.DisplayName.Substring(0, 30))
Else
obj.SetName(obj.OwningComponent.DisplayName)
End If
Else
If obj.OwningPart.Leaf.Length > 30 Then
obj.SetName(obj.OwningPart.Leaf.Substring(0, 30))
Else
obj.SetName(obj.OwningPart.Leaf)
End If
End If
tagList.Add(obj.Tag)
Next
ufs.Ps.ExportData(tagList.ToArray, strParasolid)
lw.WriteLine("Output file: " & strParasolid)
lw.Close()
End Sub
Function SelectObjects(ByRef selobj() As NXObject) As Selection.Response
Dim theUI As UI = UI.GetUI
Dim prompt As String = "Select Solid Bodies"
Dim title As String = "Selection"
Dim includeFeatures As Boolean = False
Dim keepHighlighted As Boolean = False
Dim selAction As Selection.SelectionAction = _
Selection.SelectionAction.ClearAndEnableSpecific
Dim scope As Selection.SelectionScope = Selection.SelectionScope.AnyInAssembly
Dim selectionMask_array(0) As Selection.MaskTriple
With selectionMask_array(0)
.Type = UFConstants.UF_solid_type
.Subtype = 0
.SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_BODY
End With
Dim resp As Selection.Response = theUI.SelectionManager.SelectObjects( _
prompt, title, scope, selAction, _
includeFeatures, keepHighlighted, selectionMask_array, selobj)
Return resp
End Function
End Module