Follow

How can I use Surfer Scripter to have the user select a data file, grid it, create a map, and then loop back to the beginning?

To loop through having a user select a data file, gridding it, and creating 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 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. 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 becomse "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)

        Dim Map As Object
        Set Map = Plot.Shapes.AddContourMap(GridFileName:=GridFile)

    Loop

End Sub

 

Updated September 27, 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.