Follow

How can I use a script to open an existing Surfer file, change out the grid file for the contour map, and save to a new name?

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 15\Scripter.
  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

	'========================================
	'User Defined Variables
	'========================================
	FilePath$ = SurferApp.Path+"\Samples\
	SRFFile$ = "Axes.srf"
	GRDFile$ = "demogrid.grd"
	OutFile$ = "Axes_demogrid.srf"
	mapnum = 1 'If there are more than one map in the project, specify which map to choose.
	'Either use numbers where 1 is the bottom map in the Contents window, or use the entire map name in double quotes (i.e. "Map")
	layernum=1 'If there are more than one layer in the map, specify which layer to choose. 1 is the bottom layer in the map in the Contents window.
	'Either use numbers where 1 is the bottom map in the Contents window, or use the entire map name in double quotes (i.e. "Contours-demogrid.grd")
	'========================================

	'Assigns the Documents collection to the variable named "Docs"
	Set Docs = SurferApp.Documents

	'Opens the original SRF file and assigns the plot document to the variable named "Plot"
	Set Plot = Docs.Open(FileName:=FilePath$+SRFFile$)

	'Assigns the Contours 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
	ContourLayer.GridFile=FilePath$+GRDFile$

	'Saves the SRF file to a new name
	Plot.SaveAs(FileName:=FilePath$+OutFile$)

End Sub

Updated September 13, 2017

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.