Copy link to clipboard
Copied
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.
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 w
...Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Be Aware that Photoshop only supports up to 53 Alpha channels that the limit
Copy link to clipboard
Copied
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 );
}
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
I have Masked area selected.
Copy link to clipboard
Copied
This is really nice! I believe I'll borrow it too, if you don't mind. I certainly don't have as many path needs as @MaDPROpHet
But I can see this as being very handy!
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
I did some more testing the problem is ether with some Photoshop setting or a scripting problem in some Photoshop versions. I normally use CC 2014 it seems to have the fewest bugs. Here is what a see testing the script on the same paths using the different versions of Photoshop I have installed. CS6, CC 2015 and CC 2017 fails to work correctly. Where CS2 ,CC, CC 2014, CS 2015.5 worked correctly. There are Bugs in all versions of Photoshop....
CS6
CC
CC 2014
cc2015
CC2015.5
CC 2017
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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) {}
}
Copy link to clipboard
Copied
JJMack it worked! Thank you and Chuck Uebele, you guys rock... this script will save us so much time, again my thanks to you two.
Copy link to clipboard
Copied
Hi
Use this code if needed...
#target photoshop
var docRef = app.activeDocument;
var sRGB= docRef.activeChannels;
for(var i=0;i<docRef.pathItems.length;i++){
docRef.pathItems.makeSelection(0.3,true,SelectionType.REPLACE);
makeChn(docRef,docRef.pathItems.name);
docRef.selection.deselect();
docRef.activeChannels=sRGB;
}
function makeChn(docRef,chnName){
var chanRef = docRef.channels.add();
chanRef.name = chnName;
chanRef.kind = ChannelType.SELECTEDAREA;
docRef.selection.store( docRef.channels.getByName(chnName), SelectionType.EXTEND );
}
-yajiv
Copy link to clipboard
Copied
Yes that code work with all version of Photoshop I have installed and is the cleanest posted.
It seems strange how Photoshop work at. If I run the script twice it will generate additional Alpha channels that will have the same channel name but the channels will be wrong they will be all white. However if I change the script to generate random channel names the new alpha channels will be like the path. If I change the script to away create the same Alpha channel name. The correct number of alpha channels will be created however all will be white but the first one all path which will have all the path merged in that one.
But that is what happens when duplicate names are allowed. While Path name need to be unique, Channel names and layer names do not have to be unique and get by name or select name will get the first one.
#target photoshop
var docRef = app.activeDocument;
var sRGB= docRef.activeChannels;
for(var i=0;i<docRef.pathItems.length;i++){
docRef.pathItems.makeSelection(0.3,true,SelectionType.REPLACE);
// makeChn(docRef,docRef.pathItems.name);
makeChn(docRef,"Alpha " + (Math.floor(Math.random() * 999)));
docRef.selection.deselect();
docRef.activeChannels=sRGB;
}
function makeChn(docRef,chnName){
var chanRef = docRef.channels.add();
chanRef.name = chnName;
chanRef.kind = ChannelType.SELECTEDAREA;
docRef.selection.store( docRef.channels.getByName(chnName), SelectionType.EXTEND );
}
#target photoshop
var docRef = app.activeDocument;
var sRGB= docRef.activeChannels;
for(var i=0;i<docRef.pathItems.length;i++){
docRef.pathItems.makeSelection(0.3,true,SelectionType.REPLACE);
// makeChn(docRef,docRef.pathItems.name);
makeChn(docRef,"Alpha");
docRef.selection.deselect();
docRef.activeChannels=sRGB;
}
function makeChn(docRef,chnName){
var chanRef = docRef.channels.add();
chanRef.name = chnName;
chanRef.kind = ChannelType.SELECTEDAREA;
docRef.selection.store( docRef.channels.getByName(chnName), SelectionType.EXTEND );
}
The following Script will allow you to run the script more than once so you can add additional Path and create Alpha channels for them. You can also un-comment the commented out statement to include creating an alpha with the paths merged
#target photoshop
var docRef = app.activeDocument;
var sRGB= docRef.activeChannels;
for(var i=0;i<docRef.pathItems.length;i++){
docRef.pathItems.makeSelection(0.3,true,SelectionType.REPLACE);
// makeChn(docRef,"Alpha Merged Paths");
makeChn(docRef,docRef.pathItems.name);
docRef.selection.deselect();
docRef.activeChannels=sRGB;
}
function makeChn(docRef,chnName){
try { docRef.selection.store( docRef.channels.getByName(chnName), SelectionType.EXTEND );}
catch(e) {
var chanRef = docRef.channels.add();
chanRef.name = chnName;
chanRef.kind = ChannelType.SELECTEDAREA;
docRef.selection.store( docRef.channels.getByName(chnName), SelectionType.EXTEND );
}
}
Copy link to clipboard
Copied
Final cleaned up script!
#target photoshop
if (!documents.length) alert('There are no documents open.', 'No Document');
else { app.activeDocument.suspendHistory('Alpha Channels for Path','main()');}
///////////////////////////////////////////////////////////////////////////////
// main function //
//////////////////////////////////////////////////////////////////////////////
function main() {
var docRef = app.activeDocument;
var sRGB= docRef.activeChannels;
for(var i=0;i<docRef.pathItems.length;i++){
docRef.pathItems.makeSelection(0.3,true,SelectionType.REPLACE);
makeChn(docRef,"Alpha Merged Paths");
makeChn(docRef,docRef.pathItems.name);
}
docRef.selection.deselect();
docRef.activeChannels=sRGB;
}
///////////////////////////////////////////////////////////////////////////////
// Helper function //
//////////////////////////////////////////////////////////////////////////////
function makeChn(docRef,chnName){
try { docRef.selection.store( docRef.channels.getByName(chnName), SelectionType.EXTEND );}
catch(e) {
var chanRef = docRef.channels.add();
chanRef.name = chnName;
chanRef.kind = ChannelType.SELECTEDAREA;
docRef.selection.store( docRef.channels.getByName(chnName), SelectionType.EXTEND );
}
}
Copy link to clipboard
Copied
Thank You JJ Mack, I appreciate all your help! very much appreciated!
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
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.