Description Analysis plot windows can contain both 2D and 3D plots. The irradiance spread function, for example, will result in a main 3D plot showing the energy distribution and two 2D plots that show the X and Y profiles slices. Additionally, multiple calls to the irradiance spread function analysis will result in multiple plot windows. If, for example, you called the Irradiance Spread Function twice, there would be two plot windows with a total of two 3D plots and four 2D plots. The Get3DChartTriplet function can retrieve the single 3D plot and two 2D plots from a plot window, which allows you to customize all aspects of those charts through the objects' properties and methods.
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 n3d = Get3DChartTriplet( cNum, c3d, c2d1, c2d2 )
Parameters n3d (Long) Return value indicating the number of available 3D charts whose objects could be retrieved.
cNum As Long This argument indicates the ID of the 3D chart whose object is being retrieved. The chart ID's correspond to the order in which they were displayed in FRED, but there is no way to unambiguously know which chart is being accessed. Typical usage, however, would be to iterate over all currently displayed charts or to retrieve a chart object when only one plot window is displayed.
c3d As Chart3D (or Object) After the function executes, this argument will be populated with the Chart3D object for the requested plot. If the cNum argument provided does not correspond to a 3D plot, then the c3d object will be an empty, Nothing type object.
c2d1 As Chart2D (or Object) After the function executes, this argument will be populated with the first associated Chart2D object of the requested 3D plot. For most analyses (ex. irradiance), this will be the X-profile slice. If the cNum argument provided does not correspond to a 3D plot, then the c2d1 object will be an empty, Nothing type object.
c2d2 As Chart2D (or Object) After the function executes, this argument will be populated with the first associated Chart2D object of the requested 3D plot. For most analyses (ex. irradiance), this will be the Y-profile slice. If the cNum argument provided does not correspond to a 3D plot, then the c2d2 object will be an empty, Nothing type object.
Example The example below shows a case where three irradiance spread function analysis windows are displayed, resulting in three 3D plots and six 2D profile plots. First, a custom function is used to iterate over the open 3D plots and retrieve the minimum and maximum data values. Next, a custom function called CustomizeOpen3DCharts is called that iterates over the open 3D plots and resets them all to use the same color level scaling (it also sets a few other color properties). The CustomizeOpen3DCharts makes use of some helper functions to generate a linear array of values and add/remove existing color levels. Lastly, the example iterates over all open 2D chart windows and resets their data ranges to the same min/max as the 3D plots.
Sub Main
'Delete existing rays and recreate our source node DeleteRays() CreateSources()
'Designate analysis surfaces to use for multiple irradiance analyses Dim a1 As Long, a2 As Long, a3 As Long a1 = FindFullName( "Analysis Surface(s).Waist" ) a2 = FindFullName( "Analysis Surface(s).Z500" ) a3 = FindFullName( "Analysis Surface(s).Z1000" ) IrradianceToFileAS( a1, "" ) IrradianceToFileAS( a2, "" ) IrradianceToFileAS( a3, "" )
'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 open 3D plots. Dim dMax As Double, dMin As Double Get3DChartMinMax( dMin, dMax ) Print "Maximum irradiance value in 3D plots = " & dMax Print "Minimum irradiance value in 3D plots = " & dMin
'Customize the look, set the z data max of all open 3D plots, and put all plots on the same color level profile. CustomizeOpen3DCharts( dMin, dMax, 33 ) Customize2DCharts( dMin, dMax )
End Sub
Function Get3DChartMinMax( ByRef out_min As Double, _ ByRef out_max As Double ) As Boolean
'This function loops over all of the open 3D chart windows and retrieves 'the minimum and maximum value.
'Initialize a maximum value for comparison Dim max3D As Double, curMax As Double, curMin As Double, min3D As Double max3D = -1E-200 min3D = 1E-200
'Loop over all open 3D charts. When the chart object becomes Nothing, 'then we have no more 3D charts. 'Determine the min and max value of the open 3D charts. Dim cur3D As Long, n3d As Long Dim c3d As Chart3D, c2d1 As Chart2D, c2d2 As Chart2D cur3D = 0 n3d = Get3DChartTriplet( cur3D, c3d, c2d1, c2d2 ) Print "n3d = " & n3d While Not (c3d Is Nothing) curMax = c3d.ChartArea.Axes(3).Max curMin = c3d.ChartArea.Axes(3).Min If curMax > max3D Then max3D = curMax End If If curMin < min3D Then min3D = curMin End If cur3D += 1 Get3DChartTriplet( cur3D, c3d, c2d1, c2d2 ) Wend
'Set the output values out_min = min3D out_max = max3D
Return True
End Function
Function CustomizeOpen3DCharts( ByVal in_dMin As Double, _ ByVal in_dMax As Double, _ ByVal in_nlevels As Long ) As Long
'This function loops over all of the open 3D chart windows, customizes 'each plot to use a common min/max range.
'Loop over all open 3D charts. When the chart object becomes Nothing, 'then we have no more 3D charts. Dim cur3D As Long, n3d As Long Dim c3d As Chart3D, c2d1 As Chart2D, c2d2 As Chart2D cur3D = 0 n3d = Get3DChartTriplet( cur3D, c3d, c2d1, c2d2 ) While Not (c3d Is Nothing)
c3d.ChartArea.Interior.BackgroundColor = vbWhite c3d.ChartArea.Interior.ForegroundColor = vbBlack c3d.ChartArea.Axes(3).Max.IsDefault = False c3d.ChartArea.Axes(3).Max.Value = in_dMax c3d.Legend.Interior.BackgroundColor = vbWhite c3d.Legend.Interior.ForegroundColor = vbBlack c3d.Interior.BackgroundColor = vbWhite c3d.Interior.ForegroundColor = vbBlack Set3DLevelRange( in_dMin, in_dMax, in_nlevels ) c3d.Legend.DistributionRange = oc3dDistributionRangeAll
cur3D += 1 Get3DChartTriplet( cur3D, c3d, c2d1, c2d2 )
Wend
'The number of 3D charts that were modified Return cur3D
End Function
Function Set3DLevelRange( ByVal in_min As Double, _ ByVal in_max As Double, _ ByVal in_levels As Long ) As Boolean
'This function loops over all of the open 3D chart windows and...
'Get an array of level values Dim lvls() As Double linspace( in_min, in_max, in_levels, lvls() )
'Loop over all open 3D charts. When the chart object becomes Nothing, 'then we have no more 3D charts. 'Determine the max value of the open 3D charts. Dim cur3D As Long, n3d As Long Dim c3d As Chart3D, c2d1 As Chart2D, c2d2 As Chart2D cur3D = 0 n3d = Get3DChartTriplet( cur3D, c3d, c2d1, c2d2 ) While Not (c3d Is Nothing)
Replace3DLevels( c3d, lvls() )
cur3D += 1 Get3DChartTriplet( cur3D, c3d, c2d1, c2d2 ) Wend
'Return the maximum value found 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 Customize2DCharts( ByVal in_min As Double, _ ByVal in_max As Double ) As Long
'This function loops over all of the open 2D chart windows, customizes 'each plot and sets the Y range.
'Loop over all open 2D charts. When the chart object becomes Nothing, 'then we have no more 2D charts. Dim cur2D As Long Dim c2d As Chart2D cur2D = 0 Get2DChart( cur2D, c2d ) While Not (c2d Is Nothing)
c2d.ChartArea.PlotArea.Interior.BackgroundColor = vbWhite c2d.ChartArea.PlotArea.Interior.ForegroundColor = vbBlack c2d.ChartArea.Interior.BackgroundColor = vbWhite c2d.ChartArea.Interior.ForegroundColor = vbBlack c2d.ChartArea.Axes(2).Min.IsDefault = False c2d.ChartArea.Axes(2).Min.Value = in_min c2d.ChartArea.Axes(2).Max.IsDefault = False c2d.ChartArea.Axes(2).Max.Value = in_max
cur2D += 1 Get2DChart( cur2D, c2d )
Wend
'The number of 2D charts that were modified Return cur2D
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
|