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:
- Click here to download the BAS file: open and export.BAS
- Click Automation | Scripts | Run, select the BAS file from your downloads directory, and click Open.
OR:
- Copy the script below.
- Open Grapher and turn on the Script Manager by clicking View | Display | Script Manager.
- Press Ctrl+A to select all of the existing lines in the Script Manager and then press DELETE.
- Press Ctrl+V to paste it into the Script Manager.
- 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 13\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 11, 2018
0 Comments