How can I lock all objects in my Grapher files via automation?

This article contains a sample script for opening all GRF files in a selected directory and locking all items in the GRF.

To run this script:

  1. Copy the script below, or click here to download the BAS file: Lock all Objects in Directory.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.


'Lock all Objects in Directory.BAS
'This script opens all the GRF files in a directory.
'It then locks all the objects in each GRF and saves to the same GRF name.
'                            SKP 1/10

Sub Main
  'Create Grapher as an object
  Dim Grapher As Object
  'Start Grapher
  Set Grapher = CreateObject("Grapher.Application")
  'Remove quote from the following line to make Grapher visible
  'Uncomment the next line to specify the directory in the script
  'Directory = Grapher.Path+"\Samples\"

  'Use this section if you want a dialog displayed to get the directory
  filetemp = GetFilePath$ (,"grf",Grapher.Path+"\Samples\","Directory to Change")
  Directory = Left(filetemp,InStrRev(filetemp,"\"))

  'Get all the file names
  file$ = Dir$(Directory + "*.grf")

  While file$ <> ""
    'Open the file in the directory in order
    Set doc = Grapher.Documents.Open(Directory+file$)
    'Loop through all objects and lock them
	For i = 1 To doc.Shapes.Count
		Set itemi = doc.Shapes.Item(i)
		itemi.Locked = True
	Next i

    'Save the graph

    'Close the plot window
    'Open the next file
    file$ = Dir$()

  'Uncomment the next line to close Grapher
End Sub


Updated 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.