Open an existing SRF file, replace the grid file for the contour map, and save to a new name in Surfer Scripter

If you have an existing SRF file with a contour map and you just want to change out the grid file and save to a new file, you can use the script below to do it.

To run this script:

  1. Copy the script below, or download the attached BAS file: ChangeGRDForContourLayer.BAS.
  2. In a Windows Explorer window, navigate to C:\Program Files\Golden Software\Surfer.
  3. Double click on Scripter.exe to launch Scripter.
  4. Press Ctrl+A to select all of the existing lines then press DELETE.
  5. If you copied this script, press Ctrl+V to paste it into Scripter. If you downloaded it, click File | Open, select the BAS file from your downloads directory, and click Open.
  6. Click Script | Run to run the script.

Sub Main

	'Initializes Surfer
	Dim SurferApp, Docs, Plot, Overlays, ContourLayer As Object
	Set SurferApp = CreateObject("Surfer.Application")
	SurferApp.Visible = True
	Set Docs = SurferApp.Documents

	'User Defined Variables
	'File path
	FilePath$ = "c:\users\leslie\desktop\"

	'Project file name (without file extension)
	SRFFile$ = "Contours"

	'Grid file name and extension (.grd, .asc, etc.)
	GRDFile$ = "Colorado"
	GRDExt$ = ".grd"

	'Map to use in the project. Can use numbers (1 is bottom object in Contents window) or name
	mapnum = 2   'or mapum="Map"

	'Layer to use in the map. Can use numbers (1 is bottom layer in map in Contents window) or name
	layernum=1   'or mapum="Contours-demogrid.grd"
	'Opens the original SRF file
	Set Plot = Docs.Open(FileName:=FilePath$+SRFFile$+".srf")

	'Assigns the contour map layer to the variable named "ContourLayer"
	Set ContourLayer = Plot.Shapes.Item(mapnum).Overlays.Item(layernum)

	'Changes the grid file for the contour layer to a different GRD file

	'Loops through the axes to change the tick scaling to automatic
	For i=1 To 4

	'Saves the SRF file to a new name
End Sub

Updated November 8, 2018

Was this article helpful?
3 out of 4 found this helpful



Please sign in to leave a comment.