Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Changing the folder destination HELP!!!!

Status
Not open for further replies.

mnash60

Materials
Feb 21, 2012
29
In this piece of code the output file goes to the folder where the .prt file is located.

Dim theSession As Session = Session.GetSession()
Dim ufs As UFSession = UFSession.GetUFSession()
Dim workPart As Part = theSession.Parts.Work
Dim outputPath As String = IO.Path.GetDirectoryName(workPart.FullPath)
Dim outputFile As String = IO.Path.GetFileNameWithoutExtension(workPart.FullPath)
outputFile = IO.Path.Combine(outputPath, outputFile & "MatingSurf")



I have been trying to do two things with no luck.

First, instead of the same folder I need to go back to a certain folder in the root folder.

N:\CAD Data\DATA\dwr12324\Step Data Release\Release CAD Is where the .prt file is located

N:\CAD Data\DATA\dwr12324\Step Data Release\Mating Surfaces Is where the .prt file is located

In excel I know that I can use the left string to rename the folder detestation but it seems not to work with UG.
 
Replies continue below

Recommended for you

You can still get to the parent directory by using string manipulation commands, but in my opinion, it is easier to use a directoryInfo object. The code below shows one way to do it with string manipulation and how to do it with a directoryInfo object.

Code:
Option Strict Off 
Imports System
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 string manipulation commands
        Dim parentDir As String
        parentDir = IO.Path.GetDirectoryName(workPart.FullPath)
        parentDir = parentDir.Substring(0, parentDir.Length - (parentDir.Length - parentDir.LastIndexOf("\")))
        MsgBox("parentDir: " & parentDir)
        '*************************************

        '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        'Get parent directory with IO commands
        Dim directoryInfo As System.IO.DirectoryInfo
        directoryInfo = System.IO.Directory.GetParent(IO.Path.GetDirectoryName(workPart.FullPath))
        '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

        'change "temp" to the directory name of your choosing
        Dim outputPath As String = IO.Path.Combine(directoryInfo.FullName, "temp")

        If Not IO.Directory.Exists(outputPath) Then
            'code to create directory here, if desired...
            MsgBox("The specified directory:" & ControlChars.CrLf & outputPath & ControlChars.CrLf & _
                   "does not exist. Please create the directory and re-run the journal")
            Return
        End If

        Dim outputFile As String = IO.Path.GetFileNameWithoutExtension(workPart.FullPath)
        outputFile = IO.Path.Combine(outputPath, outputFile & "MatingSurf")

        ufs.Disp.CreateImage(outputFile, 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
 
This is great!!! now what if i wanted to remove characters from a file name?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor