Change font properties for all text in a Surfer project via automation

If your Surfer project contains a mix of different fonts and font sizes, or if it was created with fonts or sizes that no longer suit your needs, you can use a script to standardize them. This script efficiently loops through all objects in your project and updates the font size and font face for all labels, titles, and text associated with those objects. This can be especially helpful for ensuring consistency in presentations or reports.

Note: This script does not update text within Grid Values map layers, as there is currently no automation support for this map type. If you'd like to request this feature, please let us know, and we can add your vote to the request!

 

To run this script:

  1. In a Windows Explorer window, navigate to C:\Program Files\Golden Software\Surfer.
  2. Double click on Scripter.exe to launch Scripter.
  3. Copy and paste the script below into Scripter's code window (be sure to delete any existing lines first), or simply download the attached BAS file and open it in Scripter.
  4. Update the values in the USER-DEFINED VARIABLES section near the top of the script as needed. If you skip this step, the script will still run using the current values for these variables
  5. If you would like to run the script using an example project file, download ExampleProject.srf. Otherwise, skip to the next step. 
  6. Click Script | Run to run the script.
  7. The script will then open a dialog in which you can select either the ExampleProject.srf or one of your own SRF files. Select the desired file and then click Open.

'Changes the font face and size for all labels/titles/text
'(other than Grid Values map labels and base map labels)
Sub Main
    
    '==================================
    'USER-DEFINED VARIABLES
    '==================================
    fontface$ = "Arial"
    fontsize = 10
    '==================================

    'Initializes Surfer
    Dim SurferApp, Plot, MapFrame As Object
    Set SurferApp = CreateObject("Surfer.Application")
    SurferApp.Visible = True

    'Prompt the user to select the SRF file
    filepath$ = GetFilePath$(, "srf", , , 0)

    'Opens the Surfer file
    Set Plot = SurferApp.Documents.Open(filepath)

    'Loops through all of the objects in the project
    For i = 1 To Plot.Shapes.Count

        'If the object is a map...
        If Plot.Shapes.Item(i).Type = srfShapeMapFrame Then
            Set MapFrame = Plot.Shapes.Item(i)

            'Loops through all of the axes within a map and update thier font properties
            For j = 1 To MapFrame.Axes.Count
                MapFrame.Axes(j).LabelFont.Face = fontface$
                MapFrame.Axes(j).LabelFont.Size = fontsize
                MapFrame.Axes(j).TitleFont.Face = fontface$
                MapFrame.Axes(j).TitleFont.Size = fontsize
                Debug.Print "Axis " + Str(j) + " done in " + MapFrame.Name
            Next j

            'Loops through all of the map layers within a map
            For k = 1 To MapFrame.Overlays.Count
    
                'If the map layer is a contour layer, update the label font properties 
                If MapFrame.Overlays(k).Type = srfShapeContourMap Then
                    MapFrame.Overlays(k).LabelFont.Face = fontface$
                    MapFrame.Overlays(k).LabelFont.Size = fontsize
                    Debug.Print "Contour layer done in " + MapFrame.Name
                End If

                'If the map layer is a base layer, update the font properties of any text objects in the layer
                If MapFrame.Overlays(k).Type = srfShapeBaseMap Then
                    MapFrame.Overlays(k).Font.Face = fontface$
                    MapFrame.Overlays(k).Font.Size = fontsize
                    Debug.Print "Base layer done in " + MapFrame.Name
                End If

                'If the object is a graticule, update the font properties of the labels
                If MapFrame.Overlays(k).Type = srfShapeGraticule  Then
                    MapFrame.Overlays(k).LabelFont.Face = fontface$
                    MapFrame.Overlays(k).LabelFont.Size = fontsize
                    Debug.Print "Graticule done in " + MapFrame.Name
                End If

                'If the map layer is a post layer or a classed post layer, loop through all label sets and update thier font properties 
                If MapFrame.Overlays(k).Type = srfShapePostmap Or  MapFrame.Overlays(k).Type = srfShapeClassedPost Then
                    MapFrame.Overlays(k).LabelFont.Face = fontface$
                    MapFrame.Overlays(k).LabelFont.Size = fontsize
                    Debug.Print "Post layer done in " + MapFrame.Name
                End If
            Next k
        End If

        'If the object is a legend, update the font properties of the title and entires
        If Plot.Shapes.Item(i).Type = srfShapeLegend Then
            Plot.Shapes.Item(i).SampleFont.Face = fontface$
            Plot.Shapes.Item(i).SampleFont.Size = fontsize
            Plot.Shapes.Item(i).TitleFont.Face = fontface$
            Plot.Shapes.Item(i).TitleFont.Size = fontsize
            Debug.Print "Legend done"
        End If

        'If the object is a color scale or legend, update the font properties of the labels and title
        If Plot.Shapes.Item(i).Type = srfShapeColorScale Then
            Plot.Shapes.Item(i).LabelFont.Face = fontface$
            Plot.Shapes.Item(i).LabelFont.Size = fontsize
            Plot.Shapes.Item(i).TitleFont.Face = fontface$
            Plot.Shapes.Item(i).TitleFont.Size = fontsize
            Debug.Print "Color scale done"
        End If

        'If the object is a scale bar, update the font properties of the labels and title
        If Plot.Shapes.Item(i).Type = srfShapeScale Then
            Plot.Shapes.Item(i).LabelFont.Face = fontface$
            Plot.Shapes.Item(i).LabelFont.Size = fontsize
            Debug.Print "Scale bar done"
        End If

        'If the object is a profile, update the font properties of the profile labels, the title, and the axes' labels
        If Plot.Shapes.Item(i).Type = srfShapeProfile Then
            Plot.Shapes.Item(i).TitleFont.Face = fontface$
            Plot.Shapes.Item(i).TitleFont.Size = fontsize
            For l = 1 To Plot.Shapes.Item(i).Axes.Count
                Plot.Shapes.Item(i).Axes(l).LabelFont.Face = fontface$
                Plot.Shapes.Item(i).Axes(l).LabelFont.Size = fontsize
                Plot.Shapes.Item(i).Axes(l).TitleFont.Face = fontface$
                Plot.Shapes.Item(i).Axes(l).TitleFont.Size = fontsize
            Next l
            Debug.Print "Profile layer and axes done
        End If

        'If the object is a drawn text object, update the font properties 
        If Plot.Shapes.Item(i).Type = srfShapeText Then
            Plot.Shapes.Item(i).Font.Face = fontface$
            Plot.Shapes.Item(i).Font.Size = fontsize
            Debug.Print "Text done"
        End If
    Next i

    'Provide a script-completion notice
    Dim updatedText As String
    MsgBox "The script has completed, and all text has been updated to " & fontsize & " pt " & fontface, vbInformation, "Completion Notice"

End Sub

Updated September, 2024

Was this article helpful?
5 out of 8 found this helpful

Comments

0 comments

Please sign in to leave a comment.