×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Already Existing file - Create file with increment (1)

Already Existing file - Create file with increment (1)

Already Existing file - Create file with increment (1)

(OP)
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




RE: Already Existing file - Create file with increment (1)

Check to see if the file already exists before the export. If it does, add an increment to the file name and test again. Repeat until you find a file name that doesn't already exist.

Here's some pseudocode:

CODE --> psuedocode

'generate base file name
myFile = "C:\temp\somefile"

dim i as integer = 0
do
  i += 1
  myFile & i
loop until NOT myFile.exists 

www.nxjournaling.com

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources