Follow

How can I automate opening all of my GRF files and export them to vector PDF?

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. Copy the script below, or click here to download the BAS file: open and export.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
'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 11\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 October 28, 2016

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.