This article contains a sample script for printing multiple graphs from a single template using all data files in a specified directory. Also shows how to export the graph to a GIF file and how to add to the plot the date/time the graph was created.
To run this script:
- Click here to download the BAS file: print from directory.bas.
- Open Grapher and turn on the Script Manager by clicking View | Display | Script Manager.
- Click the Open () icon in the Script Manager, select the downloaded script, and click Open.
- Edit the Directory on line 19 to the directory that contains all of your Grapher files.
- Click Automation | Scripts | Run.
OR:
- 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.
- Edit the Directory on line 19 to the directory that contains all of your Grapher files.
- Click the Start/Resume icon () in the Script Manager.
*********
'PRINT FROM DIRECTORY.BAS 'This script prints multiple graphs using a graph template and several data files. 'Modify the paths in the script to match your template file path and data file path. 'Also exports to a GIF with the DAT name Sub Main 'Create Grapher as an object Dim Grapher As Object 'Start Grapher Set Grapher = CreateObject("Grapher.Application") 'Remove quote from the following line to make Grapher visible Grapher.Visible(1) 'Open Grapher's Open dialog box '*******Change Directory to directory where DAT files are located******** Directory = Grapher.Path+"\Samples\" file$ = Dir$(Directory + "*.dat") '*******Change the Template to the name and location where the GRT file is located********** Template = Grapher.Path+"\Templates\line scatter plot.grt" While file$ <> "" 'Open the file in the directory in order Set doc = Grapher.Documents.Add(grfPlotDoc,Template,Directory+file$) 'Create text with new date Set Text1 = doc.Shapes.AddText(0.5, 0.5, "<<mmmm dd, yyyy>> at <<hh:nn>> PDT") 'Export to same named GIF doc.Export(Directory+Left(file$,Len(file$)-3)+"gif") 'Close the plot window doc.Close(grfSaveChangesNo) 'Open the next file file$ = Dir$() Wend 'Close Grapher Grapher.Quit() End Sub
Updated August 13, 2019
Comments
Please sign in to leave a comment.