×
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

Save Assembly In Different Directory script help

Save Assembly In Different Directory script help

Save Assembly In Different Directory script help

(OP)
This script takes the work part (assembly) and creates a new sub-directory under it called NewDirectory, and saves all the parts and assemblies to this one file.

Would anyone be able to modify this so instead of it creating a sub-directory called NewDirectory, it would instead create a new directory on your desktop of the work leaf part and put all the files in there?

CODE --> vb

' This inserts "\NewDirectory" into the filespec of each part,
' after the last folder and just before the part name.
'
' It saves the piece parts first, then the sub-assemblies, 
' and finally the top-level assembly.
'
' You should then be able to open the assembly from
' the new location using the 'as saved' option if desired
'
' Only the paths are changed - the filenames remain intact.
'
' Use cloning if you need to rename the files.


Option Strict Off

Imports System
Imports System.Collections  'This line is required to run this as a Journal
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.UI
Imports NXOpen.Utilities

Module save_assembly_in_different_directory

    Dim s As Session = Session.GetSession()
    Dim ufs As UFSession = UFSession.GetUFSession()
    Dim lw As ListingWindow = s.ListingWindow

    Sub Main()

        Dim allParts() As Part = s.Parts.ToArray()
        Dim pieceParts As New ArrayList
        Dim assyParts As New ArrayList

        For Each thisPart As Part In allParts
            Dim thisTag As NXOpen.Tag = ufs.Assem.AskRootPartOcc(thisPart.Tag)
            If thisTag = NXOpen.Tag.Null Then
                pieceParts.Add(thisPart)
            Else
                assyParts.Add(thisPart)
            End If
        Next

        lw.Open()
        lw.WriteLine("Piece parts found: " & pieceParts.Count.ToString())

        For inx As Integer = 0 To pieceParts.Count - 1
            Dim aPart As NXOpen.Part = pieceParts(inx)
            lw.WriteLine(inx.ToString() & ".  Original: " & aPart.FullPath())
            Dim newPath As String = _
                       aPart.FullPath.Insert(aPart.FullPath.LastIndexOf("\"), _
                         "\NewDirectory")
            lw.WriteLine("    Saving As: " & newPath)
            Dim pathOnly As String = Microsoft.VisualBasic.Left(newPath, _
                                                  newPath.LastIndexOf("\"))

            If My.Computer.FileSystem.DirectoryExists(pathOnly) = False Then
                My.Computer.FileSystem.CreateDirectory(pathOnly)
            End If

            Dim saveStatus As PartSaveStatus = Nothing
            saveStatus = aPart.SaveAs(newPath)
        Next
        lw.WriteLine("======================================================")
        lw.WriteLine(" ")

        lw.WriteLine("Assembly parts found:" & assyParts.Count.ToString())

        For inx As Integer = 0 To assyParts.Count - 1
            Dim aPart As NXOpen.Part = assyParts(inx)
            lw.WriteLine(inx.ToString() & ".  Original: " & aPart.FullPath())
            Dim newPath As String = _
                aPart.FullPath.Insert(aPart.FullPath.LastIndexOf("\"), _
                "\NewDirectory")
            lw.WriteLine("    Saving As: " & newPath)
            Dim pathOnly As String = Microsoft.VisualBasic.Left(newPath, _
                                                  newPath.LastIndexOf("\"))

            If My.Computer.FileSystem.DirectoryExists(pathOnly) = False Then
                My.Computer.FileSystem.CreateDirectory(pathOnly)
            End If

            Dim saveStatus As PartSaveStatus = Nothing
            saveStatus = aPart.SaveAs(newPath)
        Next

    End Sub

    Public Function GetUnloadOption(ByVal dummy As String) As Integer
        Return Session.LibraryUnloadOption.Immediately
    End Function

End Module 

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