×
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

Changing the folder destination HELP!!!!

Changing the folder destination HELP!!!!

Changing the folder destination HELP!!!!

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

RE: Changing the folder destination HELP!!!!

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

RE: Changing the folder destination HELP!!!!

(OP)
This is great!!! now what if i wanted to remove characters from a file name?

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