Navigation: Scripting Reference Manual > Functions & Subroutines > Get2DChart

 

Get2DChart

 

Contact Us: fredsupport@photonengr.com

 

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 Get2DChart function can retrieve any of the currently displayed 2D charts as objects, which allows you to customize all aspects of a chart through the object's 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

nCharts = Get2DChart( cNum, c2d )

 

 

Parameters

nCharts (Long)

Return value indicating the number of available 2D charts whose objects could be retrieved.

 

cNum As Long

This argument indicates the ID of the 2D 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.

 

c2d As Chart2D (or Object)

After the function executes, this argument will be populated with the Chart2D object for the requested plot.  If the cNum argument provided does not correspond to a 2D plot, then the c2d 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 6 2D profile plots.  A custom function, Get2DChartMax, is called that iterates over all open 2D plots and returns the maximum irradiance value from those plots.  Then, another custom function, CustomizeOpen2DCharts, is called that iterates over the open plots and sets them all to use the Y-scale and customizes some colors and plot titles.

 

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 maximum value of all open 2D plots.

    Dim dMax As Double

    dMax = Get2DChartMax()

    Print "Maximum irradiance value in 2D profiles = " & dMax

 

    'Customize the look and set the y-scale of all open 2D plots.

    CustomizeOpen2DCharts( dMax, Array("Waist", "Waist", "Z500", "Z500", "Z1000", "Z1000" ) )

 

 

End Sub

 

Function Get2DChartMax() As Double

 

    'This function loops over all of the open 2D chart windows and retrieves

    'the maximum value.

 

    'Initialize a maximum value for comparison

    Dim max2D As Double, curMax As Double

    max2D = -1E-200

 

    'Loop over all open 2D charts.  When the chart object becomes Nothing,

    'then we have no more 2D charts.

    'Determine the max value of the open 2D charts.

    Dim cur2D As Long

    Dim c2d As Chart2D

    cur2D = 0

    Get2DChart( cur2D, c2d )

    While Not (c2d Is Nothing)

        curMax = c2d.ChartArea.Axes(2).DataMax

        If curMax > max2D Then

            max2D = curMax

        End If

        cur2D += 1

        Get2DChart( cur2D, c2d )

    Wend

 

    'Return the maximum value found

    Return max2D

 

End Function

 

Function CustomizeOpen2DCharts( ByVal in_peak As Double, _

                                ByVal in_titles() ) As Long

 

    'This function loops over all of the open 2D chart windows, customizes

    'each plot and sets the maximum Y-scale.

 

    '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).Max.IsDefault             = False

        c2d.ChartArea.Axes(2).Max.Value                 = in_peak

        c2d.Header.text                                 = in_titles(cur2D)

        c2d.Header.IsShowing                            = True

        c2d.Header.Interior.BackgroundColor             = vbWhite

        c2d.Header.Interior.ForegroundColor             = vbBlack

        c2d.Header.Location.Left                        = 130

        c2d.Header.Location.Top                         = 30

 

        cur2D += 1

        Get2DChart( cur2D, c2d )

 

    Wend

 

    'The number of 2D charts that were modified

    Return cur2D

 

End Function

 

 

See Also

Chart Scripting Commands

 

 

 

 

 

Copyright © Photon Engineering, LLC