I've selected multiple objects. How can I turn them all on or off via Grapher Scripter?

This article contains a sample script for turning on or off the visibility of all selected objects.

To run this script:

  1. Copy the script below, or click here to download the BAS file: Add Legend_Data.BAS.
  2. In a Windows Explorer window, navigate to C:\Program Files\Golden Software\Grapher 12\Scripter.
  3. Double click on Scripter.exe to launch Scripter.
  4. Press Ctrl+A to select all of the existing lines then press Delete.
  5. 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.
  6. Click Script | Run to run the script.


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 October 28, 2016

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request


Please sign in to leave a comment.