API example: Reading pressure data
Time-series data are available through the API as the independent values of a plot. This is how animations are represented.
This example performs the following tasks:
- Extracts the pressure result and computes the average pressure of each set of five time steps
- Reconstructs a custom pressure plot
You can use this example when you want to read a specific result set, or put the data into a new result set.
'%RunPerInstance
'@
'@ DESCRIPTION
'@ Split Presssure Time Series Result into Individual Results.
'@ Recreate the Pressure Time Series Result
'@
'@ SYNTAX
'@ ReadingPressureData
'@
'@ PARAMETERS
'@ none
'@
'@ DEPENDENCIES/LIMITATIONS
'@ none
'@
'@ History
'@ Created DRA 9/8/2006
'@@
Option Explicit
SetLocale("en-us")
Dim SynergyGetter, Synergy
On Error Resume Next
Set SynergyGetter = GetObject(CreateObject("WScript.Shell").ExpandEnvironmentStrings("%SAInstance%"))
On Error GoTo 0
If (Not IsEmpty(SynergyGetter)) Then
Set Synergy = SynergyGetter.GetSASynergy
Else
Set Synergy = CreateObject("synergy.Synergy")
End If
Synergy.SetUnits "METRIC"
Dim PlotManager
Dim ResultID, Header, UserPlot, Indp, nodeID, Value, IndpValues, i, j ,Ave, Count, Str
ResultID = 1180
' Split Presssure Result into Individual Results.
Set PlotManager = Synergy.PlotManager()
Set IndpValues = Synergy.CreateDoubleArray()
PlotManager.GetIndpValues ResultID, IndpValues
' Display to Screen Average Pressure at interval through results
For i = 0 to IndpValues.size()-1 Step 5
Set PlotManager = Synergy.PlotManager()
Set Indp = Synergy.CreateDoubleArray()
Indp.AddDouble(IndpValues.val(i))
Set nodeID = Synergy.CreateIntegerArray()
Set Value = Synergy.CreateDoubleArray()
PlotManager.GetScalarData ResultID, Indp, nodeID, Value
Ave = 0.0
Count = 0.0
For j = 0 To nodeID.size - 1
Count = Count +1
Ave = Ave + Value.val(j)
Next
If Count > 0 Then
Ave = Ave / cdbl(count)
End If
Str = Str + "Time=" & CStr(IndpValues.val(i)) & " Average P =" & Ave &" MPa" & vbCRLF
Next
MsgBox Str
'Recreate current Time Series Pressure Result
Set UserPlot = PlotManager.CreateUserPlot()
Header = "New Pressure Time Series"
PlotManager.DeletePlotByName(Header)
UserPlot.SetName(Header)
UserPlot.SetDataType("NDDT")
UserPlot.SetDeptUnitName("MPa")
UserPlot.SetDeptName("Time")
UserPlot.SetVectorAsDisplacement(False)
For i = 0 to IndpValues.size-1
Set Indp = Synergy.CreateDoubleArray()
Indp.AddDouble(IndpValues.Val(i))
Set nodeID = Synergy.CreateIntegerArray()
Set Value = Synergy.CreateDoubleArray()
PlotManager.GetScalarData ResultID, Indp, nodeID, Value
UserPlot.AddScalarData IndpValues.Val(i), nodeID, Value
Next
UserPlot.Build()
MsgBox "Script Complete"
Wscript.Quit