Export only selected objects using Surfer automation

In order to export only a specific map, layer, or object in your project, you must first select it.  The selected objects only feature can then be used to generate the desired output.  In the example script below a SRF file is opened, the first map item is selected, and the selected map is exported to JPG.

To run this script:

  1. Copy the script below, or download the attached BAS file: ExportSelectedOnly.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. Edit the Export File path on line 10 as desired.
  7. Click Script | Run to run the script.


'ExportSelectedOnly.bas opens a selected SRF file,
'selects a map, and exports the single map to the
'specified export file.

Sub Main
    Dim SurferApp As Object
    Set SurferApp = CreateObject("Surfer.Application")
    SurferApp.Visible = True
    ExportFile = "C:\temp\test.jpg"
	SRFfilepath = GetFilePath( , "srf",SurferApp.Path+"\samples\","Open SRF File",0)

'Opens the SRF file
    Dim Plot As Object
	Set Plot = SurferApp.Documents.Open(SRFfilepath)

'Assigns the map in the SRF file to the variable "MapFrame1"
'You may need to change the Index number so that the map in the SRF file is selected.
	Dim MapFrame1 As Object
	Set MapFrame1 = Plot.Shapes.Item(1)

'Selects the map

'Exports the selected objects only to the specified ExportFile path
	Plot.Export(FileName:=ExportFile, SelectionOnly:=True)
End Sub


Updated November 2021

Was this article helpful?
0 out of 0 found this helpful



Please sign in to leave a comment.