How can I edit a property for all axes at once via Grapher automation?

This article contains a sample script for looping through all axes in the graph and making a change.

  1. To run this script:

    1. Click here to download the BAS file: Loop through and change all axes.BAS.
    2. Click Automation | Scripts | Run, select the BAS file from your downloads directory, and click Open.

    OR:

    1. Copy the script below.
    2. Open Grapher and turn on the Script Manager by clicking View | Display | Script Manager.
    3. Press Ctrl+A to select all of the existing lines in the Script Manager and then press DELETE.
    4. Press Ctrl+V to paste it into the Script Manager.
    5. Click the Start/Resume icon () in the Script Manager.

*********

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 October 15, 2018

Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.