개체 세트를 선택할 때에는 API(응용 프로그래밍 인터페이스)를 통해 개체 목록으로 선택할 수 있습니다. 이 목록은 요소 결과 목록처럼 결과에서 정렬되어 있지 않습니다.
다음 예제에서는 선택한 개체에 대해 현재 표시된 결과의 최소, 최대 및 평균 값을 찾아봅니다.
이 스크립트를 실행하기 전에 먼저 다음 단계를 완료하십시오.
다음 예제에서는 일부 오류 검사도 이행했습니다. 스크립트가 개체가 선택되었는지, 유효하고 활성화된 플롯이 있는지 확인합니다.
'%RunPerInstance
'@
'@ 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 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 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