|
DigiPara Liftdesigner LDX API
|
Treename: Shaft0.
3 code examples follow.
' from Samples/Src/LDXAPIExamples/Example_Benchmark.vb
Class Benchmarker
Dim run As Int32 = 0
Dim startTime As System.DateTime
Dim totalTime As System.TimeSpan = System.TimeSpan.FromSeconds(0)
Sub StartRun()
startTime = System.DateTime.UtcNow()
End Sub
Function EndRun(Optional minSeconds As Double = 30) As Boolean
Dim endTime = System.DateTime.UtcNow()
If run > 0 Then
totalTime = totalTime + (endTime - startTime)
Else
GC.Collect()
End If
run = run + 1
Return totalTime > System.TimeSpan.FromSeconds(minSeconds)
End Function
Function TimePerRun() As Double
Return totalTime.TotalSeconds() / run
End Function
Public Shared Function Benchmark(f As TestRunOnDocument, ByRef ldxDocument As DigiPara.LDX.LDXDocument, Optional minSeconds As Double = 30) As Double
Dim b As Benchmarker = New Benchmarker
Do
b.StartRun()
f(ldxDocument)
If (b.EndRun(minSeconds)) Then
Exit Do
End If
Loop
Return b.TimePerRun()
End Function
Public Shared Sub Benchmark(f As TestRunOnDocument, ByRef ldxDocument As DigiPara.LDX.LDXDocument, name As String, log As Text.StringBuilder, Optional minSeconds As Double = 30)
Dim result = Benchmark(f, ldxDocument, minSeconds)
log.AppendLine(String.Format("{0,-20} : {1,10:F2}s", name, result))
End Sub
End Class
Private Shared Sub CalculateModelLDX(ByRef ldxDocument As DigiPara.LDX.LDXDocument)
ldxDocument.CalculateModel(DigiPara.LDX.CalculateModelModes.rcmCalc Or DigiPara.LDX.CalculateModelModes.rcmKeepCleanFrames Or DigiPara.LDX.CalculateModelModes.rcmSuppressBuildManagedRenderViews Or DigiPara.LDX.CalculateModelModes.rcmSuppressVba)
End Sub
Private Shared Sub CalculateModelFull(ByRef ldxDocument As DigiPara.LDX.LDXDocument)
ldxDocument.CalculateModel(DigiPara.LDX.CalculateModelModes.rcmCalc Or DigiPara.LDX.CalculateModelModes.rcmKeepCleanFrames Or DigiPara.LDX.CalculateModelModes.rcmSuppressBuildManagedRenderViews)
End Sub
Private Shared Sub CalculateModelAndBuildSheet(ByRef ldxDocument As DigiPara.LDX.LDXDocument)
ldxDocument.CalculateModelAndBuildSheet(DigiPara.LDX.CalculateModelModes.rcmCalcAndReport, Nothing)
End Sub
Private Shared Sub SaveUndo(ByRef ldxDocument As DigiPara.LDX.LDXDocument)
ldxDocument.SaveUndo(DigiPara.LDX.DocSaveUndoModes.dsmSaveAll)
End Sub
<APIHelpAttribute(APIHelpModes.LoadLD3File, {APIHelpModes.InputParaLDXDoc}, "Shaft0.", "LDXDocument~Example_Benchmark", "Time All CalculateModel")>
Public Shared Sub TimeCalculateModel(ByRef ldxDocument As DigiPara.LDX.LDXDocument)
If ldxDocument Is Nothing Then
MsgBox("No document loaded.")
Exit Sub
End If
Dim log = New Text.StringBuilder
Benchmarker.Benchmark(AddressOf CalculateModelLDX, ldxDocument, "LDX only CalculateModel", log, 10)
Benchmarker.Benchmark(AddressOf CalculateModelFull, ldxDocument, "Full CalculateModel", log, 10)
Benchmarker.Benchmark(AddressOf CalculateModelAndBuildSheet, ldxDocument, "Full CalculateModelAndBuildSheet", log, 10)
Benchmarker.Benchmark(AddressOf SaveUndo, ldxDocument, "SaveUndo", log, 10)
ldxDocument.UndoLastChange(ldxDocument.UndoCount)
MessageBox.Show(log.ToString)
End Sub
' from Samples/Src/LDXAPIExamples/Example_Benchmark.vb
<APIHelpAttribute(APIHelpModes.LoadLD3File, {APIHelpModes.InputParaLDXDoc}, "Shaft0.", "LDXDocument~Example_Benchmark", "Time .NET CalculateModel Current Document")>
Public Shared Sub TimeModelCalculating(ByRef ldxDocument As DigiPara.LDX.LDXDocument)
If ldxDocument Is Nothing Then
MsgBox("No document loaded.")
Exit Sub
End If
Dim log = New Text.StringBuilder
Benchmarker.Benchmark(AddressOf CalculateModelFull, ldxDocument, "Full CalculateModel", log, 120)
MessageBox.Show(log.ToString)
End Sub
' from Samples/Src/LDXAPIExamples/Example_Benchmark.vb
<APIHelpAttribute(APIHelpModes.InputParaLDXApp, {APIHelpModes.InputParaLDXApp}, "Shaft0.", "LDXDocument~Example_Benchmark", "Time .NET CalculateModel All Documents")>
Public Shared Sub TimeAllModelCalculating(ldxApplication As LDX.LDXApplication)
If ldxApplication Is Nothing Then
MsgBox("No application loaded.")
Exit Sub
End If
Dim log = New Text.StringBuilder
For Each ldxDocument As DigiPara.LDX.LDXDocument In ldxApplication.Documents
Benchmarker.Benchmark(AddressOf CalculateModelFull, ldxDocument, "Full CalculateModel " + System.IO.Path.GetFileName(ldxDocument.Filename), log, 30)
Next
MessageBox.Show(log.ToString)
End Sub