' ' Erstellt mit SharpDevelop. ' Benutzer: Administrator ' Datum: 13.10.2008 ' Zeit: 14:58 ' ' Sie können diese Vorlage unter Extras > Optionen > Codeerstellung > Standardheader ändern. ' Option Strict Off Imports System Imports System.IO Imports System.Windows.Forms Imports NXOpen Imports NXOpen.UF Imports NXOpen.Utilities Module TestBlockPerformance Dim Ses As Session = Session.GetSession() Dim UFSes As UFSession = UFSession.GetUFSession() Dim UISes As UI = UI.GetUI() Dim TempPath As String = Environment.GetEnvironmentVariable("TMP") Dim UGRelease As String = Nothing Dim UGFullRelease As String = Nothing Sub Main Ses.LogFile.WriteLine("Executing ... " & Ses.ExecutingJournal) UFSes.UF.TranslateVariable("UGII_VERSION", UGRelease) UFSes.UF.TranslateVariable("UGII_FULL_VERSION", UGFullRelease) Dim BlockCount, Response, Row, Column As Integer Dim MenuItems(9), TextPart, LogFile, FileName As String Dim dPoint() As Double = {0.0, 0.0, 0.0} Dim tBlock As Tag = Tag.Null Dim cEdges() As String = {"10", "10", "10"} Dim wPart As Part Dim TotalElapsedTime As TimeSpan Dim StartTime, EndTime, ElapsedTime As TimeSpan Dim Failure As String = "Succeeded" For Row = 1 To 10 MenuItems(Row - 1) = 1000 * Row & " Blocks" Next If UFSes.Ui.LockUgAccess(UFConstants.UF_UI_FROM_CUSTOM) = UFConstants.UF_UI_LOCK_SET Then UFSes.Abort.DisableAbort Response = UFSes.Ui.DisplayMenu("Select Blocks to create", 0, MenuItems, MenuItems.Length) Select Case Response Case 1, 2 UFSes.Ui.UnlockUgAccess(UFConstants.UF_UI_FROM_CUSTOM) UFSes.Abort.EnableAbort Exit Sub Case 19 MsgBox("Unable to display dialog!", MsgBoxStyle.Critical, "Aborting") UFSes.Ui.UnlockUgAccess(UFConstants.UF_UI_FROM_CUSTOM) UFSes.Abort.EnableAbort Exit Sub Case Else For Each TextPart In Split(MenuItems(Response - 5)) BlockCount = CInt(TextPart) Exit For Next End Select UFSes.Ui.UnlockUgAccess(UFConstants.UF_UI_FROM_CUSTOM) else MsgBox("Unable to lock dialog area!", MsgBoxStyle.Critical, "Aborting") Exit Sub End If FileName = Path.Combine(TempPath, "Test_" & BlockCount & "_Blocks_" & UGRelease & ".prt") If File.Exists(FileName) Then File.Delete(FileName) wPart = Ses.Parts.NewDisplay(FileName, Part.Units.Millimeters) Ses.SetUndoMark(Session.MarkVisibility.Visible, "Create " & BlockCount & " Blocks") LogFile = Path.GetDirectoryName(FileName) & "\" & _ Path.GetFileNameWithoutExtension(FileName) & "_" & _ Environment.MachineName & ".txt" If File.Exists(LogFile) = True Then File.Delete(LogFile) Ses.ListingWindow.SelectDevice(ListingWindow.DeviceType.FileAndWindow,LogFile) Ses.ListingWindow.Open() Ses.ListingWindow.WriteLine("") Ses.ListingWindow.WriteLine("NX " & UGFullRelease) Ses.ListingWindow.WriteLine("") Ses.ListingWindow.WriteLine(Path.GetDirectoryName(FileName)) Ses.ListingWindow.WriteLine("") Ses.ListingWindow.WriteLine(Path.GetFileName(FileName)) Ses.ListingWindow.WriteLine("") Ses.ListingWindow.WriteLine("Creating " & BlockCount & " Blocks ...") Dim wView As NXOpen.View = wPart.Views.WorkView Dim RendStyle As New UFView.Visualization UFSes.View.AskVisualization(wView.Tag, RendStyle) RendStyle.display_mode = UFConstants.UF_VIEW_NOT_SHADED UFSes.View.SetVisualization(wView.Tag, RendStyle) StartTime = DateTime.Now.TimeOfDay Try For Row = 1 To BlockCount / 100 For column = 1 To 100 UFSes.Modl.CreateBlock1(0, dPoint, cEdges, tBlock) dPoint(0) = dPoint(0) + 15 Next dPoint(1) = dPoint(1) + 15 dPoint(0) = 0 Next Catch E As Exception Failure = E.Message End Try EndTime = DateTime.Now.TimeOfDay ElapsedTime = EndTime.Subtract(StartTime) TotalElapsedTime = TotalElapsedTime.Add(ElapsedTime) Ses.ListingWindow.WriteLine(" Create Blocks ... " & Failure) Ses.ListingWindow.WriteLine(" Start Time ... " & FormatTime(StartTime)) Ses.ListingWindow.WriteLine(" End Time ..... " & FormatTime(EndTime)) Ses.ListingWindow.WriteLine(" Elapsed ... " & FormatTime(ElapsedTime)) wPart.Views.WorkView.Fit JHTimeFileSave(TotalElapsedTime) Dim DirInfo As New DirectoryInfo(Path.GetDirectoryName(FileName)) Dim FInfoArr As FileInfo() = DirInfo.GetFiles(Path.GetFileName(FileName)) Dim FInfo As FileInfo For Each FInfo In FInfoArr Ses.ListingWindow.WriteLine("") Ses.ListingWindow.WriteLine("File Size ... " & FInfo.Length & " Bytes") Next Ses.ListingWindow.WriteLine("") Ses.ListingWindow.WriteLine("Total Elapsed Time for Part Testing ... " & FormatTime(TotalElapsedTime)) Ses.ListingWindow.WriteLine("") Ses.ListingWindow.WriteLine(GetSystemInfo()) Ses.ListingWindow.WriteLine("") Ses.ListingWindow.Close() Ses.ListingWindow.SelectDevice(ListingWindow.DeviceType.Window,"") Ses.ListingWindow.Open() Ses.ListingWindow.WriteLine("") Ses.ListingWindow.WriteLine("Information saved to:") Ses.ListingWindow.WriteLine(vbTab & LogFile) End Sub Sub JHTimeFileSave(ByRef TotalTime As TimeSpan) Dim StartTime, EndTime, ElapsedTime As TimeSpan Dim Failure As String = "Succeeded" Dim wPart As Part = Ses.Parts.Work Dim SaveStatus As PartSaveStatus = Nothing StartTime = DateTime.Now.TimeOfDay ' Try ' wPart.Save(Part.SaveComponents.False, Part.CloseAfterSave.False, SaveStatus) ' ' If SaveStatus.NumberUnsavedParts > 0 Then ' Failure = "Save Failure" ' End If ' Catch E As Exception ' Failure = E.Message ' End Try EndTime = DateTime.Now.TimeOfDay ElapsedTime = EndTime.Subtract(StartTime) TotalTime = TotalTime.Add(ElapsedTime) Ses.ListingWindow.WriteLine(" Save Part ....... " & Failure) Ses.ListingWindow.WriteLine(" Start Time ... " & FormatTime(StartTime)) Ses.ListingWindow.WriteLine(" End Time ..... " & FormatTime(EndTime)) Ses.ListingWindow.WriteLine(" Elapsed ... " & FormatTime(ElapsedTime)) End Sub Function FormatTime(TimeValue As TimeSpan) As String return TimeValue.Hours.ToString("00") & ":" & _ TimeValue.Minutes.ToString("00") & ":" & _ TimeValue.Seconds.ToString("00") & "." & _ TimeValue.Milliseconds.ToString("000") End Function Function GetSystemInfo() As String Dim SystemInfo As String = Nothing Dim InfoFile As String = TempPath & "\GetSystemInfo.txt" Dim VBScript As String = TempPath & "\GetSystemInfo.vbs" Dim VBFile As StreamWriter Dim TxtFile As StreamReader Dim VBProc As Diagnostics.Process VBFile = New StreamWriter(VBScript) VBFile.WriteLine( "On Error Resume Next" ) VBFile.WriteLine( "" ) VBFile.WriteLine( "Set fso = CreateObject(" & Chr(34) & "Scripting.FileSystemObject" & Chr(34) & ")" ) VBFile.WriteLine( "" ) VBFile.WriteLine( "Set LogFile = fso.CreateTextFile(" & Chr(34) & InfoFile & Chr(34) & ", True)" ) VBFile.WriteLine( "" ) VBFile.WriteLine( "LogFile.WriteLine()" ) VBFile.WriteLine( "LogFile.WriteLine(" & Chr(34) & "Computer System" & Chr(34) & ")" ) VBFile.WriteLine( "" ) VBFile.WriteLine( "For Each objComp in GetObject(" & Chr(34) & "winmgmts:" & Chr(34) & ").InstancesOf(" & Chr(34) & "Win32_ComputerSystem" & Chr(34) & ")" ) VBFile.WriteLine( "" ) VBFile.WriteLine( " LogFile.WriteLine(vbTab & " & Chr(34) & "Caption = " & Chr(34) & " & objComp.Caption)" ) VBFile.WriteLine( " LogFile.WriteLine(vbTab & " & Chr(34) & "Manufacturer = " & Chr(34) & " & objComp.Manufacturer)" ) VBFile.WriteLine( " LogFile.WriteLine(vbTab & " & Chr(34) & "Model = " & Chr(34) & " & objComp.Model)" ) VBFile.WriteLine( " LogFile.WriteLine(vbTab & " & Chr(34) & "SystemType = " & Chr(34) & " & objComp.SystemType)" ) VBFile.WriteLine( " LogFile.WriteLine(vbTab & " & Chr(34) & "NumberOfProcessors = " & Chr(34) & " & objComp.NumberOfProcessors)" ) VBFile.WriteLine( "Next" ) VBFile.WriteLine( "" ) VBFile.WriteLine( "LogFile.WriteLine()" ) VBFile.WriteLine( "LogFile.WriteLine(" & Chr(34) & "Operating System" & Chr(34) & ")" ) VBFile.WriteLine( "" ) VBFile.WriteLine( "For Each objOS in GetObject(" & Chr(34) & "winmgmts:" & Chr(34) & ").InstancesOf(" & Chr(34) & "Win32_OperatingSystem" & Chr(34) & ")" ) VBFile.WriteLine( "" ) VBFile.WriteLine( " LogFile.WriteLine(vbTab & " & Chr(34) & "Caption = " & Chr(34) & " & objOS.Caption)" ) VBFile.WriteLine( " LogFile.WriteLine(vbTab & " & Chr(34) & "Version = " & Chr(34) & " & objOS.Version)" ) VBFile.WriteLine( " LogFile.WriteLine(vbTab & " & Chr(34) & "CSDVersion = " & Chr(34) & " & objOS.CSDVersion)" ) VBFile.WriteLine( " LogFile.WriteLine()" ) VBFile.WriteLine( " LogFile.WriteLine(vbTab & " & Chr(34) & "MaxProcessMemorySize = " & Chr(34) & " & FormatNumber(CDbl(objOS.MaxProcessMemorySize) / 1024,0) & " & Chr(34) & " MByte" & Chr(34) & ")" ) VBFile.WriteLine( " LogFile.WriteLine(vbTab & " & Chr(34) & "TotalVirtualMemorySize = " & Chr(34) & " & FormatNumber(CDbl(objOS.TotalVirtualMemorySize) /1024,0) & " & Chr(34) & " MByte" & Chr(34) & ")" ) VBFile.WriteLine( "Next" ) VBFile.WriteLine( "" ) VBFile.WriteLine( "LogFile.WriteLine(" & Chr(34) & "Physical Memory" & Chr(34) & ")" ) VBFile.WriteLine( "" ) VBFile.WriteLine( "Set TotalCapacity = 0" ) VBFile.WriteLine( "" ) VBFile.WriteLine( "For Each objMEM in GetObject(" & Chr(34) & "winmgmts:" & Chr(34) & ").InstancesOf(" & Chr(34) & "Win32_PhysicalMemory" & Chr(34) & ")" ) VBFile.WriteLine( " TotalCapacity = TotalCapacity + CDbl(objMEM.Capacity)" ) VBFile.WriteLine( "Next" ) VBFile.WriteLine( "" ) VBFile.WriteLine( "LogFile.WriteLine(vbTab & " & Chr(34) & "Total Capacity = " & Chr(34) & " & FormatNumber(TotalCapacity / 1024 / 1024,0) & " & Chr(34) & " MByte" & Chr(34) & ")" ) VBFile.WriteLine( "" ) VBFile.WriteLine( "LogFile.WriteLine()" ) VBFile.WriteLine( "LogFile.WriteLine(" & Chr(34) & "Processor" & Chr(34) & ")" ) VBFile.WriteLine( "" ) VBFile.WriteLine( "For Each objCPU in GetObject(" & Chr(34) & "winmgmts:" & Chr(34) & ").InstancesOf(" & Chr(34) & "Win32_Processor" & Chr(34) & ")" ) VBFile.WriteLine( "" ) VBFile.WriteLine( " LogFile.WriteLine(vbTab & " & Chr(34) & "Name = " & Chr(34) & " & Trim(objCPU.Name))" ) VBFile.WriteLine( " LogFile.WriteLine(vbTab & " & Chr(34) & "Manufacturer = " & Chr(34) & " & objCPU.Manufacturer)" ) VBFile.WriteLine( " LogFile.WriteLine(vbTab & " & Chr(34) & "MaxClockSpeed = " & Chr(34) & " & FormatNumber(objCPU.MaxClockSpeed,0) & " & Chr(34) & " GHz" & Chr(34) & ")" ) VBFile.WriteLine( " LogFile.WriteLine(vbTab & " & Chr(34) & "CurrentClockSpeed = " & Chr(34) & " & FormatNumber(objCPU.CurrentClockSpeed,0) & " & Chr(34) & " GHz" & Chr(34) & ")" ) VBFile.WriteLine( " LogFile.WriteLine(vbTab & " & Chr(34) & "ExtClock = " & Chr(34) & " & FormatNumber(objCPU.ExtClock,0) & " & Chr(34) & " MHz" & Chr(34) & ")" ) VBFile.WriteLine( "" ) VBFile.WriteLine( " LogFile.WriteLine()" ) VBFile.WriteLine( "Next" ) VBFile.WriteLine( "" ) VBFile.WriteLine( "LogFile.WriteLine()" ) VBFile.WriteLine( "LogFile.WriteLine(" & Chr(34) & "Video Controller" & Chr(34) & ")" ) VBFile.WriteLine( "" ) VBFile.WriteLine( "For Each objDC in GetObject(" & Chr(34) & "winmgmts:" & Chr(34) & ").InstancesOf(" & Chr(34) & "Win32_VideoController" & Chr(34) & ")" ) VBFile.WriteLine( "" ) VBFile.WriteLine( " LogFile.WriteLine(vbTab & " & Chr(34) & "Caption = " & Chr(34) & " & objDC.Caption)" ) VBFile.WriteLine( " LogFile.WriteLine(vbTab & " & Chr(34) & "VideoProcessor = " & Chr(34) & " & objDC.VideoProcessor)" ) VBFile.WriteLine( " LogFile.WriteLine(vbTab & " & Chr(34) & "AdapterRAM = " & Chr(34) & " & FormatNumber(objDC.AdapterRAM / 1024 / 1024,0) & " & Chr(34) & " MByte" & Chr(34) & ")" ) VBFile.WriteLine( " LogFile.WriteLine(vbTab & " & Chr(34) & "DriverVersion = " & Chr(34) & " & objDC.DriverVersion)" ) VBFile.WriteLine( " LogFile.WriteLine(vbTab & " & Chr(34) & "DriverDate = " & Chr(34) & " & StringToDate(objDC.DriverDate))" ) VBFile.WriteLine( " LogFile.WriteLine(vbTab & " & Chr(34) & "VideoModeDescription = " & Chr(34) & " & objDC.CurrentHorizontalResolution & _" ) VBFile.WriteLine( " " & Chr(34) & " x " & Chr(34) & " & objDC.CurrentVerticalResolution & _" ) VBFile.WriteLine( " " & Chr(34) & " x " & Chr(34) & " & objDC.CurrentBitsPerPixel & " & Chr(34) & "bpp" & Chr(34) & ")" ) VBFile.WriteLine( "Next" ) VBFile.WriteLine( "" ) VBFile.WriteLine( "LogFile.Close" ) VBFile.WriteLine( "" ) VBFile.WriteLine( "WScript.Quit" ) VBFile.WriteLine( "" ) VBFile.WriteLine( "Function StringToDate(sDate)" ) VBFile.WriteLine( " sYear = Left(sDate, 4)" ) VBFile.WriteLine( " sMonth = Mid(sDate, 5, 2)" ) VBFile.WriteLine( " sDay = Mid(sDate, 7, 2)" ) VBFile.WriteLine( "" ) VBFile.WriteLine( " sHour = Mid(sDate, 9, 2)" ) VBFile.WriteLine( " sMinute = Mid(sDate, 11, 2)" ) VBFile.WriteLine( " sSecond = Mid(sDate, 13, 2)" ) VBFile.WriteLine( "" ) VBFile.WriteLine( " StringToDate = CDate(sMonth & " & Chr(34) & "/" & Chr(34) & " & sDay & " & Chr(34) & "/" & Chr(34) & " & sYear & " & Chr(34) & " " & Chr(34) & " & sHour & " & Chr(34) & ":" & Chr(34) & " & sMinute & " & Chr(34) & ":" & Chr(34) & " & sSecond)" ) VBFile.WriteLine( "End Function" ) VBFile.Flush() VBFile.Close() VBProc = Diagnostics.Process.Start(VBScript) VBProc.WaitForExit() TxtFile = New StreamReader(InfoFile) SystemInfo = TxtFile.ReadToEnd() TxtFile.Close() Return SystemInfo End Function End Module