×
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

Need help with VB Creating Incremental

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

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

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