Follow

How can I export multiple SRF files to bitmap images using Surfer automation?

This article contains a sample script for exporting all SRF files in a given directory to a GIF file.

To run this script:

  1. Copy the script below, or download the attached BAS file: ExportAll.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

'Opens all SRF file in directory
'Exports each to GIF
Debug.Clear

''''''''''''' User Variables ''''''''''''''''''

file_extension	= "srf"

file_directory	= "C:\temp\grids\"

export_format = "gif"

'''''''''''''''''''''''''''''''''''''''''''''''
	Set surf = CreateObject("surfer.application")
	surf.Visible = True
	Debug.Print surf.Version

	file_extension	= LCase(Right(file_extension,(Len(file_extension) - InStrRev(file_extension,"."))))
	If  Len(file_directory)-InStrRev(file_directory,"\") <> 0 Then file_directory = file_directory + "\"

	srf_file = Dir( file_directory  + "*." + file_extension)

	On Error GoTo FileError
	While srf_file <> ""
		'Define output grid file directory & name
		export_file	= file_directory + Left(srf_file, Len(srf_file)-(Len(srf_file)-InStrRev(srf_file,".")+1) ) + "." + export_format

		'Declares Plot As an Object And opens an SRF file
   		Dim Plot As Object
		Set Plot = surf.Documents.Open(file_directory + srf_file)
		'surf.plot.Export(export_file)
		Plot.Export2(export_file, filterid:=export_format)

		Debug.Print srf_file
		srf_file = Dir() 'get next file
	Wend

	surf.Quit
	Exit Sub

	'Print a meaningful error message for each file that did not grid correctly
	FileError:
	Debug.Print  "Error:	" + srf_file + "						" + Err.Description
	Resume Next

End Sub

 

Updated October 11, 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.