Break a map layer out of the map via Surfer automation

Before a layer can be broken out into a new map, the layer must first be defined.  In the sample script below, three maps are created, then overlaid, and then one layer is broken out again.  If you are breaking a layer out of an existing map, you can define the layer using the Overlays property of the MapFrame.  When counting map layers, their index number is counted up from the bottom.

To run this script:

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


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

'Declares MapFrame as Object
	Dim MapFrame1 As Object

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

'Creates a contour map and assigns the map frame to the variable "MapFrame2"
	Set MapFrame2 = Plot.Shapes.AddContourMap(GridFileName:=SurferApp.Path+"\samples\demogrid.grd")
	Dim ContourLayer As Object
	Set ContourLayer = MapFrame2.Overlays(1)

'Creates a post map and assigns the map frame to the variable "MapFrame3"
	Set MapFrame3 = Plot.Shapes.AddPostMap (SurferApp.Path+"\samples\demogrid.dat")
	Dim PostLayer As Object
	Set PostLayer = MapFrame3.Overlays(1)

'Selects the three maps
	MapFrame1.Selected = True
	MapFrame2.Selected = True
	MapFrame3.Selected = True

'Overlays the maps and set the overlay to NewMapFrame
	Set NewMapFrame = Plot.Selection.OverlayMaps

'Breaks apart the overlay and sets the new map frame to NewMapFrame2
'For more overlay options, see Overlays Collection
	Set NewMapFrame2 = NewMapFrame.Overlays.BreakApart(pOverlay:=ContourLayer)
End Sub



Updated December 2021

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



Please sign in to leave a comment.