Follow

How can I use Surfer Scripter to reformat my BNA file(s) for import into CMG?

This article provides a full script for changing which column of a BNA header row the z information is located in.
 

Q: I want to get my contour map into CMG so I've exported them to BNA, but they aren't loading. CMG support says it's the headers that are the issue. Surfer is exporting a header with the z value in column A and an empty column in column B, but CMG expects the z value in column B and an empty column in column A. How can I update the header information without having to manually go through thousands of lines?

 

A: This is the perfect instance where a script can do all this manual work for you.

    1. In Windows Explorer, navigate to C:\Program Files\Golden Software\Surfer 14\Scripter and double click on Scripter.exe to launch Scripter.
    2. Delete the existing two lines of script and copy/paste in this script:
      Sub Main
      
          'Initialize Surfer
          Dim SurferApp, Wks, WksRangeA, WksRangeB As Object
          Set SurferApp = CreateObject("Surfer.Application")
          SurferApp.Visible = True 'Make Surfer visible
      
          'Prompt the user for the name of the data file to process.
          InFile = GetFilePath("","BNA", CurDir(), "Select data file", 0)
      
          'Open BNA
          Set Wks = SurferApp.Documents.Open(FileName:=InFile)
          Set WksRangeA = Wks.Columns(Col1:=1, Col2:=1)
          Set WksRangeB = Wks.Columns(Col1:=2, Col2:=2)
      
          'Loop through rows
          numrows = WksRangeA.RowCount
          For i=1 To numrows
              'If col B in row is empty, cut col A cell for that row and paste it into col B
              If WksRangeB.Cells(i)="" Then
                  WksRangeA.Cells(i).Cut
                  WksRangeB.Cells(i).Paste
              End If
          Next
      
          'Saves the BNA to the same name
          Wks.Save
      
          'Closes Surfer
          SurferApp.Quit
      
      End Sub
    3. Click Script | Run.
    4. Choose your BNA file and click Open.

 

If you have multiple BNA files, you can update line 8 of this script to instead loop through BNA files in a certain directory.

 

Updated February 15, 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.