Creating a Script using Grapher's Script Recorder

Grapher has come a long way since introducing basic scripting in 1998 with Grapher 2! Over the years, its automation capabilities have grown stronger, allowing you to script virtually anything you can do manually in the software. But what if you’re new to scripting or just want to save time? That’s where the Script Recorder comes in! Introduced in Grapher 7, this handy tool records your actions as you perform them—just like having Grapher take notes for you. Once recorded, you can replay the script to automate repetitive tasks, troubleshoot syntax issues, or fine-tune your workflow without manually writing every command.

Simply click the Automation | Scripts | Record command to start recording. If you want to watch your script unfold in real time, check the View | Display | Script Manager option. Just remember to stop recording before making edits!

 

Let's walk through some examples below! 

Create a new graph with a line plot

    1. Click the View | Display | Script Manager to display the Script Manager window. 
    2. Click the Automation | Scripts | Record command to start recording.
    3. Click File | New | Plot to open a new plot document.
    4. Click Home | New Graph | Line/Scatter | Line Plot to open the Open Worksheet dialog.
    5. Navigate to and select the sample file located at
      C:\Program Files\Golden Software\Grapher\Samples\Tutorial.dat. 
    6. Click Open.

      The graph is created. Now let's edit some plot and axis properties! 

    7. Select the new line plot under Graph 1 in the Object Manager and change some plot properties in the Property Manager. Choose any properties you wish! 
    8. Select the X or Y axis in the Object Manager and change some of those properties too. 

      Once you're done editing the properties, stop recording and save your script for future use.

    9. Click Automation | Scripts | Stop Recording to stop the recording process.
    10. The Save As dialog will appear once you stop recording. Enter your desired script name and then click Save.

      grapher_script_saveas.png
      In the Save As dialog, type in the desired File name and click the Save button to save the script.

      The script has now been saved and can be used to make a new graph in the future.

Alter an existing graph

Occasionally, you may want to make routine changes to existing GRF files. These steps can also be recorded, but you will need to do some editing to the recorded script to ensure that it can be applied to other GRF files. 

    1. Open Grapher and click File | Open.
    2. Select the GRF file that you want to edit and click Open.
    3. Click the View | Display | Script Manager to display the Script Manager window.
    4. Click Automation | Scripts | Record.

      The Script Recorder is now recording your steps.

    5. Click on the portion of the graph that you want to change and start editing. For example, you may want to change the fill color for a plot, or you may wish to change the tick marks or tick labels for an axis. You can also add new items to the graph, such as text, drawn objects, or additional plots.
    6. After you have made all of the desired changes, click Automation | Scripts | Stop to stop the recording process.
    7. In the Save As dialog, you can either save your script now or click Cancel.

      Let's edit the script so that it can be used on any graph in the future (as long as the graph has similar properties). 

    8. In the Script Manager window, scroll to the top of the script and locate the lines that look similar to this:
      'Create a new document window
      Set Plot1_doc = Grapher.Documents.Add(grfPlotDoc)
    9. Change Grapher.Documents.Add(grfPlotDoc) to Grapher.Documents.Active 
      'Create a new document window
      Set Plot1_doc = Grapher.Documents.Active
    10. If your script includes a plot or text linked to a specific worksheet, or if you've added grid lines, plot labels, or other worksheet-dependent elements, you may also need to update those lines accordingly.
    11. Right-click in the Script Manager, and click File | Save As. In the Save As dialog, type in the new File name and click the Save button. The script can now be used with any open GRF file.

Opening and running an existing script

After the script is recorded, it can be used at any time in the future. You can open an existing script within Grapher's Script Manager like so: 

  1. Right-click in the Script Manager, and click File | Open. Alternatively, you can click on the Open button in the Script Manager's tool bar. 
  2. In the Open dialog, select any desired script file (with a BAS extension) and click the Open button. The script will be displayed.
  3. Right-click in the Script Manager, and click Macro | Run or click the Automation | Scripts | Run command. Alternatively, you can click on the Start/Resume button in the Script Manager's tool bar. 

Scripts can also be opened in the Golden Software Scripter program or any VB-like programming environment. 

 

Additional Resources:

Where can I find Grapher script examples?

Debugging Scripts

 

Updated January, 2025

Was this article helpful?

Comments

0 comments

Please sign in to leave a comment.