1 組のエンティティを選択したときに、アプリケーション プログラミング インターフェース (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