Follow

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. Click here to download the BAS file:Lock all Objects in Directory.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. 

*********

'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
  Grapher.Visible(1)
  
  '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
	i=1
	For i = 1 To doc.Shapes.Count
		Set itemi = doc.Shapes.Item(i)
		itemi.Locked = True
	Next i

    'Save the graph
	doc.Save

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

  'Uncomment the next line to close Grapher
  'Grapher.Quit()
  
End Sub

 

Updated January 16, 2018

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

0 Comments

Please sign in to leave a comment.