9 Replies Latest reply on Jun 26, 2015 5:35 PM by mikaelj50294563
      • 1. Re: ExportType.SVG "Use Artboards" option
        CarlosCanto Adobe Community Professional & MVP

        it works the same as if you do it manually in the UI, there's no "use artboards" option, the active artboard gets exported...so, replicated that in your script, activate the artboard you wish export first, then do Document.exportFile

        • 2. Re: ExportType.SVG "Use Artboards" option
          Seth Olson Level 1

          In the latest version of Illustrator (CS6), there is no export as SVG.  There is "Save As" SVG, and that has the option checkbox "Use Artboards". 

           

          Unfortunatly, there is no "Save As" method that I can find, hence the Document.exportFile.  When I run the script, it is including everything in the file, regardless of the layers or artboard position.

           

          Here is the script:

           

          var folder = Folder.selectDialog();

          var document = app.activeDocument;

          if(document && folder)

          {

                    var options = new ExportOptionsSVG();

                    options.compressed = false;

                    options.preserveEditability = false;

           

                    var n = document.layers.length;

                    for(var i=0; i<n; ++i)

                    {

                              hideAllLayers();

                              var layer = document.layers[i];

                              layer.visible = true;

                              var file = new File(folder.fsName+"/"+layer.name+".png");

                              document.exportFile(file, ExportType.SVG, options);

                    }

                    showAllLayers();

          }

           

           

          function hideAllLayers()

          {

                    forEach(document.layers, function(layer) {

                              layer.visible = false;

                    });

          }

           

          function showAllLayers()

          {

                    forEach(document.layers, function(layer) {

                              layer.visible = true;

                    });

          }

           

          function forEach(collection, fn)

          {

                    var n = collection.length;

                    for(var i=0; i<n; ++i)

                    {

                              fn(collection[i]);

                    }

          }

           

           

          I might be going about this the wrong way, but it feels like I am close.  If there is someway to remove the extra pieces... maybe if I duplicate the document and delete all other layers per export? 

          I am open to ideas.  Thanks!

          • 3. Re: ExportType.SVG "Use Artboards" option
            Seth Olson Level 1

            Is it possible to script save as a copy?

            • 4. Re: ExportType.SVG "Use Artboards" option
              Seth Olson Level 1

              Ok, temporary solution:

              • Run script that exports each layer as an SVG
              • Reopen all of the SVGs, and then run a custom illustrator Action that does "Save As" with the "Use Artboards" option check on.   This purges all the hidden junk.
              1 person found this helpful
              • 5. Re: ExportType.SVG "Use Artboards" option
                CarlosCanto Adobe Community Professional & MVP

                Seth Olson wrote:

                 

                Is it possible to script save as a copy?

                 

                not possible, we only have "Save as...", so you must save the reference to the actual file before saving as, then you'll have to close the file and reopen the original reference

                • 6. Re: ExportType.SVG "Use Artboards" option
                  CarlosCanto Adobe Community Professional & MVP

                  this function is from the documentation, I checked and it is the same for CS5 and CS6, I tried it with CS5 and it works as I described in post # 1, it exports the active artboard only

                   

                  // Exports current document to dest as an SVG file with specified
                  // options, dest contains the full path including the file name
                  function exportFileToSVG (dest) {
                  if ( app.documents.length > 0 ) {
                  var exportOptions = new ExportOptionsSVG();
                  var type = ExportType.SVG;
                  var fileSpec = new File(dest);
                  exportOptions.embedRasterImages = true;
                  exportOptions.embedAllFonts = false;
                  exportOptions.fontSubsetting = SVGFontSubsetting.GLYPHSUSED;
                  app.activeDocument.exportFile( fileSpec, type, exportOptions );
                  }
                  }
                  
                  • 7. Re: ExportType.SVG "Use Artboards" option
                    gregbriandavis

                    So from here, where do I take this code to "plug it in"?

                    • 8. Re: ExportType.SVG "Use Artboards" option
                      CarlosCanto Adobe Community Professional & MVP

                      the code I posted in post #6 is just a function, it won't do anything "as is", it needs to be called, like this

                       

                      exportFileToSVG ("your file name")

                       

                      to use complete code from this thread or anywhere else, follow this

                       

                      - copy the script from a post

                      - open Adobe ExtendScript Toolkit (or a text Editor of your choice)

                      - paste the copied script

                      - save the script with a meaningful name

                       

                      to run double click on the script.

                       

                       

                      if you want to run it from within Illustrator -> File -> Scripts Menu

                       

                      - save the script here:

                      C:\Program Files\Adobe\Adobe Illustrator CS5\Presets\en_US\Scripts\

                       

                       

                      Mac user,  /Applications/Adobe\ Illustrator\ CS5/Presets/en_US/Scripts/

                       

                      - restart Illustrator

                      • 9. Re: ExportType.SVG "Use Artboards" option
                        mikaelj50294563

                        Hello

                         

                        I found a solution for illustrator 2015, i have made a script to export different size of images for mobiles app, but i have made som changes to it to fix this problem.

                         

                        You just need to run the script and export it as svg files.

                         

                        i have place it on cloud app .. artbord_to_img_v2.jsx.

                         

                        Hopes this helps