3.3.6 Exporting Graphs

Introduction

In this example, we call X function expGraph in Python to export all graphs in the project to the User Files Folder. We use PyOrigin.XF to call the X-function in Python. Note that XF method requires Origin 2016 or later.

Examples

# This PyOrigin example will import export all the graph pages to a PNG file.
import os
import sys
import PyOrigin

# Define a function to export all graphs in the current project.
def expAllGraphs():
	# Check how many graph pages the current project has.
	if PyOrigin.GraphPages().GetCount() > 0:
		# Loop for each graph page.
		for graph in PyOrigin.GraphPages():
			print('Exporting', graph.GetName())
		PyOrigin.XF('expGraph', {'type':'png','export':'project','overwrite':'rename', 'filename':'<short name>', 'tr1.unit':2, 'tr1.width':600})
	else:
		print('There are no graphs to export.')


if __name__ == '__main__':
	if len(sys.argv) > 1:
		option = sys.argv[1]
	else:
		option = ''
	if option == 'export':
		expAllGraphs()
	elif option == 'folder':
		userFilesFolder = PyOrigin.GetPath(PyOrigin.PATHTYPE_USER)
		os.startfile(userFilesFolder)

To run this sample:

  1. Open Code Builder.
  2. Create a new Python file in the User Files Folder, like test1.py
  3. After putting in the code above and save the file test1.py, open the script window.

To save graph(s) to User Files Folder, please execute:

run -pyf test1.py export;

To open the User Files Folder to see exported graph(s), please execute:

run -pyf test1.py folder;