Export multiple graphs in a Plot Document to separate files in Grapher Automation

This article contains a sample script for looping through multiple graphs in a single project's plot document and exporting each graph individually.

 

To run this script:

  1. Copy the script below.
  2. Open Grapher and turn on the Script Manager by clicking View | Display | Script Manager.
  3. Press Ctrl+A to select all of the existing lines in the Script Manager and then press DELETE.
  4. Press Ctrl+V to paste it into the Script Manager.
  5. Click the green arrow Start/Resume icon in the Script Manager. 

Sub Main

'Initializes Grapher
Dim Grapher As Object
Set Grapher = CreateObject("Grapher.Application")
Grapher.Visible = True

'================================
'User-defined variables
'================================
inpath$ = Grapher.Path+"\Samples\"
filename$ = "BarCharts.gpj"
outpath$ = "C:\temp\"
'================================

'Open an existing document
Set PlotDoc = Grapher.Documents.Open(inpath$+filename$)

'Loop through graphs, selecting and exporting each individually
For i=1 To PlotDoc.Shapes.Count
	PlotDoc.Shapes.Item(i).Select
	graphname = PlotDoc.Shapes.Item(i).Name
	PlotDoc.Export2(outpath$+graphname+".jpg",True,"HDPI=200",True,"jpg")
	PlotDoc.Selection.DeselectAll
	Debug.Print i
Next
Debug.Print "Done"

End Sub

 

Updated March 2020

Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.