Skip to main content
Victor Padilla
Participating Frequently
February 14, 2017
Answered

Photoshop Paths to Alpha Channel

  • February 14, 2017
  • 4 replies
  • 3432 views

Good morning fellow Photoshop citizens

Quick question: Does anyone know of a script, or plugin that converts a group of different paths into their own individual alpha channels? It would be nice to run this script rather than selecting each path and saving each path into it's own alpha channel. I have clients who do not like paths and rather use alpha channels. Any information would be appreciated!

Thanks.

This topic has been closed for replies.
Correct answer JJMack

JJ Mack, yes, I'm using CC 2017... I've tried several things and I can't get it to work. It may be the version of Photoshop as you've said.


The script goes through the motions but the make alpha channels fails to materialize. So I changed the the Action manger code that is use to make the alpha channel. All versions of Photoshop then create alpha channels with a selection, However, CC 2017 Alpha channels were the inverses of what the should be.  So I added a test for Photoshop and if above CC 2015.5 through in an invert selection.  So the script no work with all the version of Photoshop I now have installed. Who know what tomorrow will bring? All versions of Photoshop have bugs.  What will Adobe give us next.

#target photoshop 

var doc = activeDocument; 

setColors (); 

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

    doc.pathItems.select();

    makeSelection ();

    //makeChannel ();

  n = i+1;

    saveAlpha("Alpha " + n);

selRGB (); 

doc.selection.deselect(); 

 

function selRGB(){ 

    var idslct = charIDToTypeID( "slct" ); 

        var desc10 = new ActionDescriptor(); 

        var idnull = charIDToTypeID( "null" ); 

            var ref5 = new ActionReference(); 

            var idChnl = charIDToTypeID( "Chnl" ); 

            var idChnl = charIDToTypeID( "Chnl" ); 

            var idRGB = charIDToTypeID( "RGB " ); 

            ref5.putEnumerated( idChnl, idChnl, idRGB ); 

        desc10.putReference( idnull, ref5 ); 

    executeAction( idslct, desc10, DialogModes.NO ); 

     

    } 

 

function setColors(){ 

    var idRset = charIDToTypeID( "Rset" ); 

        var desc3 = new ActionDescriptor(); 

        var idnull = charIDToTypeID( "null" ); 

            var ref3 = new ActionReference(); 

            var idClr = charIDToTypeID( "Clr " ); 

            var idClrs = charIDToTypeID( "Clrs" ); 

            ref3.putProperty( idClr, idClrs ); 

        desc3.putReference( idnull, ref3 ); 

    executeAction( idRset, desc3, DialogModes.NO );   

    } 

 

function makeChannel(){ 

    var idMk = charIDToTypeID( "Mk  " ); 

        var desc4 = new ActionDescriptor(); 

        var idNw = charIDToTypeID( "Nw  " ); 

            var desc5 = new ActionDescriptor(); 

            var idClrI = charIDToTypeID( "ClrI" ); 

            var idMskI = charIDToTypeID( "MskI" ); 

            var idMskA = charIDToTypeID( "MskA" ); 

            desc5.putEnumerated( idClrI, idMskI, idMskA ); 

            var idClr = charIDToTypeID( "Clr " ); 

                var desc6 = new ActionDescriptor(); 

                var idRd = charIDToTypeID( "Rd  " ); 

                desc6.putDouble( idRd, 255.000000 ); 

                var idGrn = charIDToTypeID( "Grn " ); 

                desc6.putDouble( idGrn, 0.000000 ); 

                var idBl = charIDToTypeID( "Bl  " ); 

                desc6.putDouble( idBl, 0.000000 ); 

            var idRGBC = charIDToTypeID( "RGBC" ); 

            desc5.putObject( idClr, idRGBC, desc6 ); 

            var idOpct = charIDToTypeID( "Opct" ); 

            desc5.putInteger( idOpct, 50 ); 

        var idChnl = charIDToTypeID( "Chnl" ); 

        desc4.putObject( idNw, idChnl, desc5 ); 

    executeAction( idMk, desc4, DialogModes.NO ); 

 

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

    var idFl = charIDToTypeID( "Fl  " ); 

        var desc7 = new ActionDescriptor(); 

        var idUsng = charIDToTypeID( "Usng" ); 

        var idFlCn = charIDToTypeID( "FlCn" ); 

        var idBckC = charIDToTypeID( "BckC" ); 

        desc7.putEnumerated( idUsng, idFlCn, idBckC ); 

        var idOpct = charIDToTypeID( "Opct" ); 

        var idPrc = charIDToTypeID( "#Prc" ); 

        desc7.putUnitDouble( idOpct, idPrc, 100.000000 ); 

        var idMd = charIDToTypeID( "Md  " ); 

        var idBlnM = charIDToTypeID( "BlnM" ); 

        var idNrml = charIDToTypeID( "Nrml" ); 

        desc7.putEnumerated( idMd, idBlnM, idNrml ); 

    executeAction( idFl, desc7, DialogModes.NO ); 

     

    } 

 

