Open all GRF files in a directory and export them to vector PDF using Grapher automation

This article contains a sample script for opening all GRF files in a directory and exporting each to a vector PDF file.

To run this script:

  1. Click here to download the BAS file: open and export.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
'Opens all GRF file in directory
'Exports each to PDF (vector)
Debug.Clear

''''''''''''' User Variables ''''''''''''''''''

file_extension	= "grf"

file_directory	= "C:\program files\golden software\grapher 15\samples\"

export_format = "pdf"

'''''''''''''''''''''''''''''''''''''''''''''''
	Dim grapher As Object
	Set grapher = CreateObject("grapher.application")
	grapher.Visible = True
	Debug.Print grapher.Version

	file_extension	= LCase(Right(file_extension,(Len(file_extension) - InStrRev(file_extension,"."))))
	If  Len(file_directory)-InStrRev(file_directory,"\") <> 0 Then file_directory = file_directory + "\"

	grf_file = Dir( file_directory  + "*." + file_extension)

	On Error GoTo FileError
	While grf_file <> ""
		'Define output file directory & name
		export_file	= file_directory + Left(grf_file, Len(grf_file)-(Len(grf_file)-InStrRev(grf_file,".")+1) ) + "." + export_format

		'Opens a GRF file
		Set Plot = grapher.Documents.Open(file_directory + grf_file)
		Plot.Export2(export_file, False, , False, "pdfv")

		Debug.Print grf_file
		grf_file = Dir() 'get next file
	Wend

	grapher.Quit
	Exit Sub

	'Print a meaningful error message for each file that did not grid correctly
	FileError:
	Debug.Print  "Error:	" + grf_file + "						" + Err.Description
	Resume Next

End Sub

 

Updated August 6, 2019

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

Comments

0 comments

Please sign in to leave a comment.