Prompt the user to select a data file, grid it, create a map, and then repeat in Surfer automation

To loop through having a user select a data file, grid the data, and create a map from the grid, you can use a "Do" loop. Start with Do, enter all the commands you want to loop, and end with Loop to go back to the beginning. Use If InFile = "" Then Exit Do to exit the loop. Below is a full script example of this.

 

To run this script:

  1. Copy the script below.
  2. In a Windows Explorer window, navigate to C:\Program Files\Golden Software\Surfer\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. Press Ctrl+V to paste it into Scripter. 
  6. Click Script | Run to run the script.
     

*********

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

        'Prompt the user for the name of the data file to process.
        InFile = GetFilePath(" ","DAT;TXT;CSV;XLS",CurDir(), "Select Data File", 0)
        If InFile = "" Then Exit Do

        'Get file name without the extension (for example, "week5.txt becomes "week5")
        BaseName = InFile
        ExtStart = InStrRev(InFile, ".")
        If ExtStart >1 Then BaseName = Left(InFile,ExtStart-1)

        'Create a grid from the specified data file using the kriging algorithm
        GridFile = BaseName + ".grd"
        SurferApp.GridData (DataFile:= InFile, OutGrid:= GridFile)

  'Create a contour map from the grid file Dim Map As Object Set Map = Plot.Shapes.AddContourMap(GridFileName:=GridFile) Loop End Sub

 

Updated November 2021

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

Comments

0 comments

Please sign in to leave a comment.