1 Reply Latest reply on May 29, 2015 12:19 AM by c.pfaffenbichler

    Automate illustrator artboards to photoshop smartobject

    mikeymiz

      1. I have an illustrator file with multiple artboards.

      2. I have a photoshop file with artwork taken from these illustrator files, and placed as a smartobject.

      3. I'd like to automate this process, rather than a COPY/PASTE/SAVE scenario , 1 at a time.

      4. See photo.

       

      Screen Shot 2015-05-28 at 11.02.03 AM.png

        • 1. Re: Automate illustrator artboards to photoshop smartobject
          c.pfaffenbichler Level 9

          If you want to give it a try paste the following text into a new file in ExtendScript Toolkit and save it as a jsx-file into Photoshop’s Presets/Scripts-folder.

          After restarting Photoshop the Script should be available under File > Scripts and can be assigned a Keyboard Shortcut directly, recorded into an Action or started from ExtendScript Toolkit directly.

          Maybe open should insert an upper limit for pages in cases there should be problems with registering the page number of the ai file.

           

          Edit: This Script would replace existing files of the respective names without prompting.

           

          // replace smart object content with pages from ai file and save psd files;
          // 2015, use at your own risk; 
          #target "photoshop-70.032"
          main();
          ////// function //////
          function main () {
          // set to pixels;
          var originalRulerUnits = app.preferences.rulerUnits;
          app.preferences.rulerUnits = Units.PIXELS;
          var myDocument = app.activeDocument;
          // get properties, thanks to xbytor;
          var docName = myDocument.name;
          if (docName.indexOf(".") != -1) {var baseName = docName.match(/(.*)\.[^\.]+$/)[1]}
          else {var baseName = docName};
          baseName = baseName.replace(new RegExp ("_[0-9]*$"), "");
          // getting the location, if unsaved save to desktop;
          try {var docPath = myDocument.path}
          catch (e) {var docPath = "~/Desktop"};
          // the smart object;
          var theLayer = myDocument.activeLayer;
          if (theLayer.kind == LayerKind.SMARTOBJECT) {
          // select files;
          if ($.os.search(/windows/i) != -1) {var theFile = File.openDialog ("please select files", '*.ai;*.pdf', false)}
          else {var theFile = File.openDialog ("please select files", getFiles, false)};
          if (theFile) {
          var time1 = Number(timeString());
          // psd options;
          psdOpts = new PhotoshopSaveOptions();
          psdOpts.embedColorProfile = true;
          psdOpts.alphaChannels = true;
          psdOpts.annotations = true;
          psdOpts.layers = true;
          psdOpts.spotColors = true;
          // duplicate open image;
          var theCopy = myDocument.duplicate(baseName);
          var theLayer = theCopy.activeLayer;
          ////////////////////////////////////
          var theNumber = getPDFPageCount(theFile);
          // try to replace contents;
          for (var thePage = 1; thePage <= theNumber; thePage++) {
          try {
          replaceContents (theLayer, theFile, thePage);
          // save;
          theCopy.saveAs((new File(docPath+"/"+baseName+"_"+bufferNumberWithZeros(thePage,3)+".psd")),psdOpts,false);
          }
          catch (e) {return}
          };
          ////////////////////////////////////
          // finish;
          var time2 = Number(timeString());
          alert(((time2-time1)/1000)+" seconds\nstart "+time1+"\nend "+time2);
          }
          };
          // reset;
          app.preferences.rulerUnits = originalRulerUnits;
          };
          ////// replace contents //////
          function replaceContents (theSO, theFile, thePage) {
          app.activeDocument.activeLayer = theSO;
          // =======================================================
          var idplacedLayerReplaceContents = stringIDToTypeID( "placedLayerReplaceContents" );
              var desc4 = new ActionDescriptor();
              var idnull = charIDToTypeID( "null" );
              desc4.putPath( idnull, new File( theFile ) );
              var idPgNm = charIDToTypeID( "PgNm" );
              desc4.putInteger( idPgNm, thePage);
          executeAction( idplacedLayerReplaceContents, desc4, DialogModes.NO );
          return app.activeDocument.activeLayer
          };
          ////// get psds, tifs and jpgs from files //////
          function getFiles (theFile) {
              if (theFile.name.match(/\.(ai|pdf|)$/i)) {
                  return true
                  };
            };
          ////// buffer number with zeros //////
          function bufferNumberWithZeros (number, places) {
            var theNumberString = String(number);
            for (var o = 0; o < (places - String(number).length); o++) {
            theNumberString = String("0" + theNumberString)
            };
            return theNumberString
            };
          ////// function to get the date //////
          function timeString () {
            var now = new Date();
            return now.getTime()
            };
          // by jezz, based on something by xbytor i guess;
          function getPDFPageCount(f) {
          f.open ('r');
          var gotCount = false;
          while (! gotCount) {
          next_line = f.readln();
          if ( f.eof ) {alert("Aborting the script\nWe've got to the end of the file without finding a page count");
               f.close();
               exit();
               }
               if (next_line.indexOf ("/N ") > 0 && next_line.slice(0, 9) != "<</Length" && next_line.slice(0, 9) != "[/Separat") {
               var p = next_line.match (/\/N (\d+)\/T/)[1];
               gotCount = true;
               }
               else if (next_line.indexOf ("/Pages") > 0 ) {
          //      alert (next_line);
               var p = parseInt(next_line.substring(next_line.indexOf("/Pages") +6), 10)
               gotCount = true;
               }
          }
          f.close ();
          return Number(p);
          };