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

If your Surfer project was created with all different fonts and font sizes, or it was created with different fonts/sizes than what you need, you can use a script to change them all. This script loops through all objects in your project and changes the font size and font face for all labels, titles, and/or text associated with those objects.

Note: This does not apply to Grid Values map labels, nor does it apply to vector Base map labels, since those two maps do not currently have automation commands for editing label font properties.

To run this script:

  1. Copy the script below, or download the attached BAS file: ChangeFontPropertiesForEntireProject.bas.
  2. Download the attached Plot1.srf file.
  3. In a Windows Explorer window, navigate to C:\Program Files\Golden Software\Surfer.
  4. Double click on Scripter.exe to launch Scripter.
  5. Press Ctrl+A to select all of the existing lines then press Delete.
  6. 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.
  7. Change the file path, font face, and font size in the User-defined variables section (the file path should be the location you downloaded Plot1.srf to, such as your Downloads directory).
  8. Click Script | Run to run the script.

'Changes the font face and size for all labels/titles/text
'(other than Grid Values map labels and base map labels)
Sub Main

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

'==================================
'User-defined variables
'==================================
filepath$ = "C:\temp\"
filename$ = "Plot1.srf"
fontface$ = "Arial"
fontsize = 10
'==================================

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

'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 assigns Arial 10 to labels and titles
		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 Map "+Str(i)
		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, assign Arial 10 labels
			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 Map "+Str(i)
			End If

			'If the map layer is a base layer, assign Arial 10 to 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 Map "+Str(i)
			End If

			'If the object is a graticule, assign Arial 10 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 Map "+Str(i)
			End If

			'If the map layer is a post layer or a classed post layer, loop through all label sets and assign Arial 10
			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 Map "+Str(i)
			End If
		Next k
	End If

	'If the object is a color scale or legend, assign Arial 10 labels and title
	If Plot.Shapes.Item(i).Type = srfShapeColorScale Or Plot.Shapes.Item(i).Type = srfShapeLegend 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/legend done"
	End If

	'If the object is a scale bar, assign Arial 10 to 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, change the font to Arial 10 for the profile labels and the title and labels of both axes
	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, assign Arial 10 labels
	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
End Sub

 

Updated June 24, 2019

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

Comments

0 comments

Please sign in to leave a comment.