Need help with VB Creating Incremental
Need help with VB Creating Incremental
(OP)
I have a vb script that creates a image file of the screen. But when I run the script it rewrites the file. What I would like to do is create a new file and add a incremental digit at the end. I have been trying for weeks with no dice. Is there anyone out there that can help?





RE: Need help with VB Creating Incremental
thread561-357735: Already Existing file - Create file with increment (1)
If you are having trouble with the implementation, you will need to ask a more specific question and possibly post the relevant code snippet that you have.
www.nxjournaling.com
RE: Need help with VB Creating Incremental
RE: Need help with VB Creating Incremental
Try this:
CODE
Option Strict Off Imports System Imports System.IO Imports NXOpen Imports NXOpen.UF Module increment_file_name 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 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 & "_Sect_" & strCurrentDate & ".jpg") Dim i As Integer = 1 Do While File.Exists(outputFile2) outputFile2 = IO.Path.Combine(outputPath, outputFile & "_Sect_" & strCurrentDate & "_" & i.ToString & ".jpg") i += 1 Loop 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 Modulewww.nxjournaling.com