Description The ARNDisplayInChartChartTriplet function displays an Analysis Results Node in a plot window and returns (by reference arguments) the objects for the 3D plot and the two 2D plots. The individual 3D and 2D plots can then be fully customized by using the chart objects properties and methods. For example, a whole collection of ARNs can have their color levels programatically reset using the Chart3D objects, allowing multiple charts to use the same color level sets for comparison.
Procedure for adding the References to Chart3D and Chart2D
In the script editor, right mouse click to bring up the context menu and then choose Edit > References. From the references dialog, scroll down in the list and toggle the "ComponentOne Chart 8.0 2D Control (8.0)" and "ComponentOne Chart 8.0 3D Control (8.0)" options. Adding these references allows you dimension variables as type Chart2D and Chart3D and use the syntax tooltip helpers in the script editor to view the object's properties and methods.
If the chart 2D and 3D references cannot be added in the manner described above, it may be necessary to add them manually through the chart control *.ocx files directly. If this is required, the user should make sure that FRED is being run as an Administrator. Right mouse click in the script editor and then choose Edit > References. In the references dialog, choose the Browse button. Navigate to C:\Windows\System32 and filter for ActiveX Controls (*.ocx) files, then choose olch2x8.ocx for the 2D chart control and olch3x8.ocx for the 3D chart control. If running a 32-bit version of FRED, the *.ocx files may be located in the C:\Windows\SysWOW64 directory.
Syntax success = ARNDisplayInChartTriplet( arn, parmString, c3d, c2dx, c2dy )
Parameters success (Boolean) Return value indicating whether the chart window was successfully opened and the chart objects retrieved.
arn As Long Node number of the ARN being displayed.
parmString As String Current implementation requires at least an empty string argument. All other string entries will be ignored and default chart settings used. Future implementations will allow display options using this string argument.
c3d As Chart3D (or Object) After the function executes, this argument will be populated with the Chart3D object for the resulting plot window of the requested arn. If the function does not return True, then the c3d object will be an empty, Nothing type object.
c2dx As Chart2D (or Object) After the function executes, this argument will be populated with the Chart2D object for the X profile slice of the resulting plot window. If the function does not return True, then the c2dx object will be an empty, Nothing type object.
c2dy As Chart2D (or Object) After the function executes, this argument will be populated with the Chart2D object for the Y profile slice of the resulting plot window. If the function does not return True, then the c2dy object will be an empty, Nothing type object.
Example The example below demonstrates how the ARNDisplayInChartTriplet function can be used in a loop over all ARN in a document. The script starts by calculating three different irradiance distributions and then using a custom function to determine the minimum and maximum value ranges across all of the ARNs, from which a linear array of values spanning the min/max range is created for use as a custom level set for the resulting 3D charts. Inside of the ARNDisplayAndCustomize function we call the ARNDisplayInChartTriplet on each of the ARNs, which returns to us the 3D chart object and the two 2D chart objects. Custom functions are used to manipulate the properties of those chart objects in order to customize their visual appearance and color levels.
Sub Main
'Delete existing rays and recreate our source node ARNDeleteAllNodes() DeleteRays() CreateSources()
'Designate analysis surfaces to use for multiple irradiance analyses Dim a1 As Long, a2 As Long, a3 As Long Dim arn1 As Long, arn2 As Long, arn3 As Long a1 = FindFullName( "Analysis Surface(s).Waist" ) a2 = FindFullName( "Analysis Surface(s).Z500" ) a3 = FindFullName( "Analysis Surface(s).Z1000" ) IrradianceToARN( a1, "Waist", arn1 ) IrradianceToARN( a2, "Z500", arn2 ) IrradianceToARN( a3, "Z1000", arn3 )
'NOTE: Right mouse click, Edit > References. Add the Component One Chart 8.0 2D and Component One Chart 8.0 3D references. 'This adds the references to the Component One chart controls and allows you to access the object method and properties 'in the script editor.
'Retrieve the minimum and maximum value of all ARN. Dim dMax As Double, dMin As Double GetARNMinMax( dMin, dMax ) Print "Maximum irradiance value in ARN = " & dMax Print "Minimum irradiance value in ARN = " & dMin
'Generate a linear array of levels for the 3D charts 'so that they all use the same color scaling Dim lvls() As Double linspace( dMin, dMax, 33, lvls() )
'Now display the ARN and customize them ARNDisplayAndCustomize( lvls() )
End Sub
Function GetARNMinMax( ByRef out_min As Double, _ ByRef out_max As Double ) As Boolean
'This function loops over all of the ARN and retrieves the min/max value range 'across all ARN
'Initialize a maximum value for comparison Dim arnMax As Double, curMax As Double, curMin As Double, arnMin As Double arnMax = -1E-200 arnMin = 1E-200
'Loop over all ARN. Determine the min and max value. Dim tStats As T_ARN_2D_CELL_STATS Dim curArn As Long, arnCount As Long arnCount = ARNGetMaxNodeNum() For curArn = 0 To arnCount If ARNIsValidNode( curArn ) Then ARNCompute2DCellStatistics( curArn, tStats ) curMax = tStats.MaxCellVal curMin = tStats.MinCellVal If curMax > arnMax Then arnMax = curMax End If If curMin < arnMin Then arnMin = curMin End If End If Next
'Set the output values out_min = arnMin out_max = arnMax
Return True
End Function
Function ARNDisplayAndCustomize( ByVal in_lvls() As Double ) As Long
'Loop over all ARN. Display each ARN and then operate on the objects. Dim c3d As Chart3D Dim c2dx As Chart2D, c2dy As Chart2D Dim curArn As Long, arnCount As Long Dim cCount As Long arnCount = ARNGetMaxNodeNum() For curArn = 0 To arnCount If ARNIsValidNode( curArn ) Then
ARNDisplayInChartTriplet( curArn, "", c3d, c2dx, c2dy )
'Batch Updates c3d.IsBatched = True c2dx.IsBatched = True c2dy.IsBatched = True
Customize3DChart( c3d, in_lvls() ) Customize2DChart( c2dx, in_lvls(0), in_lvls(UBound(in_lvls)) ) Customize2DChart( c2dy, in_lvls(0), in_lvls(UBound(in_lvls)) )
'Batch Updates c3d.IsBatched = False c2dx.IsBatched = False c2dy.IsBatched = False
cCount += 1
End If Next
Return cCount
End Function
Function Customize3DChart( ByVal in_c3d As Chart3D, _ ByVal in_lvls() As Double ) As Boolean
'This function customizes a specified 3D chart object that is 'currently displayed in a plot window.
in_c3d.ChartArea.Interior.BackgroundColor = vbWhite in_c3d.ChartArea.Interior.ForegroundColor = vbBlack in_c3d.ChartArea.Axes(3).Max.IsDefault = False in_c3d.ChartArea.Axes(3).Max.Value = in_lvls( UBound(in_lvls) ) in_c3d.Legend.Interior.BackgroundColor = vbWhite in_c3d.Legend.Interior.ForegroundColor = vbBlack in_c3d.Interior.BackgroundColor = vbWhite in_c3d.Interior.ForegroundColor = vbBlack Replace3DLevels( in_c3d, in_lvls() ) in_c3d.Legend.DistributionRange = oc3dDistributionRangeAll
Return True
End Function
Function Replace3DLevels( ByVal in_obj As Chart3D, _ ByVal in_lvls() As Double ) As Boolean
'Loop over levels to delete all that exist Dim nLevels As Long, cLvl As Long Dim cVal As Double nLevels = in_obj.ChartGroups.Item(1).Contour.Levels.NumLevels
'Loop backwards and remove levels For cLvl = nLevels To 1 Step -1 cVal = in_obj.ChartGroups.Item(1).Contour.Levels.Value( cLvl ) in_obj.ChartGroups.Item(1).Contour.Levels.Remove( cVal ) Next
'Set custom level count in_obj.ChartGroups.Item(1).Contour.Levels.IsDefault = False
'Now add new levels For cLvl = 0 To UBound(in_lvls) cVal = in_lvls(cLvl) in_obj.ChartGroups.Item(1).Contour.Levels.Add( cVal ) Next
Return True
End Function
Function Customize2DChart( ByVal in_c2d As Chart2D, _ ByVal in_min As Double, _ ByVal in_max As Double ) As Boolean
'This function customizes a 2D chart object.
in_c2d.ChartArea.PlotArea.Interior.BackgroundColor = vbWhite in_c2d.ChartArea.PlotArea.Interior.ForegroundColor = vbBlack in_c2d.ChartArea.Interior.BackgroundColor = vbWhite in_c2d.ChartArea.Interior.ForegroundColor = vbBlack in_c2d.ChartArea.Axes(2).Min.IsDefault = False in_c2d.ChartArea.Axes(2).Min.Value = in_min in_c2d.ChartArea.Axes(2).Max.IsDefault = False in_c2d.ChartArea.Axes(2).Max.Value = in_max
Return True
End Function
Function linspace( ByVal in_start As Double, _ ByVal in_end As Double, _ ByVal in_nsamps As Long, _ ByRef out_vals() As Double ) As Boolean
'Get an array with linear spacing
Erase out_vals ReDim out_vals(in_nsamps-1)
Dim cind As Long Dim csamp As Double cind = 0 For csamp = in_start To in_end + 1e-10 Step (in_end - in_start)/(in_nsamps-1) out_vals( cind ) = csamp cind += 1 Next csamp
Return True
End Function
See Also
|