Grapher introduced basic scripting abilities when Grapher 2 was released in 1998. Since then, the scripting abilities have become stronger and more functional. Now, all features that you manually do in Grapher can be done through a script. Since the release of Grapher 7, you have had the ability to have Grapher record the script for you as you do the desired steps.
Recording a script to create a new graph
Open Grapher and make sure that you are working in a blank plot window. If you have anything present on the plot window, click File | New | Plot. A new, blank plot window is displayed. Click Automation | Scripts | Record. The Script Recorder is now recording your steps. We will create a graph and edit the properties of various elements.
- Click Home | New Graph | Basic | Line Plot.
- Select the data file you wish to use, such as Tutorial.dat, located in the Samples folder and click Open. The graph is created.
- With the line/scatter plot selected, change some of the properties in the property inspector. You can change the line, fill, clipping, or any other properties you wish.
- After you have made all of the changes to the line/scatter plot, continue making changes to the axes, graph, or by adding drawn objects such as text, polygons, etc.
- Click Automation | Scripts | Stop to stop the recording process.
- In the Save As dialog, type in the name that you want to use to save the script and click the Save button.
- The script has now been saved and can be used to make a new graph in the future. To view the script in the Script Manager window, check the View | Display | Script Manager option. The Script Manager will open and the sample script you just recorded will be shown.
Recording a script to alter an existing graph
After a script has been created, either by typing in the various commands in a Scripter window or recording the commands, the script can be used over and over again to create the same graph. This is not always the desired result from recording a script. Occasionally, you may want to make changes to existing graphs. These steps can also be recorded, but you will need to do some editing after the script has finished recording.
- Open Grapher and click File | Open.
- Select the GRF file that you want to edit and click the Open button.
- Choose Automation | Scripts | Record. The Script Recorder is now recording your steps. Click on the desired portion of the graph to edit. For instance, you may want to add clipping or 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.
- After you have made all of the desired changes, click Automation | Scripts | Stop to stop the recording process.
- In the Save As dialog, click the Cancel button. This will not save the script, but will display it in the Script Manager.
- Click in the Script Manager. We will now make a few edits so that the script will be used on existing open graphs in the future. Scroll to the top of the script. You will find these lines:
'Create a new document window Set Plot1 = Grapher.Documents.Add(grfPlotDoc)
Change the second line to:
'Create a new document window Set Plot1 = Grapher.Documents.Active
- If you added a plot or text that uses a specific worksheet or added grid lines, plot labels, or anything else that specifies a worksheet, you may need to make changes to this line, as well.
- 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 Grapher GRF file.
- Right-click in the Script Manager, and click File | Open.
- In the Open dialog, select any desired script file (extension BAS) and click the Open button. The script will be displayed.
- Right-click in the Script Manager, and choose Macro | Run or click the Automation | Scripts | Run command. The script will begin. The script should create/alter the graph as directed in the script.
Opening and running an existing script
After the script is recorded, it can be used at any time in the future. To do so, verify that the Script Manager is open. You can verify this by ensuring the Automation | Script Manager | View Script Manager box is checked (or the View | Display | Script Manager). If there is a check next to View Script Manager (or Script Manager), then the window should be open at the bottom of the screen, by default.
Scripts recorded in the Script Recorder can also be opened in the Golden Software Scripter program or any VB-like programming environment. To open the Scripter program, click on the Windows Start button and click on Programs. Find the Golden Software Grapher 15 (or Grapher Preview) folder and click on the Scripter link. The Scripter program will open. Scripter is a separate program and can be run without a visible Grapher window.
For free sample scripts, please go to our Grapher scripts download page.
Updated August 13, 2019
Comments
Please sign in to leave a comment.