This article contains a sample script for looping through all axes in the graph and making a change.
To run this script:
- Copy the script below, or download the attached BAS file: Loop through and change all axes.BAS.
- In a Windows Explorer window, navigate to C:\Program Files\Golden Software\Grapher 12\Scripter.
- 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.
Sub Main 'Declares GrapherApp as an Object Dim GrapherApp As Object 'Start Grapher Set GrapherApp = CreateObject("Grapher.Application") 'Make the Grapher window visible GrapherApp.Visible = True 'Open the bar chart orientations.grf sample file Set Plot1 = GrapherApp.Documents.Open(GrapherApp.Path+"\Samples\bar chart orientations.gpj") 'Loop through and find only graphs For i = 1 To Plot1.Shapes.Count If Plot1.Shapes.Item(i).Type = grfShapeGraph Then 'Once you find a graph, loop through and find only axes For j = 1 To Plot1.Shapes.Item(i).Axes.Count 'Once you find an axis, see if it is an X Axis If Plot1.Shapes.Item(i).Axes.Item(j).axisType = grfXAxis Then 'If it is an X Axis, change the min and max values - these can be values that are previously set to a variable Plot1.Shapes.Item(i).Axes.Item(j).AutoMin = False Plot1.Shapes.Item(i).Axes.Item(j).AutoMax = False Plot1.Shapes.Item(i).Axes.Item(j).Min = 3 Plot1.Shapes.Item(i).Axes.Item(j).Max = 28 'Change the label format Plot1.Shapes.Item(i).Axes.Item(j).TickLabels.MajorFormat.DateTimeFormat = 5 End If 'Find the next axis Next j End If 'Find the next graph Next i End Sub
Updated April 14, 2017