Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with VB Creating Incremental

Status
Not open for further replies.

mnash60

Materials
Feb 21, 2012
29
0
0
US
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?
 
Replies continue below

Recommended for you

Did you try the suggestion from your last thread on this topic?
thread561-357735

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
 
Don't forget to add the file extension type before checking for existence.
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 Module

www.nxjournaling.com
 
Status
Not open for further replies.
Back
Top