Turn visibility on/off for all selected objects via Grapher automation

To turn the visibility of all selected objects on or off via Scripter, see below:

To run this script:

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


  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

'Create Grapher as an Object
Dim Grapher As Object

'Start Grapher
Set Grapher = CreateObject("Grapher.Application")

'Make Grapher visible
Grapher.Visible = True

'Use the existing plot
Set Plot1 = Grapher.Documents.Active

'Change visibility of all selected axes
For i = 1 To Plot1.Shapes.Count
	'Loop through graphs
	If Plot1.Shapes.Item(i).Type = grfShapeGraph Then
		'Loop through all axes
		For j = 1 To Plot1.Shapes.Item(i).Axes.Count
			'Only change the selected ones
			If Plot1.Shapes.Item(i).Axes.Item(j).selected = True Then
				'Turn off axes if they are on and turn off if they are on
				If Plot1.Shapes.Item(i).Axes.Item(j).Visible = True Then
					Plot1.Shapes.Item(i).Axes.Item(j).Visible = False
				ElseIf Plot1.Shapes.Item(i).Axes.Item(j).Visible <> True Then
					Plot1.Shapes.Item(i).Axes.Item(j).Visible = True
				End If
			End If
		Next j
		'Loop through all plots
		For k = 1 To Plot1.Shapes.Item(i).Plots.Count
			'Only change the selected ones
			If Plot1.Shapes.Item(i).Plots.Item(k).selected = True Then
				'Turn off plots if they are on and on if they are off
				If Plot1.Shapes.Item(i).Plots.Item(k).Visible = True Then
					Plot1.Shapes.Item(i).Plots.Item(k).Visible = False
				ElseIf Plot1.Shapes.Item(i).Plots.Item(k).Visible <> True Then
					Plot1.Shapes.Item(i).Plots.Item(k).Visible = True
				End If
			End If
		Next k
	'Loop through all other objects
	ElseIf Plot1.Shapes.Item(i).Type <> grfShapeGraph Then
		If Plot1.Shapes.Item(i).selected = True Then
			'Turn it off if it is on and on if it is off
			If Plot1.Shapes.Item(i).Visible = True Then
				Plot1.Shapes.Item(i).Visible = False
			ElseIf Plot1.Shapes.Item(i).Visible <> True Then
				Plot1.Shapes.Item(i).Visible = True
			End If
		End If
	End If
Next i

End Sub


Update August 2019

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



Please sign in to leave a comment.