Copy a map into a new plot document via Surfer automation

One of the most common methods to cut down on work when preparing multiple maps or models is to re-use content.  This same practice can be used in automation.  To copy a map from one document to another for use as the start of a new model, see the sample script below.

To run this script:

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


'CopyPasteMaps.bas shows how to copy a map from one
'plot document window and paste into another.

Sub Main

'Declare the variable that will reference the application
	Dim SurferApp As Object
	Set SurferApp = CreateObject("Surfer.Application")
	SurferApp.Visible = True

'Declares Plot as an object
	Dim Plot As Object
	Set Plot = SurferApp.Documents.Add

'Creates a contour map and assigns the map frame to the variable "MapFrame"
	Set MapFrame1 = Plot.Shapes.AddContourMap(GridFileName:=SurferApp.Path+"\samples\demogrid.grd")

'Selects MapFrame 1

'Copies the selection

'Declares Plot as an object
	Dim Plot2 As Object
	Set Plot2 = SurferApp.Documents.Add

'Creates a contour map and assigns the map frame to the variable "MapFrame"
	Set MapFrame2 = Plot2.Shapes.AddContourMap(GridFileName:=SurferApp.Path+"\samples\demogrid.grd")

'Positions MapFrame2 on the page
	MapFrame2.Left = 1
	MapFrame2.Top = 5.5

'Pastes the contents of the clipboard and assigns it to the variable "MapFrame3"
	Dim MapFrame3 As Object
	Set MapFrame3 = Plot2.Shapes.Paste(Format:=srfPasteBest)

'Positions the copied MapFrame3 on the page
	MapFrame3.Left = 1
	MapFrame3.Top = 10.75
End Sub


Updated November 08, 2018

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



Please sign in to leave a comment.