mnash60
Materials
- Feb 21, 2012
- 29
I have a journal file creates an image with a unique file name. I what I want to do is when the journal file is ran for the 2nd time I need the file name to create a (1) and increments (2) (3) and so one. Below is the code I have been working with if i could get some help, I would greatly appreciate it.
Thanks in advance!
Option Strict Off
Imports System
Imports System.IO
Imports NXOpen
Imports NXOpen.UF
Module Module1
Sub Main()
Dim theSession As Session = Session.GetSession()
Dim ufs As UFSession = UFSession.GetUFSession()
Dim workPart As Part = theSession.Parts.Work
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'Get parent directory with IO commands
Dim directoryInfo As System.IO.DirectoryInfo
directoryInfo = System.IO.Directory.GetParent(IO.Path.GetDirectoryName(workPart.FullPath))
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Dim strCurrentDate As String = Format(Today, "MMddy")
Dim tempSelectedObjects() As NXObject
Dim step214File As String
Dim Filenumber as Integer
'Dim outputFile3 As String
Dim outputFile2 As String
Dim outputPath As String = IO.Path.GetDirectoryName(workPart.FullPath)
Dim outputFile As String = IO.Path.GetFileNameWithoutExtension(workPart.FullPath)
outputFile = mid(outputfile, 1, 11)
outputFile2 = IO.Path.Combine(outputPath, outputFile & "_ANT_” & strCurrentDate)
If File.Exists(outputFile2) Then
filenumber = 0
Do
fileNumber += 1
Loop While File.Exists(outputFile2)
outputFile2 = IO.Path.Combine(outputPath, outputFile & “_ANT_” & fileNumber, strCurrentDate)
End If
Dim strPartJpg As String = ""
strPartJpg =outputFile2
ufs.Disp.CreateImage(strPartJpg, UFDisp.ImageFormat.Jpeg, UFDisp.BackgroundColor.White)
End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
'Unloads the image when the NX session terminates
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination
End Function
End Module
Thanks in advance!
Option Strict Off
Imports System
Imports System.IO
Imports NXOpen
Imports NXOpen.UF
Module Module1
Sub Main()
Dim theSession As Session = Session.GetSession()
Dim ufs As UFSession = UFSession.GetUFSession()
Dim workPart As Part = theSession.Parts.Work
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'Get parent directory with IO commands
Dim directoryInfo As System.IO.DirectoryInfo
directoryInfo = System.IO.Directory.GetParent(IO.Path.GetDirectoryName(workPart.FullPath))
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Dim strCurrentDate As String = Format(Today, "MMddy")
Dim tempSelectedObjects() As NXObject
Dim step214File As String
Dim Filenumber as Integer
'Dim outputFile3 As String
Dim outputFile2 As String
Dim outputPath As String = IO.Path.GetDirectoryName(workPart.FullPath)
Dim outputFile As String = IO.Path.GetFileNameWithoutExtension(workPart.FullPath)
outputFile = mid(outputfile, 1, 11)
outputFile2 = IO.Path.Combine(outputPath, outputFile & "_ANT_” & strCurrentDate)
If File.Exists(outputFile2) Then
filenumber = 0
Do
fileNumber += 1
Loop While File.Exists(outputFile2)
outputFile2 = IO.Path.Combine(outputPath, outputFile & “_ANT_” & fileNumber, strCurrentDate)
End If
Dim strPartJpg As String = ""
strPartJpg =outputFile2
ufs.Disp.CreateImage(strPartJpg, UFDisp.ImageFormat.Jpeg, UFDisp.BackgroundColor.White)
End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
'Unloads the image when the NX session terminates
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination
End Function
End Module