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:
- Copy the script below.
- Open Grapher and turn on the Script Manager by clicking View | Display | Script Manager.
- Press Ctrl+A to select all of the existing lines in the Script Manager and then press DELETE.
- Press Ctrl+V to paste it into the Script Manager.
- 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 May 10, 2019