Skip to content

Instantly share code, notes, and snippets.

@davidtolsma
Created November 25, 2010 00:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save davidtolsma/714674 to your computer and use it in GitHub Desktop.
Save davidtolsma/714674 to your computer and use it in GitHub Desktop.
An Unigraphics NX journal file to test loading and saving times
' NX 5.0.1.4
' Journal created by dtolsma on Thu Sep 27 08:44:26 2007 Central Daylight Time
'
Option Strict Off
Imports System
Imports NXOpen
Imports System.Diagnostics
Module NXJournal
Sub Main
' Overall StopWatch
Dim stopWatch as StopWatch = new StopWatch()
Dim value As TimeSpan
Dim totalTime As String
' Individual Part StopWatch
Dim partWatch as StopWatch = new StopWatch()
Dim partTime As TimeSpan
Dim totalPartTime As String
' User Entry
Dim path As String
path = "C:\downloads\40136799_refile\"
Dim logFileName As String
logFileName = "H:\logs\40136799_LoadSave_NOT_COMPRESS_02OC2007.txt"
stopWatch.Start()
Dim theSession As Session = Session.GetSession()
Dim loadedPart As String
Dim loadParts() As String
' Read Directory
Dim directory As New IO.DirectoryInfo(path)
Dim directoryFiles As IO.FileInfo() = directory.GetFiles()
Dim fileNames As IO.FileInfo
Dim basePart1 As BasePart
Dim partLoadStatus1 As PartLoadStatus
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim markId1 As Session.UndoMarkId
Dim partSaveStatus1 As PartSaveStatus
For Each fileNames In directoryFiles
' Start the StopWatch
partWatch.Start()
' ----------------------------------------------
' Menu: File->Open...
' ----------------------------------------------
basePart1 = theSession.Parts.OpenBaseDisplay(path + fileNames.Name, partLoadStatus1)
partLoadStatus1.Dispose()
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Enter Gateway")
' ----------------------------------------------
' Menu: File->Save
' ----------------------------------------------
workPart = theSession.Parts.Work
partSaveStatus1 = workPart.Save(BasePart.SaveComponents.True, BasePart.CloseAfterSave.False)
partSaveStatus1.Dispose()
' ----------------------------------------------
' Menu: File->Close->All Parts
' ----------------------------------------------
theSession.Parts.CloseAll(BasePart.CloseModified.CloseModified, Nothing)
workPart = Nothing
displayPart = Nothing
partSaveStatus1 = Nothing
basePart1 = Nothing
partWatch.Stop()
partTime = partWatch.Elapsed
totalPartTime = string.Format("{0:00}:{1:00}:{2:00}.{3:00}", partTime.Hours, partTime.Minutes, partTime.Seconds, partTime.Milliseconds/10)
My.Computer.FileSystem.WriteAllText (logFileName, "Loaded: " + path + fileNames.Name + Environment.NewLine, True)
My.Computer.FileSystem.WriteAllText (logFileName, "Elapse Time: " + totalPartTime + Environment.NewLine + Environment.NewLine, True)
Next
' ----------------------------------------------
' Menu: Tools->Journal->Stop
' ----------------------------------------------
stopWatch.Stop()
value = stopWatch.Elapsed
totalTime = string.Format("{0:00}:{1:00}:{2:00}.{3:00}", value.Hours, value.Minutes, value.Seconds, value.Milliseconds/10)
My.Computer.FileSystem.WriteAllText (logFileName, Environment.NewLine , true)
My.Computer.FileSystem.WriteAllText (logFileName, "Total Load Time: " + totalTime, true)
End Sub
End Module
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment