6 Replies Latest reply on May 13, 2016 8:58 AM by clutch-cargo

    Export file as a Tiff

    clutch-cargo Level 1

      I have my script working until I try to export it as a tiff file.  I literally copy/pasted the code from the Illustrator CS6 Scripting Reference example (the sub routine).  I get an error on Line 34 getting an "Expected Identifier" error 800A03F2.  In the example code line 30  is written as: Sub ExportFileAsTIFF (Dest)  ' Dest contains the full path and file name to save to.  So I added my full path.  Any ideas?


      Set AppRef = CreateObject("Illustrator.Application")
      Set FSO = CreateObject("Scripting.FileSystemObject")
      doJavaScript = "var fileRef = File.openDialog ('Select the Road DXF file to open:', '*.DXF', false); if(fileRef) filePath = fileRef.fsName;" 
      FileRef = AppRef.DoJavaScript(doJavaScript)
      If (FSO.FileExists(fileRef)) Then
          Set AutoCADOpenOptions = AppRef.Preferences.AutoCADFileOptions
          AutoCADOpenOptions.MergeLayers = false
          CurrentInteractionLevel = AppRef.UserInteractionLevel
          AppRef.UserInteractionLevel = -1 ' aiDontDisplayAlerts
          AppRef.Open FileRef, 2 ' aiCMYK
          AppRef.UserInteractionLevel = CurrentInteractionLevel
          AppRef.ActiveDocument.Layers.GetByName( "Unknown_Area_Type" ).Delete() 
      End If    
      If (AppRef.Documents.Count > 0) Then
          Set DocPathItems = AppRef.ActiveDocument.PathItems
              If (DocPathItems.Count > 0) Then
                  For Each CurrentPath in DocPathItems
                  CurrentPath.StrokeWidth = 30  ' 30 for motorway, 10 for motorway_link, 20 for main, 10 for res
              End If            
      End If    
      ' Exports the current document as TIFF to dest
      ' dest contains the full path and file name to save to
      Sub ExportFileAsTIFF ("S:\SOCAL\Section_13\Light TIFFs\_testTIFF")
          Set TiffExportOptions = CreateObject("Illustrator.ExportOptionsTIFF")
          If AppRef.Documents.Count > 0 Then
              TiffExportOptions.imageColorSpace = 2 'aiImageRGB
              TiffExportOptions.resolution = 72
              TiffExportOptions.lZWCompression = false
              TiffExportOptions.AntiAliasing = true
              TiffExportOptions.SaveMultipleArtboards = true
              Set DocRef = AppRef.ActiveDocument
              Call DocRef.Export (Dest, 9, TiffExportOptions) ' 9 = aiTIFF
          End If
      End Sub
        • 1. Re: Export file as a Tiff
          clutch-cargo Level 1

          Ooops, just a small addition.  The error message I get refers to line 30, not 34 as noted above.

          • 2. Re: Export file as a Tiff
            clutch-cargo Level 1

            CarlosCanto - help! if you come across this. I found a post you answered in 2015 'How to define 'dest' in Illustrator VBscript example?', and followed your answer.  I applied the following to work with Tiffs but I get the following error message:


            ActiveX component can't create object  800A01AD

            Line 116  (this is line 'Set tiffExportOptions = CreateObject("Illustrator.ExportOptionsTIFF")'


            Here's my edited version (sorry, can't seem to remember how to add code here in the forum)


            DestFile = "S:\SOCAL\Section_13\Light TIFFs\_testTIFF"

            ExportFileAsTIFF (DestFile)


            Sub ExportFileAsTIFF (Dest)

                Set App = CreateObject("Illustrator.Application")

                Set tiffExportOptions = CreateObject("Illustrator.ExportOptionsTIFF")

                If App.Documents.Count > 0 Then

                    tiffExportOptions.imageColorSpace = 2 'aiImageRGB

                    tiffExportOptions.resolution = 72

                    tiffExportOptions.lZWCompression = false

                    tiffExportOptions.AntiAliasing = true

                    tiffExportOptions.SaveMultipleArtboards = true


                    Set DocRef = App.ActiveDocument

                    Call DocRef.Export (Dest, 9, tiffExportOptions) ' 9 = aiTIFF

                End If

            End Sub

            • 4. Re: Export file as a Tiff
              clutch-cargo Level 1

              Oh, bummer...  Ok, so I can try my hand a Javascript (hard enough time with VBscript, ).  Luckily, they have code for it in the Illustrator Reference CS6 guide for Javascript.


              Here's what I have but it is drawing an error: "Expected Statement" at line 1.  Since this is a VBscript do I need to activate Java in some way like "doJavaScript = ??" or will it pick it up automatically?


              // Exports current document to dest as a TIFF file with specified
              // options, dest contains the full path including the file name
              destFile = "S:\SOCAL\Section_13\Light TIFFs\_TestFile"
              exportFileToPSD (destFile)
              function exportFileToPSD (dest) {
                  if ( app.documents.length > 0 ) {
                      var exportOptions = new ExportOptionsTIFF();
                      var type = ExportType.TIFF;
                      var fileSpec = new File(dest);
                      exportOptions.resolution = 72;
                      exportOptions.byteOrder = TIFFByteOrder.IBMPC;
                      exportOptions.IZWCompression = false;
                      exportOptions.saveMultipleArtboards = true
                      app.activeDocument.exportFile( fileSpec, type, exportOptions );
              • 5. Re: Export file as a Tiff
                CarlosCanto Adobe Community Professional & MVP

                that's javascript, no need to use "doJavascriptScript", it seems you only need to change slashes with forward slashes


                "S:\SOCAL\Section_13\Light TIFFs\_TestFile"


                "S:/SOCAL/Section_13/Light TIFFs/_TestFile"   

                • 6. Re: Export file as a Tiff
                  clutch-cargo Level 1

                  Dooooh!  Always helpful with a 2nd pair of eyes to catch a simple mistake.  Many thx my fried.  I did find a work-around also by creating an Action in Illustrator and using the DoScript function.