function makeSelection(){ 

   var idsetd = charIDToTypeID( "setd" ); 

        var desc12 = new ActionDescriptor(); 

        var idnull = charIDToTypeID( "null" ); 

            var ref6 = new ActionReference(); 

            var idChnl = charIDToTypeID( "Chnl" ); 

            var idfsel = charIDToTypeID( "fsel" ); 

            ref6.putProperty( idChnl, idfsel ); 

        desc12.putReference( idnull, ref6 ); 

        var idT = charIDToTypeID( "T   " ); 

            var ref7 = new ActionReference(); 

            var idPath = charIDToTypeID( "Path" ); 

            var idOrdn = charIDToTypeID( "Ordn" ); 

            var idTrgt = charIDToTypeID( "Trgt" ); 

            ref7.putEnumerated( idPath, idOrdn, idTrgt ); 

        desc12.putReference( idT, ref7 ); 

        var idVrsn = charIDToTypeID( "Vrsn" ); 

        desc12.putInteger( idVrsn, 1 ); 

        var idvectorMaskParams = stringIDToTypeID( "vectorMaskParams" ); 

        desc12.putBoolean( idvectorMaskParams, true ); 

    executeAction( idsetd, desc12, DialogModes.NO ); 

    } 

function  saveAlpha(alphaName){

  var numberArray = version.split(".");

  if ( numberArray[0] > 17 ) {

  var idInvs = charIDToTypeID( "Invs" );

  executeAction( idInvs, undefined, DialogModes.NO );

  }

  var idDplc = charIDToTypeID( "Dplc" );

     var desc27 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

         var ref11 = new ActionReference();

         var idChnl = charIDToTypeID( "Chnl" );

         var idfsel = charIDToTypeID( "fsel" );

         ref11.putProperty( idChnl, idfsel );

     desc27.putReference( idnull, ref11 );

     var idNm = charIDToTypeID( "Nm  " );

     desc27.putString( idNm, alphaName );

  try {

  executeAction( idDplc, desc27, DialogModes.NO );

  }

  catch(e) {}

}

4 replies

Participant
January 29, 2020

I have never used a script before but this is exactly what I need. Where do I put it? How do I run this script? thanks!

Kukurykus
Legend
January 30, 2020

I didn't read anything above, but normally you save scripts in file with .jsx extension, then copy to Presets / Scripts folder of your Photoshop. After you run Ps you'll find a script on the list in File / Scripts menu.

Victor Padilla
Participating Frequently
February 22, 2017

Chuck Uebele, I'm sorry... but for some reason, the alpha channel are solid black. I have no clue why it's not filling white/black properly. Since the Alpha channel is a solid black, i'm assuming the fill is white, correct? For some odd reason, it doesn't work. I've tried resetting my fill options and palette options, no luck. Is there anything else I can try?

JJMack
Community Expert
Community Expert
February 22, 2017

It look like your in quick mask mode or something with the red effect. Please delete the two alpha channels show the three palettes Layer, Channels and Path.  That something like the background is the current Photoshop target and not in quick mask mode. Capture that screen Run the script and capture the resits.

Today I'm getting your black results with CC 2017 but not other Photoshop versions.

JJMack
Chuck Uebele
Community Expert
Community Expert
February 16, 2017

Try this:

#target photoshop

var doc = activeDocument;

setColors ();

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

    doc.pathItems.select();

    makeSelection ();

    makeChannel ();

}

selRGB ();

doc.selection.deselect();

function selRGB(){

    var idslct = charIDToTypeID( "slct" );

        var desc10 = new ActionDescriptor();

        var idnull = charIDToTypeID( "null" );

            var ref5 = new ActionReference();

            var idChnl = charIDToTypeID( "Chnl" );

            var idChnl = charIDToTypeID( "Chnl" );

            var idRGB = charIDToTypeID( "RGB " );

            ref5.putEnumerated( idChnl, idChnl, idRGB );

        desc10.putReference( idnull, ref5 );

    executeAction( idslct, desc10, DialogModes.NO );

   

    }

function setColors(){

    var idRset = charIDToTypeID( "Rset" );

        var desc3 = new ActionDescriptor();

        var idnull = charIDToTypeID( "null" );

            var ref3 = new ActionReference();

            var idClr = charIDToTypeID( "Clr " );

            var idClrs = charIDToTypeID( "Clrs" );

            ref3.putProperty( idClr, idClrs );

        desc3.putReference( idnull, ref3 );

    executeAction( idRset, desc3, DialogModes.NO ); 

    }

