When writing a script to complete a complex workflow, it is sometimes necessary to get input from the user. User prompts can be used to get many different kind of information including input files as demonstrated in the script below.
To run this script:
- Copy the script below, or download the attached BAS file: GetFilePath.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.
*********
'GetFilePath.bas shows how to open a dialog box to select a grid or 'data file to use, or to save an SRF file. '======================================== Sub Main Dim SurferApp As Object Set SurferApp = CreateObject("Surfer.Application") SurferApp.Visible = True Dim Plot As Object Set Plot = SurferApp.Documents.Add 'GetFilePath format is in the form of: 'default file name, extension(s), default file path, dialog title, and option value. 'See Help | BASIC Language Help, UserInput | GetFilePath for option values 'Choose a grid file for contour map gridfilepath = GetFilePath( , "grd",SurferApp.Path+"\samples\","Open Grid File",0) Dim MapFrame As Object Set MapFrame = Plot.Shapes.AddContourMap(GridFileName:=gridfilepath) 'Choose a data file for post map datafilepath = GetFilePath("demogrid.dat","dat;txt;csv;xlsx;xls",CurDir(),"Open Data File",0) Dim MapFrame2 As Object Set MapFrame2 = Plot.Shapes.AddPostMap(DataFileName:=datafilepath) 'Save to an SRF file SRFfile = GetFilePath ("default name" ,"srf", CurDir(),"Save SRF File",2) End Sub
Updated November 2021
Comments
Please sign in to leave a comment.