5 Replies Latest reply on Aug 21, 2010 9:25 PM by JJMack

    Add layers from other psd file and retain text layers (Batch processing)

    norway_photo

      I want to batch process a large number of portraits adding text info from the filename (year_name_number.jpg) to existing text layers. I want to make a template psd file containg the correct labeled text layers formatted and adjusted (With bleding effects and more) How can i add layers from an other psd file to the active document and retaining the text layers editable. The place command in PS5 adds the file as a smart object, no use.

       

      Any ideas?

       

      I tried the combined action/script way, but no joy so far. Right now i am making the text layers with a action, then calling the script from the action. It works but its difficult to make different templates from adjusting a action.


      The code i am using now (in combination with a action creating the 3 text layers and other grapchical elements)

       

      var docRef = activeDocument;

      // strip the extension off


      var fileNameNoExtension = docRef.name;
      fileNameNoExtension = fileNameNoExtension.split( "_" );
      if ( fileNameNoExtension.length > 1 ) {
                      fileNameNoExtension.length--;
      }

      fileNameNoExtension = fileNameNoExtension.join("_");

      var myString = fileNameNoExtension;
      var mySplitResult = myString.split("_");

       

      var textLayer = docReflayers['Year']; // define the existing text layer to a var
      docRef.activeLayer = textLayer;
      textLayer.kind = LayerKind.TEXT;
      var T1 = textLayer.textItem;
      T1.contents = mySplitResult[0]

      var textLayer = docRef.layers['Name']; // define the existing text layer to a var
      docRef.activeLayer = textLayer;
      textLayer.kind = LayerKind.TEXT;
      var T2 = textLayer.textItem;
      T2.contents = mySplitResult[1]

       

      var textLayer = docRef.layers['Number']; // define the existing text layer to a var
      docRef.activeLayer = textLayer;
      textLayer.kind = LayerKind.TEXT;
      var T3 = textLayer.textItem;
      T3.contents = mySplitResult[2]

       

      Thanks

      Eivind

        • 1. Re: Add layers from other psd file and retain text layers (Batch processing)
          JJMack Most Valuable Participant

          norway_photo wrote:

           

          I want to batch process a large number of portraits adding text info from the filename (year_name_number.jpg) to existing text layers. I want to make a template psd file containg the correct labeled text layers formatted and adjusted (With bleding effects and more) How can i add layers from an other psd file to the active document and retaining the text layers editable.

           

          Thanks

          Eivind

          Your description does not seem to make sense to me.  It reads more like you want to add a new text to your portrait images using an existing text layer that is in a template psd file. It seems you want to copy that text layer including  its blending layer style effects into the current portrait image document and also edit the text in the copy of the text layer to add additional text namely date and filename.   Are all the portrait images the same size so the position will match the template file?  What is the additional text in the template psd text layer.  You may have be better off creating a script that prompts for the additional text or retrieves the template psd text layerbv then process the images in your portrait folder adding the text layer and adding a layer style to it. Layer styles can change a layers blending as well as adding styles effects. You could save the your text layer style as a name of your choice an use the ScriptListener to generate the script code to apply it the the current layer would be the text layer you just added.  If your portrait image files vary in pixel size and resolution you will also need to also adjust the font size and text layers location.             

          • 2. Re: Add layers from other psd file and retain text layers (Batch processing)
            norway_photo Level 1

            Thanks for your reply

             

            All my portraits are the same size and the template file containing the text layers are also the same size.

             

            By having a template file with logos, text layers and other elements i can easily update the template the script uses.

             

            Here is my intended workflow:

             

            - A set of same size portraits labeled "year_name_number.jpg"

            - A template.psd os same size with graphical elements and text layers (named "year", "name" and "number")

            - A script or action copy/pasting og adding all layers from the template.psd file to the open portrait file, retaining text layers editable.

            - A script (The one i have working) changing the text layers added from the template to text from the filename.

            - A action saving this as a PDF ready for print.

             

            This way i can process a large number of portraits, add names and other information and save it as a file ready for print.

             

            I can image it is much easier to edit a template than writing a script or an action creating all the graphical elements.

            And even better, to change this template for different customers/departments/logos.

             

            Basically i need a way to add layers to an open file using a batch file or script.

             

            Eivind

            • 3. Re: Add layers from other psd file and retain text layers (Batch processing)
              Paul Riggott Level 6

              Here is the basics, it needs that your portrait is open in Photoshop

               

              
              //Amend to suit
              //The template file Must only have the text layers with thier own styles!
              var Template = File("/c/Folder1/FolderWhatever/Template.psd");
              open(Template);
              selectAllLayers();
              activeDocument.activeLayer.duplicate(app.documents[0] );
              app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
              var Name = decodeURI(app.activeDocument.name).replace(/\.[^\.]+$/, '');
              var NameParts = Name.split('_');
              activeDocument.activeLayer = activeDocument.artLayers.getByName('Year');
              activeDocument.activeLayer.textItem.contents = NameParts[0];
              activeDocument.activeLayer = activeDocument.artLayers.getByName('Name');
              activeDocument.activeLayer.textItem.contents = NameParts[1];
              activeDocument.activeLayer = activeDocument.artLayers.getByName('Number');
              activeDocument.activeLayer.textItem.contents = NameParts[2];
              function selectAllLayers() {
                  var desc111 = new ActionDescriptor();
                      var ref23 = new ActionReference();
                      ref23.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
                  desc111.putReference( charIDToTypeID('null'), ref23 );
                  executeAction( stringIDToTypeID('selectAllLayers'), desc111, DialogModes.NO );
              };
              
              • 4. Re: Add layers from other psd file and retain text layers (Batch processing)
                JJMack Most Valuable Participant

                norway_photo wrote:

                 

                 

                Here is my intended workflow:

                 

                - A set of same size portraits labeled "year_name_number.jpg"

                - A template.psd os same size with graphical elements and text layers (named "year", "name" and "number")

                - A script or action copy/pasting og adding all layers from the template.psd file to the open portrait file, retaining text layers editable.

                - A script (The one i have working) changing the text layers added from the template to text from the filename.

                - A action saving this as a PDF ready for print.

                 

                This way i can process a large number of portraits, add names and other information and save it as a file ready for print.

                 

                I can image it is much easier to edit a template than writing a script or an action creating all the graphical elements.

                And even better, to change this template for different customers/departments/logos.

                 

                Basically i need a way to add layers to an open file using a batch file or script.

                 

                Eivind

                 

                OK I understand what your trying to do and now I do not agree with your conclusion you made in you first append about place being no good for you.  Its is I think a perfect solution for you. I feel you need to address the process from a new angle.

                 

                I am very familiar with templates I use them all the time for collages which I populate with an actions.  However I do not batch this process and my process is interactive.  If you look at what your trying to do from the angle of creating a collage.  You will see what you are trying to do is automate the population of a single image collage using a single template in a batch process.  An example of one of my single image collage populated by one of my actions that has been saved as a jpeg image file.  My actions are played in Photoshop with no document opened.  After my action is play there is a single collage document in Photoshop that contains layers that can be tweaked all text is in text layers the can be edited.

                http://mouseprints.net/old/dpr/Examples/MyNameIsMud.jpg

                 

                If I wanted to automate the batch population of a single collage template I think all I would need to know is three thing.

                1.) The location of the input images

                2.) The full Path of the PSD template file.

                3.) The location to store the output  file

                 

                Looking at some of the recent threads in this forum I could almost cut and past the script you want to put  together.  There was a recent thread that had javascript code to process files in a folder and process only a list of file types.   There also was a thread that had a place function in it to place images into the current document or create a new document to place the image into.  The image was read from the web using a URL.  This thread has code to change a text layer.  At first I though you may need to open these image file to get at its meta-data to get the Portrait image Exif creation data.  But see all you need is the Filename for it has the data you want the year and name.  So the function that get the image files from the folder will give you that. The   Script needs to Open the Template PSD file and retrieve the prototype text layers text content  then the scrip needs a loop that get the next image file to be processed from the folder get filename function. In the loop the image files are place into the open template above a place holder layer like the Background layer. Then using the prototype text contents and the filename are used  create the new content for the text layer and then change the text layers content to it.  Follow that up with a save as for the output file.  Once the output file is saved delete the placed smart object layer.  When this loop ends the script will close the document with no save and end. As for the three inputs you need  the script could either have a dialog like the images processor or simply prompt you for the folders and template file.

                • 5. Re: Add layers from other psd file and retain text layers (Batch processing)
                  JJMack Most Valuable Participant

                  I put together a little package for you that demonstrates how "Place" may work for you. The big difference is I place the image into the template where you tried to place the template into the image.  I only hack at Photoshop scripting for I type with two fingers and don't really know oo programming or javascript. So the script I created has no dialog it just prompts for the folders and template.  Also there is no checking done when saving the file  so if the input folder has image file with duplicate filenames like image1.tif image1.cr2 image1.psd the output folder will only have a singel image1.psd.  My script saves PSD file it would be easy to add a saveAsPDF function to save a layered PDF file. I did not have javascript code handy to do that. The zip file contains an interactive action to populate single image collages, three single image collage templates and the Batch Script. I user 4 rules when I create collage templates:

                  1 Size the photo collage templates for the print size you want - width, height and DPI.

                  2 Photo collage templates must have a Photoshop background layer. The contents of this layer can be anything.

                  3 Photo collage templates must have alpha channels named "Image 1", "Image 2", ... "Image n".

                  4 Photo collage templates layers above the background layers must provide transparent areas to let the images show

                   

                  The Background is required for I place the images just above it and count on it being a layer thar does not support transparency.

                  The alpha channels are use to place the images and mask the image layers to trim off any excess image.

                   

                  http://www.mouseprints.net/old/dpr/Generic1ImageCollage.zip