Saving Charts to Image Files
Saving a displayed chart window to an image file through scripting can be facilitated through the use of Analysis Results Nodes (ARNs) and the ARNDisplayInChartTriplet() function. The ARNDisplayInChartChartTriplet function displays an Analysis Results Node in a plot window and returns (by reference arguments) the chart control objects for the 3D plot and the two 2D profile plots. The individual 3D and 2D plots can then be fully customized by using the chart objects properties and methods. Among the methods available in the chart objects are a collection of commands to save the displayed chart to a number of different image file formats. Please refer to the ARNDisplayInChartTriplet Help topic within FRED for more detailed information about this script command and its usage.
If the chart control objects are desired to be used in a script, you must first load the references to the chart control libraries in the FRED script editor. This can be done in the following way:
- 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 chart object 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.
Now, lets assume that an Analysis Results Node (ARN) has been created and it's node number on the tree is stored in a variable called "arn". This can be done by using, for example, IrradianceToARN(), ColorImageToARN, EnergyDensityToARN, etc. The following script code will display the ARN in the chart window and then call methods from the Chart2D and Chart3D objects that write the displayed chart to image files.
'Directory that image files will be written to Dim baseDir As String baseDir = GetDocDir() & "\" 'Use the chart objects to write image files Dim c3d As Chart3D, c2dx As Chart2D, c2dy As Chart2D ARNDisplayInChartTriplet( arn, "", c3d, c2dx, c2dy ) c3d.SaveImageAsJpeg( baseDir & "Irradiance.jpg", 100, 0, 1, 1 ) c3d.SaveImageAsPng( baseDir & "Irradiance.png", 0 ) c2dx.SaveImageAsPng( baseDir & "Irradiance_X.png", 0 ) c2dy.SaveImageAsPng( baseDir & "Irradiance_Y.png", 0 ) Print "Finished writing image files for the irradiance plot."<br>