Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am looking for a javascript that can run within Photoshop. Ideally, the script will convert a series of clipping paths to layers - and then fill the layer (defined by the clipping path) with black. If possible, I would like to have the layer retain the name of the clipping path, and also for the layers to appear in the same order as the clipping paths. For instance, if the first clipping path was named "Door," then I would like Layer 1 to be the door section...and for it to be called "Door". Additionally, it would be nice to have the selection to be filled with black. So, the "Door" layer would have the door selection filled with black and everything else would be transparent.

Can somebody help?

// Create solid fills based on paths array

// hex value: FFFFFF is white, FF0000 is red, and so on.
var color = "000000";
var paths = app.activeDocument.pathItems;
var pathsLength = paths.length;
var newLayers = [];

// create solid fill layers
for(var i = 0; i < pathsLength; i++)
   var fill = app.activeDocument.activeLayer; = paths[i].name;

// combine shapes
for(var i = 0; i < newLayers.length; i++)
   app.activeDocument.activeLayer = newLayers[i];
   selectPath(newLayers[i].name + " Shape Path");

// select path by name
function selectPath(name)
   var idslct = charIDToTypeID( "slct" );
   var desc50 = new ActionDescriptor();
   var idnull = charIDToTypeID( "null" );
   var ref34 = new ActionReference();
   var idPath = charIDToTypeID( "Path" );
   ref34.putName( idPath, name );
   desc50.putReference( idnull, ref34 );
   executeAction( idslct, desc50, DialogModes.NO );

// create solid fill based on selected path items
function createFill(hexValue)
   var color = new SolidColor();
   color.rgb.hexValue = hexValue != undefined ?  hexValue : "000000";

   var idMk = charIDToTypeID( "Mk  " );
   var desc51 = new ActionDescriptor();
   var idnull = charIDToTypeID( "null" );
   var ref35 = new ActionReference();
   var idcontentLayer = stringIDToTypeID( "contentLayer" );
   ref35.putClass( idcontentLayer );
   desc51.putReference( idnull, ref35 );
   var idUsng = charIDToTypeID( "Usng" );
   var desc52 = new ActionDescriptor();
   var idType = charIDToTypeID( "Type" );
   var desc53 = new ActionDescriptor();
   var idClr = charIDToTypeID( "Clr " );
   var desc54 = new ActionDescriptor();
   var idRd = charIDToTypeID( "Rd  " );
   desc54.putDouble( idRd, );
   var idGrn = charIDToTypeID( "Grn " );
   desc54.putDouble( idGrn, );
   var idBl = charIDToTypeID( "Bl  " );
   desc54.putDouble( idBl, );
   var idRGBC = charIDToTypeID( "RGBC" );
   desc53.putObject( idClr, idRGBC, desc54 );
   var idsolidColorLayer = stringIDToTypeID( "solidColorLayer" );
   desc52.putObject( idType, idsolidColorLayer, desc53 );
   var idcontentLayer = stringIDToTypeID( "contentLayer" );
   desc51.putObject( idUsng, idcontentLayer, desc52 );
   executeAction( idMk, desc51, DialogModes.NO );

// select color fill items and combine shapes
function combineShapes()
   var idslct = charIDToTypeID( "slct" );
   var desc55 = new ActionDescriptor();
   var idnull = charIDToTypeID( "null" );
   var ref36 = new ActionReference();
   var idPath = charIDToTypeID( "Path" );
   var idPath = charIDToTypeID( "Path" );
   var idvectorMask = stringIDToTypeID( "vectorMask" );
   ref36.putEnumerated( idPath, idPath, idvectorMask );
   var idLyr = charIDToTypeID( "Lyr " );
   var idOrdn = charIDToTypeID( "Ordn" );
   var idTrgt = charIDToTypeID( "Trgt" );
   ref36.putEnumerated( idLyr, idOrdn, idTrgt );
   desc55.putReference( idnull, ref36 );
   executeAction( idslct, desc55, DialogModes.NO );
share|improve this question
Originally, I was planning on using actions. However, I cannot seem to find a way to have the path name become the layer name. Additionally, I'm looking for something that can convert multiple paths to layers in seconds. Thanks for your response, though. The second link was useful - as I found the script that exports the layers to PNGs quite useful. However, that doesn't really solve my issue. – bryan akers Jul 1 '13 at 18:54
I have the solution and have added the code above, for anyone who is looking for the answer. – bryan akers Jul 8 '13 at 18:56

Color Selection.

var color = app.foregroundColor.rgb.hexValue;

share|improve this answer
Please expand on your answer, this is not very helpful except for insiders. How is this the answer to the question? – user 99572 is fine Aug 24 '13 at 9:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .