Skip to main content
Participant
March 29, 2018
Question

Action - Batch Channel automation

  • March 29, 2018
  • 1 reply
  • 1260 views

Hi everyone,

I'm trying to figure out a way in PS, to start with an image, then batch/automate/action a way to open a then selected folder that will have a bunch of alphas to then directly import into the current images channels.

So its very similar to File//Scripts//Load files into stack...

Just instead of stacking into the normal layering system to then move each ALPHA image into the channels.

This topic has been closed for replies.

1 reply

Tom Winkelmann
Inspiring
March 29, 2018
kurzolrAuthor
Participant
March 29, 2018

Thanks for your response,

it may be a good start, but i have no idea what any of it means. so it may help others for now.

I have an image open, go file//Scripts//Browse -- Click on your script, i then point to folder with some Alphas/masks

It flickers about, loads images into the normal layering, but also seems to resize canvas randomly, then at the end opens what seems to be the .jsx tool kit box? In the end it's put them into the layers and nothing into channels.

Apologies for being a complete noob to this, but where have i gone wrong and could you point me in the right direction.

Tom Winkelmann
Inspiring
March 29, 2018

// Import files as Named Alpha Channels

// Built on:

// Import Folder as Layers - Photoshop CS/CS2 Script

// Author: Trevor Morris (tmorris@fundy.net) - with help from Krista Cook and Gunnar Landva

// Tweaker for this version: David Pardini

// Assist from Mike Hale of ps-scripts.com!

// Version: 1.0

// debugging code

/*

debugger;

$.level = 1;

*/

// Import Folder as Layers - Photoshop CS/CS2 Script

// Description: Imports a series of images (from the designated folder) as named layers into a new document

// Author: Trevor Morris (tmorris@fundy.net) - with help from Krista Cook and Gunnar Landva

// Version: 1.3.1, 29/May/2005

// debugging code

/*

debugger;

$.level = 1;

*/

// determine Photoshop version number

function getCSVersion() {

   return parseInt(app.version);

}

function getFolder() {

   // display the Path Entry dialog with Browse option for Photoshop CS

   if (getCSVersion() === 8) {

      // create dialog for pasting/typing path to images folder

      var dlg = new Window('dialog', 'Import Folders as Layers', [0,0,480,118]);

      dlg.center();

      dlg.add('statictext', [15,15,460,35], 'Please enter the path of the folder to be imported:');

      dlg.add('edittext', [15,45,465,65], '', {name:'pathText'});

      dlg.pathText.active = true;

      dlg.add('button', [235,80,305,103], 'Browse', {name:'browse'});

      dlg.browse.onClick = function() {this.parent.close(3);};

      dlg.add('button', [315,80,385,103], 'OK', {name:'ok'});

      dlg.add('button', [395,80,465,103], 'Cancel', {name:'cancel'});

      // display dialog

      dlg.result = dlg.show();

      if (dlg.result == 3) { // Browse

         return Folder.selectDialog('Please select the folder to be imported:', Folder('~'));

      } else if (dlg.result == 1) { // OK

         return Folder(dlg.pathText.text);

      } else { // Cancel (dlg.result == 0)

         return null;

      }

   }

   // display only the browse dialog for Photoshop CS2+

   else {

      return Folder.selectDialog('Please select the folder to be imported:', Folder('~'));

   }

}

function importFolderAsLayers(selectedFolder) {

       // if a folder was selected continue with action, otherwise quit

       if (selectedFolder) {

          // create document list from files in selected folder

          var docList = selectedFolder.getFiles();

          for (var i = 0; i < docList.length; i++) {

             // open each document in file list

             if (docList instanceof File) {

                // get the file name

                var fName = docList.name.toLowerCase();

               

                // check for supported file formats

                if ((fName.indexOf(".gif") == -1) && (fName.indexOf(".jpg") == -1) && (fName.indexOf(".png") == -1) && (fName.indexOf(".bmp") == -1) && (fName.indexOf(".tif") == -1) && (fName.indexOf(".psd") == -1)) {

                   // skip unsupported formats

                } else {

                    // open documents from list;

                    var docRef = open(docList);

                   // if supported documents exist, create a new document

                   if (!newCanvas) {

                       // get the file size and set the units

                       var originalRulerUnits = preferences.rulerUnits;

                      preferences.rulerUnits = Units.PIXELS;

                     var fHigh = docRef.height.value;

                     var fWide = docRef.width.value;

                      var fRes = docRef.resolution;

                      // remember unit settings and change to pixels

                      var newDoc = app.documents.add(fHigh, fWide, fRes, "Start File", NewDocumentMode.RGB, DocumentFill.TRANSPARENT, 1);

                      // restore original unit setting

                      preferences.rulerUnits = originalRulerUnits;

                      app.activeDocument = docRef;

                      var newCanvas = 1;

                   }

                   //  get document name; flatten; duplicate to new document; close;

                   // name layer in new document using the original document name

                   var docName = docRef.name;

                   docRef.flatten();

                   docRef.changeMode(ChangeMode.RGB);

                   docRef.channels[0].duplicate(documents[newDoc.name],ElementPlacement.PLACEATBEGINNING);

                   docRef.close(SaveOptions.DONOTSAVECHANGES);

                   //rename active channel

                   app.activeDocument.activeChannels[0].name = fName;

                }

             }

          }

       }

    }

importFolderAsLayers(getFolder());

Sorry - my fault - wrong script ... here's the right one...