4 Replies Latest reply on Nov 29, 2013 6:10 AM by c.pfaffenbichler

    How to automate layer stack creation including layer masks based on filename?

    Proteus2000

      Hi

       

      Can someone help me to create a script that would automate the creation of layers including a layermask, based on filenames.

      E.g.

      Unwrap_001_diffuse.jpg

      Unwrap_001_mask.jpg

      Unwrap_002_diffuse.jpg

      Unwrap_002_mask.jpg

       

       

      The image with the suffix "_diffuse" would be the layer and the image with the suffix "_mask" would be the layermask.

      In the above example the script would create 1 psd with 2 layers.

      If there is no file with the ending "_mask", the script would only create a single layer with no layermask.

       

      Any help would be highly appreciated.

       

      Thank you

      Boris

       

      I

        • 1. Re: How to automate layer stack creation including layer masks based on filename?
          c.pfaffenbichler Level 9

          For starters the Folder-selection dialog could be used if the images are all in one Folder.

          var theFolder = Folder.selectDialog ("select folder");

          And then the method getFiles could be used to get the files.

          var theFiles1 = theFolder.getFiles("*_diffuse.jpg");

          Loading the file as Layers can be done with the ScriptingListener code for File > Place for example and finding the corresponding mask files seems fairly easy.

          Are they grayscale or RGB?

           

          But why jpg anyway?

          Are those renderings?

          If so why not tiffs or some other non destructively compressed file format?

          • 2. Re: How to automate layer stack creation including layer masks based on filename?
            c.pfaffenbichler Level 9

            Placing the images may lead to resizing if receiving document and placed image have different resolutions.

             

            To get the Layer Masks one could load the »…_mask.jpg« files in the same document or duplicate the document, convert it to a grayscale profile, turn off color management for the duplicate, fill it with black, place the mask there, then flatten, copy and then paste into a newly created Layer Mask in the original document. The positions should be identical if bot images are identical in dimensions and resolution.

            Some of this would, again, need Action Manager code as one can record with ScriptingListener.plugin.

            • 3. Re: How to automate layer stack creation including layer masks based on filename?
              Chuck Uebele Adobe Community Professional & MVP

              Another option for creating the layer mask would be to open the layer mask document then use apply image to transfer it to the other document's layer mask with either the invert check box selected or not, depending upon how layer mask file was created.  Again, as c.pfaffenbichler mentioned, using scriptListener.  You might want to even use apply image to create the diffuse layers in the target document.  You could use c.pfaffenbichler's method for getting the files, but then create a new doc for your doc for your target document, create a new layer, then open your source doc and apply it to the new layer.  In doing this, you could also at the same time create a variable for each layer to better track your layers for applying the layer mask to each.

              • 4. Re: How to automate layer stack creation including layer masks based on filename?
                c.pfaffenbichler Level 9

                Well, I don’t especially like copy/pasting in Scripts, either.

                And as is so often the case in Photoshop there are more ways than one to achieve the result.