您選取一組圖元時,可以在「應用程式介面」(API) 上將選取內容做為圖元清單使用。此清單不會排序,就像結果中的元素結果清單一樣。
以下範例會針對所選圖元,找出目前顯示之結果的最小、最大與平均值。
在執行此指令碼之前,您必須先完成以下步驟:
在以下範例中,已執行某些錯誤檢查。指令碼會檢查是否已選取圖元,以及是否存在有效的作用中出圖。
'@
'@ DESCRIPTION
'@ This command will calculate the result Minimum Maximum and Average Value
'@ of the entities selected
'@
'@ SYNTAX
'@ MinimumMaximumAverage
'@
'@ PARAMETERS
'@ none
'@
'@ DEPENDENCIES/LIMITATIONS
'@ 1. User must select a group of entities before using this command
'@ 2. User must select a result before using this command
'@ 3. Only works with nodal/elemental plots ie no vector/tensor plots
'@
'@ History
'@ Created DRA 9/8/2006
'@@
Option Explicit
SetLocale("en-us")
Dim Synergy
Set Synergy = CreateObject("Synergy.Synergy")
Synergy.SetUnits "METRIC"
Dim StudyDoc, Viewer, Plot, PlotManager
Dim EntList, ResultID, ResultType, ResultName, ResultData
Dim IndpValues, IndpValues1
Dim EntityIndex, Result, ElementNumber, NodeNumber
Dim Min, Max, Ave, Count, Value, I, J, Ent, Name
' Check that the user has selected some Entities
Set StudyDoc = Synergy.StudyDoc
Set EntList = StudyDoc.Selection
If EntList.Size <= 0 Then
MsgBox "No Entities Selected",,"Error"
WScript.Quit
End If
' Read/Check the Plot Information is correct
' Get Plot
Set Viewer = Synergy.Viewer
Set Plot = Viewer.ActivePlot()
If Plot Is Nothing Then
MsgBox "Please Select a result",,"Error"
WScript.Quit
End If
' Read Result ID Type
ResultID=Plot.GetDataID
' Read the Result Name
ResultName = Plot.GetName
' Check for Invalid Plot Data
ResultData = Plot.GetDataType
If ResultData <> "ELDT" and ResultData <> "NDDT" Then
MsgBox "Data Type Not Supported",,"Error"
WScript.Quit
End If
' Check for Invalid Plot Types
ResultType = Plot.GetPlotType
If ResultType <> "Contour Plot" Then
MsgBox "Plot Type Not Supported",,"Error"
WScript.Quit
End If
' Read the Result Data set
' Ensure we read the last data set
Set PlotManager = Synergy.PlotManager
Set IndpValues = Synergy.CreateDoubleArray()
PlotManager.GetIndpValues ResultID, IndpValues
Set IndpValues1 = Synergy.CreateDoubleArray()
IndpValues1.AddDouble(IndpValues.Val(IndpValues.Size()-1))
' Read Result Data from last set
Set EntityIndex = Synergy.CreateIntegerArray()
Set Result = Synergy.CreateDoubleArray()
PlotManager.GetScalarData ResultID, IndpValues1, EntityIndex, Result
' Calcuate the required Values
Min = 1.0E20 ' Set extremely Large Value
Max = -1.0E20 ' Set extremely Small Value
Ave = 0.0
Count= 0
' If Result in Elemental then loop through selected elements
If ResultData = "ELDT" Then
For I = 0 To EntList.Size()-1
Set Ent = EntList.Entity(I)
Name = Ent.ConvertToString
If (Left(Name,1) = "T" and Left(Name,2) <> "TE" ) Then
ElementNumber = StudyDoc.GetEntityID(Ent)
For J = 0 To EntityIndex.Size()-1
If EntityIndex.Val(J) = ElementNumber Then
Count = Count + 1
Value = Result.Val(J)
If (Value > Max) Then
Max = Value
End If
If (Value < Min) Then
Min = Value
End If
Ave = Ave + Value
End If
Next
End If
Next
' If Result in Nodal then loop through selected nodes
ElseIf ResultData = "NDDT" Then
For I = 0 To EntList.Size()-1
Set Ent = EntList.Entity(I)
Name = Ent.ConvertToString
If (Left(Name,1) = "N" ) Then
NodeNumber = StudyDoc.GetEntityID(Ent)
For J = 0 To EntityIndex.Size()-1
If EntityIndex.Val(J) = NodeNumber Then
Count = Count + 1
Value = Result.Val(J)
If (Value > Max) Then
Max = Value
End If
If (Value < Min) Then
Min = Value
End If
Ave = Ave + Value
End If
Next
End If
Next
End If
' Display Results
If Count > 0 Then
Ave = Ave / CDbl(Count)
MsgBox "Analysing result :" & ResultName & vbcrLf & _
"Number of Selected Entities is: " & Cstr(Count) & vbcrLF & _
"Minimum is: " & Cstr(Min) & vbcrLF & _
"Maximum is: " & Cstr(Max) & vbcrLF & _
"Average is: " & Cstr(Ave)
Else
MsgBox "Analysing result :" & ResultName & vbcrLf & _
"Number of Selected Entities is: " & Cstr(Count) & vbcrLF
End If
MsgBox "Script Completed"
WScript.Quit