Follow

How can I fill my contours via Surfer automation?

This article contains a sample script for filling a contour map with a user defined range.


To run this script:

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

*********

'==========================================================================
'CONTOURFILL.BAS
'
'This script demonstrates the following:
'
'	How to create a contour map
'	How to fill the contour intervals with CLR file
'	How to fill a single contour interval with a specific color

'==========================================================================

Sub Main

	Dim SurferApp As Object
	Set SurferApp = CreateObject("Surfer.Application")
	SurferApp.Visible = True
	
	Path = SurferApp.Path + "\samples\"
	
	Dim Plot As Object
	Set Plot = SurferApp.Documents.Add
	Set MapFrame = Plot.Shapes.AddContourMap(GridFileName:=Path+"demogrid.grd")
	Set ContourLayer = MapFrame.Overlays(1)
	ContourLayer.FillContours = True

'Fills the contours with colors from a CLR file
	ContourLayer.FillForegroundColorMap.LoadFile(SurferApp.Path+"\ColorScales\Rainbow.clr")
	ContourLayer.ApplyFillToLevels(1, 1, 0)

'Change a specific contour interval to Magenta
	Set Levels = ContourLayer.Levels
	Levels(8).Fill.ForeColorRGBA.Color = srfColorMagenta
	
'Move first map to lower left
	MapFrame.Selected = True
	Plot.Selection.Left = 1.0
	Plot.Selection.Top = 4.0
		
'Deselect All
	Plot.Selection.DeselectAll
	
'Create a second contour map and fill contours
	Set MapFrame2 = Plot.Shapes.AddContourMap(GridFileName:=Path+"demogrid.grd")
	Set ContourLayer2 = MapFrame2.Overlays(1)
	ContourLayer2.FillContours = True
	
'Set the colors to be gradational from blue to white
	Set Levels2 = ContourLayer2.Levels
	m = Levels2.Count
	ColorInc2 = 255.0 / (m-1)
	For j=1 To m
		ColorInc2 = 255.0 * (j-1) / (m-1)
		Levels2(j).Fill.ForeColorRGBA.Color = RGB(ColorInc2,ColorInc2,255)
	Next j
	
	'Move second map to upper right
	MapFrame2.Selected = True
	Plot.Selection.Left = 4.5
	Plot.Selection.Top = 10.0
	
	'Turn on screen updating to view maps
	Plot.Windows(1).Zoom(srfGridZoomFitToWindow)

End Sub

 

Updated February 13, 2017

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

0 Comments

Please sign in to leave a comment.