Writing Scripts

To create a script, you must type the script text into the Scripter code window, or edit an existing script. When you want to create a new script that is specific for your circumstances, you will most likely start with an empty Scripter window and type the entire script. If you want to perform a routine task such as creating a grid file or a contour map, you can probably open an existing script file and edit the file to meet you specific needs. Surfer comes with several sample scripts that you can modify as desired.

Consider a script that creates a grid file from an XYZ data file, and then creates a contour map from the grid file:

Sub Main

' Create a programmable object to represent the Surfer program

Set SurferApp = CreateObject("Surfer.Application")

' Make the Surfer window visible

SurferApp.Visible = True

' Add a new plot document

Set plot = SurferApp.Documents.Add

' Prompt for name of the data file

DataFile$ = GetFilePath$()

' Invoke the Surfer Grid Data command.

SurferApp.GridData DataFile := DataFile$, OutGrid := "out.grd", ShowReport := False

' Invoke the AddContour map method.

' The AddContourMap method is a member of the Shapes collection object.

' The Shapes collection object, in turn, is one of the

' properties of the plot document object.

plot.Shapes.AddContourMap "out.grd"

End Sub

When you execute the script, Surfer is automatically started and a plot window is displayed. The grid file is created (the progress of the operation is indicated on the Surfer status bar), and the contour map is drawn in the plot window. When the script execution is complete, you are returned to the Scripter window. The Surfer window remains open, although the Scripter window is the active window.

Writing comments in your scripts to explain how they work can save you time and frustration when you later need to modify the script. The apostrophe character (') signals the start of a comment.

See Also


Subroutines and Functions