|
Grapher: Creating a Script
using the Script Recorder
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. With the release
of Grapher 7, you now have 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 7 and make sure that you are working in a
blank plot window. If you have anything present on the plot window, choose File
| New. In the New window, select Plot and click OK. A new, blank plot window
is displayed. Choose Edit | Script Recorder | Record or
click on the button. The Script Recorder is now recording your steps.
We will create a graph and edit the properties of various elements.
- Choose
Graph | 2D Graphs | Line/Scatter.
- Select
the data file you wish to use, such as sample3.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.
- Choose Edit | Script Recorder | Stop or
click the
button 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.
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.
To view the script in the Script Manager window, choose View | Toolbars/Managers | Script Manager.
The Script Manager window will open and the sample script you just recorded will be shown.
The Script Manager window is shown with the sample script.
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 7 and choose File | Open.
- Select the GRF file that you want to edit and click the Open button.
- Choose Edit | Script Recorder | Record or click on
the
button. 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, choose Edit | Script Recorder | Stop
or click the
button 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 window.
- Click in the Script Manager window. 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 window and choose File | Save. 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.
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 window is open. You can verify this by
choosing View | Toolbars/Managers | Script Manager. If there is a check next to Script
Manager, then the window should be open at the bottom of the screen.
- Click on the Script Manager tab to view the Script Manager window.
- Right-click in the Script Manager window and choose 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 window and choose Macro | Run or click
the
button. The script will begin. The script should create/alter the graph as directed in the script.
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 (or All Programs). Find the Golden Software Grapher 7 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 Grapher Script Page.
|