Follow

How can I change my map scale via Surfer automation?

This article contains a sample script for changing the scale of the map.

To run this script:

  1. Copy the script below, or download the attached BAS file: MapScale.bas.
  2. In a Windows Explorer window, navigate to C:\Program Files\Golden Software\Surfer 15\Scripter.
  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.
     

*********

'==========================================================================
'MAPSCALE.BAS
'
'This script demonstrates the following:
'
'	Create a wireframe and a contour map
'	Overlay two maps
'	Change the X, Y, and Z scale for the maps
'
'==========================================================================

Sub Main
	'Declare the variable that will reference the application
	Dim SurferApp As Object

	'Creates an instance of the Surfer Application object 
	' and assigns it to the variable named "SurferApp"
	Set SurferApp = CreateObject("Surfer.Application")

	'Assigns the location of the data and grid files to the variable "Path"
	Path = SurferApp.Path + "\samples\"

	'Makes Surfer visible
	SurferApp.Visible = True
	
	'Declares Doc as Object
	Dim Doc As Object
	
	'Creates a plot document in Surfer and assigns it to the variable "Doc"
	Set Doc = SurferApp.Documents.Add
	
	'Declares MapFrame1 as object
	Dim MapFrame1 As Object

	'Creates a wireframe map and assigns the map frame to the variable "MapFrame1"
	Set MapFrame1 = Doc.Shapes.AddWireframe(GridFileName:=Path+"demogrid.grd")
	
	'Declares MapFrame2 as object
	Dim MapFrame2 As Object
	
	'Creates a contour map and assigns the map frame to the variable "MapFrame2"
	Set MapFrame2 = Doc.Shapes.AddContourMap(GridFileName:=Path+"demogrid.grd")
	
	'Select both Maps
	MapFrame1.Selected = True
	MapFrame2.Selected = True

	'Overlay the selected maps and save the new map frame
	Dim MapFrame As Object
	Set MapFrame = Doc.Selection.OverlayMaps
	
	'Change the map scale
	MapFrame.xMapPerPU = 0.5
	MapFrame.yMapPerPU = 0.5
	MapFrame.zMapPerPU = 20	
		
	'Declares Plot as Object
	Dim Plot As Object
	
	'Assigns the first (and only) plot window To the variable "Plot"
	Set Plot = Doc.Windows(1)
		
	'Change the view so the entire map fits on the screen
	Plot.Zoom(srfGridZoomFitToWindow)

End Sub

 

Updated October 11, 2017

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

2 Comments

  • 0
    Avatar
    Kien Pham

    It seems to me that the per unit settings don't behave the same as the scale input in the Transform menu. Is there a way to automate setting specifically the X and Y scale inputs in the Transform menu?

    EDIT: I was actually able to figure out the scaling I want using the MapPerPU properties. However, I have not figured out how to turn off Proportional XY scaling via automation. Please help on that. 

    Edited by Kien Pham
  • 1
    Avatar
    Brittany Bodane

    Hi Kien,

    Thank you for posting your questions! I am happy you found how to automat setting the X and Y scale inputs in the Transform menu. 

    Regarding your new question, The Proportional XY Scaling option is automatically turned off if you set the Map scale to lengths that are not proportional. Thus, there is no method to uncheck this option. If you only establish a length for the X, Y, or Z, Surfer assumes you would like to keep the map proportionally scaled. Otherwise, it will take the lengths stated in the script. For example, the script below will change the X,Y, and Z scales to disproportionate scaling:


    MapFrame1.zLength = 1.75
    MapFrame1.xLength = 3
    MapFrame1.yLength = 3

    Another sample script you may be interested in seeing in located by default in C:\Program Files\Golden Software\Surfer <version number>\Samples\Scripts and is named MapFrame.bas

     

    Please let us know if you have any further questions.

    Thank you,

    Brittany Bodane

    Golden Software

     

     

    Edited by Brittany Bodane
Please sign in to leave a comment.