Adjust the visibilty of map objects via Surfer automation

You can turn on or off the visibility of maps, map layers, axes, and other objects in Scripter using the  .Visible property of the Shape object. Sample scripts for each of the most common objects are provided below.

To run any of these scripts:

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

 

Turn off the visibility of the mapframe

Sub Main
    Dim SurferApp As Object
    Set SurferApp = CreateObject("Surfer.Application")
    SurferApp.Visible = True

    'Opens an SRF file
    Dim Plot As Object
    Set Plot = SurferApp.Documents.Open(FileName:=SurferApp.Path+"\Samples\MapLayers.srf")

    'Identifies a layer in the map. This is a shape object.
    Dim MapFrame1 As Object
    Set MapFrame1 = Plot.Shapes.Item(Index:=1)
    Set ContoursLayer = MapFrame1.Overlays(2)

    'Sets that layer to be invisible
    ContoursLayer.Visible = False
End Sub

 

Turn off the visibility of a map layer

'===================================
'Visibility of Map Layer OFF.bas
'===================================
'Shows how to turn off the visibility of a map layer, similar to unchecking
'the checkbox in the Contents window next to the map layer in the UI.
'===================================
Sub Main

'Initializes Surfer
	Dim SurferApp, Plot, PostLayer, PostLayer2 As Object
	Set SurferApp = CreateObject("Surfer.Application")
	SurferApp.Visible = True
	Set Plot = SurferApp.Documents.Add

'Creates two post maps
	Set MapFrame = Plot.Shapes.AddPostMap(SurferApp.Path + "\samples\demogrid.dat")
	Set MapFrame2 = Plot.Shapes.AddPostMap(SurferApp.Path + "\samples\sample1.dat")

'Overlays the two post maps
	Plot.Shapes.SelectAll
	Plot.Selection.OverlayMaps
	Plot.Selection.DeselectAll
	
'Turns off the visibility of the second post layer
	Set NewMapFrame = Plot.Shapes.Item(1)
	Set PostLayer2 = NewMapFrame.Overlays(2)
	PostLayer2.Visible = False
End Sub

 

Turn off the visibility of a single axis

'===========================================
'Visibility of Axis OFF.bas
'===========================================
'Shows how to turn off the visibility of an axis, like unchecking the check box for
'the axis in the Contents window in the UI.
'===========================================
Sub Main

'Initializes Surfer
        Dim SurferApp, Plot, MapFrame, Axes As Object
        Set SurferApp = CreateObject("Surfer.Application")
        SurferApp.Visible = True
        Set Plot = SurferApp.Documents.Add

'Creates a contour map
	Set MapFrame = Plot.Shapes.AddContourMap(GridFileName:=SurferApp.Path+"\samples\demogrid.grd")

'Turns off the visibility of the bottom axis
	MapFrame.Axes("Bottom axis").Visible=False
End Sub

 

Turn off the visibility of all map axes

'HideAxes.bas eliminates ticks, labels, and axis titles, and hides the axes
'for selected maps in an open SRF file. It ignores selected objects that are not maps.
'Does not work for maps grouped into composite objects.
'1. Open SRF file.
'2. Select the maps to eliminate the axes.
'3. Run script.
'=======================================

Sub Main
	Debug.Clear
	'Use existing Surfer instance.
	On Error GoTo Error1:
  	Set surf = GetObject(, "Surfer.Application")
	On Error GoTo 0
	Set document = surf.ActiveDocument
	If  document.Type <> srfDocPlot Then GoTo Error2:
	Debug.Print "Surfer Version:     " & surf.Version
	Debug.Print "Document:           " & surf.ActiveDocument
	Set selection = document.Selection
	i = 0
	For Each obj In selection
		If obj.Type = srfShapeMapFrame Then
			i = i + 1
			Debug.Print "Modified Map" & i & ":      " & obj.Name
			shrinkAxes(obj)
		End If
	Next obj
	If i = 0 Then GoTo Error3:
GoTo Xit:
Error1:
Debug.Clear
Debug.Print "Surfer is not running.  Start Surfer, open a document, and select maps to modify."
GoTo Xit:
Error2:
Debug.Clear
Debug.Print "Active document is not a plot. Open or activate a plot document and select a maps to modify."
GoTo Xit:
Error3:
Debug.Clear
Debug.Print "No maps selected.  Select some maps to modify."
Debug.Print "Make sure your maps are Not inside a composite Object."
GoTo Xit:
Xit:
End Sub
Public Function shrinkAxes(frame As Object)
	For Each axis In frame.Axes
		axis.ShowLabels = False
		axis.MajorTickType = srfTickNone
		axis.MinorTickType = srfTickNone
		axis.Visible = False
		axis.Title = ""
	Next axis
End Function

 

For more information, please see the Visible Property [Shape] Help page. 

 

Updated October 2021

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

Comments

0 comments

Please sign in to leave a comment.