2.11.2 Exporting Graphs
Export GraphGraph ExportHere are three examples of exporting graphs using the X-Function expGraph called from LabTalk:
Export a Graph with Specific Width and Resolution (DPI)
Export a graph as an image using the expGraph X-Function. The image size options are stored in the nodes of tree variable named tr1, while resolution options (for all raster type images) are stored in a tree named tr2.
One common application is to export a graph to a desired image format specifying both the width of the image and the resolution. For example, consider a journal that requires, for a two-column article, that graphs be sent as high-resolution (1200 DPI), *.tif files that are 3.2 inches wide:
// Export the active graph window to D:\TestImages\TEST.TIF.
// Width = 3.2 in, Resolution = 1200 DPI
expGraph type:=tif path:="D:\TestImages" filename:="TEST"
Possible values for tr1.unit are:
- 0 = inch
- 1 = cm
- 2 = pixel
- 3 = page ratio
Note: this is a good example of accessing data stored in a tree structure to specify a particular type of output. The full documentation for tr1 can be found in the online and product (CHM) help.
Exporting All Graphs in the Project
Exporting all of the graphs from an Origin Project can be achieved by combining the doc -e command, which loops over all specified objects in a project with the expGraph X-Function.
For example, to export all graphs in the current project as a bitmap (BMP) image, as above:
doc -e P
// %H is a string register that holds the name of the active window.
expGraph type:=bmp path:="d:\TestImages" filename:=%H
Several examples of doc -e can be found in Looping Over Objects.
Exporting Graph with Path and File Name
The string registers, %G and %X, hold the current project file name and path. Combine with the label command, you can place these information on page while exporting a graph. For example:
// Path of the project
string proPath$ = system.path.program$ + "Samples\Graphing\Multi-Curve Graphs.opj";
// Open the project
doc -o %(proPath$);
// Add file path and name to graph
win -a Graph1;
label -s -px 0 0 -n ForPrintOnly \v(%X%G.opj);
// Export graph to disk D
expGraph type:=png filename:=%H path:=D:\;
// Delete the file path and name
label -r ForPrintOnly;