By default, Grapher names new plots using the value in the first row of the Y variable column. However, this behavior differs in older Grapher versions, and you may have existing files with plots that aren’t named this way. The script below renames plots based on the Y variable column header. It applies to plot types with a YCol property, but you can modify it to work with other plot types or use a different column (e.g., the X variable column) for naming.
To run this script:
- In a Windows Explorer window, navigate to C:\Program Files\Golden Software\Surfer.
- Double click on Scripter.exe to launch Scripter.
- 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.
- Update the inputFile variable under the USER-DEFINED VARIABLES section at the beginning of the script. If you do not update this variable, the script will still run using a Grapher sample file.
- Click Script | Run to run the script.
'=========================================================== 'This script renames plots based on the Y variable column 'header. It applies only to plot types with a YCol property. 'Refer to the "YCol Property" page in the Help for a list of 'supported plot types. '=========================================================== Sub Main '======================================================= ' USER-DEFINED VARIABLES '======================================================= ' Path to input GRF or GPJ file inputFile = "C:\Program Files\Golden Software\Grapher\Samples\Graph Magnifier.gpj" '======================================================= ' Initialize Grapher Dim Grapher As Object Set Grapher = CreateObject("Grapher.Application") Grapher.Visible = True ' Open the input file in a plot document Dim PlotDoc As Object Set PlotDoc = Grapher.Documents.Open(inputFile) ' Initialize objects used in the for loop below Dim Graph As Object, Plot As Object, Wks As Object ' Loop through all shape objects in the plot document For i = 1 To PlotDoc.Shapes.Count ' If the shape object is graph... If PlotDoc.Shapes.Item(i).Type = grfShapeGraph Then ' Create and object pointer to the graph Set Graph = PlotDoc.Shapes.Item(i) ' Loop through the plots under the graph For j = 1 To Graph.Plots.Count ' Create an object pointer to the plot object Set Plot = Graph.Plots.Item(j) ' Get the worksheet used by this plot wksPath = Plot.Worksheet Set Wks = Grapher.Documents.Open(wksPath) ' Get the column index from the plot columnIndex = Plot.YCol ' Get the column name from the first worksheet row colName = Wks.Cells(1, columnIndex) ' Use the the column name to rename the plot Plot.Name = colName ' Close the worksheet Wks.Close(grfSaveChangesNo) Next End If Next End Sub
Updated March 2025
Comments
Please sign in to leave a comment.