2.3.4 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)