function makeChannel(){

    var idMk = charIDToTypeID( "Mk  " );

        var desc4 = new ActionDescriptor();

        var idNw = charIDToTypeID( "Nw  " );

            var desc5 = new ActionDescriptor();

            var idClrI = charIDToTypeID( "ClrI" );

            var idMskI = charIDToTypeID( "MskI" );

            var idMskA = charIDToTypeID( "MskA" );

            desc5.putEnumerated( idClrI, idMskI, idMskA );

            var idClr = charIDToTypeID( "Clr " );

                var desc6 = new ActionDescriptor();

                var idRd = charIDToTypeID( "Rd  " );

                desc6.putDouble( idRd, 255.000000 );

                var idGrn = charIDToTypeID( "Grn " );

                desc6.putDouble( idGrn, 0.000000 );

                var idBl = charIDToTypeID( "Bl  " );

                desc6.putDouble( idBl, 0.000000 );

            var idRGBC = charIDToTypeID( "RGBC" );

            desc5.putObject( idClr, idRGBC, desc6 );

            var idOpct = charIDToTypeID( "Opct" );

            desc5.putInteger( idOpct, 50 );

        var idChnl = charIDToTypeID( "Chnl" );

        desc4.putObject( idNw, idChnl, desc5 );

    executeAction( idMk, desc4, DialogModes.NO );

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

    var idFl = charIDToTypeID( "Fl  " );

        var desc7 = new ActionDescriptor();

        var idUsng = charIDToTypeID( "Usng" );

        var idFlCn = charIDToTypeID( "FlCn" );

        var idBckC = charIDToTypeID( "BckC" );

        desc7.putEnumerated( idUsng, idFlCn, idBckC );

        var idOpct = charIDToTypeID( "Opct" );

        var idPrc = charIDToTypeID( "#Prc" );

        desc7.putUnitDouble( idOpct, idPrc, 100.000000 );

        var idMd = charIDToTypeID( "Md  " );

        var idBlnM = charIDToTypeID( "BlnM" );

        var idNrml = charIDToTypeID( "Nrml" );

        desc7.putEnumerated( idMd, idBlnM, idNrml );

    executeAction( idFl, desc7, DialogModes.NO );

   

    }

function makeSelection(){

   var idsetd = charIDToTypeID( "setd" );

        var desc12 = new ActionDescriptor();

        var idnull = charIDToTypeID( "null" );

            var ref6 = new ActionReference();

            var idChnl = charIDToTypeID( "Chnl" );

            var idfsel = charIDToTypeID( "fsel" );

            ref6.putProperty( idChnl, idfsel );

        desc12.putReference( idnull, ref6 );

        var idT = charIDToTypeID( "T   " );

            var ref7 = new ActionReference();

            var idPath = charIDToTypeID( "Path" );

            var idOrdn = charIDToTypeID( "Ordn" );

            var idTrgt = charIDToTypeID( "Trgt" );

            ref7.putEnumerated( idPath, idOrdn, idTrgt );

        desc12.putReference( idT, ref7 );

        var idVrsn = charIDToTypeID( "Vrsn" );

        desc12.putInteger( idVrsn, 1 );

        var idvectorMaskParams = stringIDToTypeID( "vectorMaskParams" );

        desc12.putBoolean( idvectorMaskParams, true );

    executeAction( idsetd, desc12, DialogModes.NO );

    }

Victor Padilla
Participating Frequently
February 16, 2017

Chuck, this seems to be a very awesome script, I can see the selections take place and the new channels made, but for some reason, I have a complete black fill. The channels are black and the fill black... is there a way to tell script to make the channel white and fill black? Again, Chuck, you're a genius, but for some reason it's a solid black channel. I can see everything is functioning and I can see through my history, the steps are right, make selection, fill channel... but for some reason it's black.

I know as shown below... if you pick the "Masked Areas" when making a new channel... the alpha channel is a solid black, if you select "selected areas" the new alpha channel made is a white background. Could this be the issue of the script not working depending which option I have set? I tried both ways and the final outcome is a solid black alpha channel.

I wish I knew code as good as you Chuck! that's pretty amazing.

JJMack
Community Expert
Community Expert
February 16, 2017

That script should create a Alpha channel for every path you have you have in the paths palette. It does not do any combining of paths. When done you should have Alpha Channels in the Channels palette and Paths in the Path Palette.  You will be limited to 53 Alpha channels the script will fails if it tries to create a 54 alpha channel. Photoshop supports more Paths than it does Alpha channels.

JJMack
S_Gans
Community Expert
Community Expert
February 14, 2017

That's a great idea for a script - I'd never thought of it, but I like it. Unfortunately, I haven't ever heard of a script that does that (perhaps some coders on here might get interested?). In the meantime, I'd look into making a single action that does what you suggest, and giving it a keyboard shortcut. You'd still have to select each path individually, but then just... I dunno... Shift F11(or anything else) to make the channel, convert to selection and fill?

Yeah - a script would be better, but at least this can take out SOME of the tedium.

Adobe Community Expert / Adobe Certified Instructor
JJMack
Community Expert
Community Expert
February 16, 2017

Be Aware that Photoshop only supports up to 53 Alpha channels  that the limit

JJMack