Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports Microsoft.VisualBasic
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 NXOpen.Tag
Dim exportFileName As String = Nothing
Dim exportFileName1 As String = Nothing
Dim nazwa as string
Dim path As String
'Dim PSversion as integer = 240
Dim i As Integer = 0
lw.Open()
myResponse = SelectObjects(mySelectedObjects)
If (myResponse = Selection.Response.Cancel) OrElse (myResponse = Selection.Response.Back) Then
'user canceled selection, exit journal
Exit Sub
End If
ReDim tagList(mySelectedObjects.GetUpperBound(0))
For i = 0 To mySelectedObjects.GetUpperBound(0)
tagList(i) = mySelectedObjects(i).Tag
Next
'return the full path of the work part
exportFileName = workPart.FullPath
nazwa = workPart.Leaf
exportFileName = exportFileName.Remove(exportFileName.Length - (workPart.Leaf.length + 4))
path = exportfilename + "step"
If(Not System.IO.Directory.Exists(Path)) Then
System.IO.Directory.CreateDirectory(Path)
End If
exportFileName = "step\" + nazwa + ".x_t"
'msgbox(exportFileName)
'if this file already exists, delete it
If My.Computer.FileSystem.FileExists(exportFileName) Then
My.Computer.FileSystem.DeleteFile(exportFileName)
End If
Dim numUnexported As Integer
Try
'ufs.Ps.ExportData(tagList, exportFileName)
ufs.Ps.ExportLinkedData(Taglist, Taglist.Length, exportFileName, 220, Nothing, numUnexported, Nothing)
Catch ex As NXException
lw.WriteLine("*** ERROR ***")
lw.WriteLine(ex.ErrorCode.ToString & " : " & ex.Message)
End Try
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_SOLID_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