When starting a project you may find that you have numerous sets of different data for your site. Automation can be used to generate grids and maps of these files in just minutes. If you have collected or generated numerous grids files of your site, the script below can be used to create contour maps for each one.
To run this script:
- Copy the script below, or download the attached BAS file: MapAll.bas.
- In a Windows Explorer window, navigate to C:\Program Files\Golden Software\Surfer.
- Double click on Scripter.exe to launch Scripter.
- Press Ctrl+A to select all of the existing lines then press Delete.
- 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.
- Click Script | Run to run the script.
*********
'For each GRD in the specified directory, the script creates a new window, a contour map in the window, saves and closes the SRF file. 'Then repeats for the next GRD in the directory. Sub Main ''''''''''''' User Variables '''''''''''''''''' 'You must enter the path to the grid files and the name of the BLN file file_directory = "C:\program files\golden software\surfer 15\samples\" 'make sure has a trailing \ file_extension = "grd" 'no "." preceding the extension ''''''''''''''''''''''''''''''''''''''''''''''' 'Opens Surfer Set SurferApp = CreateObject("surfer.application") SurferApp.Visible = True 'Progress for each file can be seen in the status bar of the application. 'Start the loop file_extension = LCase(Right(file_extension,(Len(file_extension) - InStrRev(file_extension,".")))) If Len(file_directory)-InStrRev(file_directory,"\") <> 0 Then file_directory = file_directory + "\" grid_file = Dir( file_directory + "*." + file_extension) On Error GoTo FileError While grid_file <> "" 'Opens new Surfer window Dim Plot As Object Set Plot = SurferApp.Documents.Add 'Creates the map Dim MapFrame As Object Set MapFrame = Plot.Shapes.AddContourMap(GridFileName:=file_directory + grid_file) 'Saves the file as SRF Plot.SaveAs (file_directory + Left(grid_file, Len(grid_file)-(Len(grid_file)-InStrRev(grid_file,".")+1) ) +".srf") Debug.Print grid_file Plot.Close grid_file = Dir() 'get next file Wend 'Closes Surfer SurferApp.Quit Exit Sub 'Error instructions FileError: Debug.Print "Error: " + grid_file + " " + Err.Description Resume Next End Sub
Updated November 12, 2021
Comments
Please sign in to leave a comment.