4 Replies Latest reply on Mar 4, 2017 12:07 PM by c.pfaffenbichler

    Batch replace smart layer with eps files

    johnb73378901

      Hi everyone, I am hoping someone can please help me as I have over 500+ files just for one type of product.

       

      Basically I have eps files in a folder which are different sizes, I need someway of making one image in photoshop for example a rear view of a car, I want to select an area where a script will open the folder of eps files and insert, resize to a certain height or width and then save as a jpg, then repeat next eps file.

       

      0-60-black-1000.jpg

       

      Where you see the 0 - 60 eventually, will be replaced with another eps file, the back of the car remain the same.

       

      Hopefully someone can please help as lost on how to do this with a few thousand products.

       

      Thanks John

        • 1. Re: Batch replace smart layer with eps files
          JJMack Most Valuable Participant

          Your description read like a logic puzzle that has errors in it.

          • 2. Re: Batch replace smart layer with eps files
            c.pfaffenbichler Level 9

            Is the element currently a Smart Object?

            Do the eps differ in proportions?

            How is the maximum area for the eps’ in the receiving image defined?

             

            If you had included the pertinent Panel/s in the screenshot you might have made your point more clearly. (edited)

            • 3. Re: Batch replace smart layer with eps files
              johnb73378901 Level 1

              Hi c.pfaffenbichler thank you so much for your response.

               

              Hope this clears things up.

               

              1. I am setting up my own website selling vinyl graphics, all are eps files of different proportions.

              2. I want to overlay each of the eps file on top of an image that I select so that it appears like in the above picture, I would set the size of the area and position of where the eps file will be placed (not sure how) and then save the file at 1000px x 1000px in jpg

              3. This would then repeat the next eps file and save again etc.

               

              How would I achieve this without having to do each file manually.

               

              Trying to create pictures like this.WS-15945-01.jpgWS-15967-01.jpgWS-32402-02.jpg

               

              Thanks John

              • 4. Re: Batch replace smart layer with eps files
                c.pfaffenbichler Level 9

                If the SO resides in a Group with a Layer Mask that defines the target area the following may help, though I did not bother with scaling the jpgs – either start with a layered file in the correct dimensions or amend the Script yourself.

                // replace selected smart object, scale according to layer froup’s layer mask and save jpgs;

                // 2017, use it at your own risk;

                #target photoshop

                if (app.documents.length > 0) {

                var myDocument = app.activeDocument;

                var theName= myDocument.name.match(/(.*)\.[^\.]+$/)[1];

                var thePath = myDocument.path;

                var theLayer = myDocument.activeLayer;

                // jpg options;

                var jpegOptions = new JPEGSaveOptions();

                jpegOptions.quality = 9;

                jpegOptions.embedColorProfile = true;

                jpegOptions.matte = MatteType.NONE;

                // check if layer is smart object;

                if (theLayer.kind != "LayerKind.SMARTOBJECT") {alert ("selected layer is not a smart object")}

                else {

                // select files;

                if ($.os.search(/windows/i) != -1) {var theFiles = File.openDialog ("please select files", "*.psd;*.psb;*.tif;*.eps", true)}

                else {var theFiles = File.openDialog ("please select files", getFiles, true)};

                if (theFiles) {

                var originalRulerUnits = app.preferences.rulerUnits;

                app.preferences.rulerUnits = Units.PIXELS;

                // get target area;

                myDocument.activeLayer = theLayer.parent;

                loadLayerMaskSelection (myDocument, theLayer.parent, false);

                var theDim = myDocument.selection.bounds;

                myDocument.activeLayer = theLayer;

                myDocument.selection.deselect();

                // work through the array;

                for (var m = 0; m < theFiles.length; m++) {

                // replace smart object;

                theLayer = replaceContents (theFiles[m], theLayer);

                // scale;

                var theBounds = theLayer.bounds;

                var theHor = (theDim[2]-theDim[0])/(theBounds[2]-theBounds[0])*100;

                var theVer = (theDim[3]-theDim[1])/(theBounds[3]-theBounds[1])*100;

                $.writeln(theDim);

                $.writeln((theDim[2]-theDim[0])/(theDim[3]-theDim[1]) +"\n"+ (theBounds[2]-theBounds[0])/(theBounds[3]-theBounds[1])+"\n");

                if ((theDim[2]-theDim[0])/(theDim[3]-theDim[1]) < (theBounds[2]-theBounds[0])/(theBounds[3]-theBounds[1])) {var theFactor = theHor}

                else {var theFactor = theVer};

                theLayer.resize(theFactor, theFactor, AnchorPosition.MIDDLECENTER);

                //save jpg;

                var theNewName = theFiles[m].name.match(/(.*)\.[^\.]+$/)[1];

                myDocument.saveAs((new File(thePath+"/"+theName+"_"+theNewName+".jpg")),jpegOptions,true);

                };

                // reset;

                app.preferences.rulerUnits = originalRulerUnits;

                }

                }

                };

                ////// get psds, tifs and jpgs from files //////

                function getFiles (theFile) {

                if (theFile.name.match(/\.(psd|tif|psb|eps)$/i) != null || theFile.constructor.name == "Folder") {

                return true

                };

                };

                ////// replace contents //////

                function replaceContents (newFile, theSO) {

                app.activeDocument.activeLayer = theSO;

                // =======================================================

                var idplacedLayerReplaceContents = stringIDToTypeID( "placedLayerReplaceContents" );

                var desc3 = new ActionDescriptor();

                var idnull = charIDToTypeID( "null" );

                desc3.putPath( idnull, new File( newFile ) );

                var idPgNm = charIDToTypeID( "PgNm" );

                desc3.putInteger( idPgNm, 1 );

                executeAction( idplacedLayerReplaceContents, desc3, DialogModes.NO );

                return app.activeDocument.activeLayer

                };

                ////// also adapted from xbytor’s stdlib //////

                function loadLayerMaskSelection (doc, layer, invert) {

                  var desc = new ActionDescriptor();

                  var cref = new ActionReference();

                  cref.putProperty(charIDToTypeID("Chnl"), charIDToTypeID("fsel"));

                  desc.putReference(charIDToTypeID("null"), cref);

                  var tref = new ActionReference(); // Channel Kind ("Trsp" or "Msk ")

                  tref.putEnumerated(charIDToTypeID("Chnl"), charIDToTypeID("Chnl"), charIDToTypeID("Msk "));

                  desc.putReference(charIDToTypeID("T   "), tref);

                  if (invert == true) {desc.putBoolean(charIDToTypeID("Invr"), true)};

                  executeAction(charIDToTypeID("setd"), desc, DialogModes.NO);

                  };

                replaceSmartObjectScaleScr.jpg