When preparing for a presentation, publication, or time animation, it may be necessary to export all of your project files to the same file type such as GIF. Rather than opening each file and exporting it individually, the attached script can be used to export all SRF files in a specified directory to the preferred file format. The name of each exported file will match the name of the SRF. Prior to running the script, ensure the file directory and export format are set as desired in the User Variables section.
To run this script:
- Copy the script below, or download the attached BAS file: ExportAll.bas.
- In a Windows Explorer window, navigate to C:\Program Files\Golden Software\Surfer.
- Double click on Scripter.exe to launch Scripter.
- Press Ctrl+A to select all of the existing lines then press Delete.
- 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.
- Edit the file_directory on line 11 to point to the location of your files.
- Edit the export_format on line 13 to define the desired file type.
- If desired, add an options string to the export on line 34
- 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 November 2021
Please sign in to leave a comment.