Hello all,
I'm looking for some assistance with a script that will convert clipping paths to layers - and then apply a black fill to the clipping path shape. For example, a path named "Door" would become a layer named "Door"...and the door shape would be filled with black. If multiple paths existed in the file, then the script would convert all of them until finished.
Does this sound scriptable?
Thanks in advance...
Paths to Layers with Black Fill
-
Mike Hale
Paths to Layers with Black Fill
I am not clear what you want to do. Photoshop only allows one path to be set as the clipping path.
-
Halcyon
Paths to Layers with Black Fill
I apologize if I used the incorrect term - I'm thinking of paths that are in the Paths palette.
-
pattesdours
Paths to Layers with Black Fill
Give this a try. It's based on ScriptingListener output. I tried combining the resulting path shapes, but it doesn't work when batching (couldn't find why)
Code: Select all// 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++)
{
selectPath(paths.name);
createFill(color);
var fill = app.activeDocument.activeLayer;
fill.name = paths.name;
newLayers.push(app.activeDocument.activeLayer);
}
/*
// combine shapes
for(var i = 0; i < newLayers.length; i++)
{
app.activeDocument.activeLayer = newLayers;
selectPath(newLayers.name + " Shape Path");
combineShapes();
}
*/
// 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, color.rgb.red );
var idGrn = charIDToTypeID( "Grn " );
desc54.putDouble( idGrn, color.rgb.green );
var idBl = charIDToTypeID( "Bl " );
desc54.putDouble( idBl, color.rgb.blue );
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 );
};
Code: Select all// 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++)
{
selectPath(paths.name);
createFill(color);
var fill = app.activeDocument.activeLayer;
fill.name = paths.name;
newLayers.push(app.activeDocument.activeLayer);
}
/*
// combine shapes
for(var i = 0; i < newLayers.length; i++)
{
app.activeDocument.activeLayer = newLayers;
selectPath(newLayers.name + " Shape Path");
combineShapes();
}
*/
// 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, color.rgb.red );
var idGrn = charIDToTypeID( "Grn " );
desc54.putDouble( idGrn, color.rgb.green );
var idBl = charIDToTypeID( "Bl " );
desc54.putDouble( idBl, color.rgb.blue );
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 );
};
-
Halcyon
Paths to Layers with Black Fill
This could easily be something that I'm not aware of....but when I tried to run the script in PS, I'm receiving an "Error 8: Syntax error. Line: 1 -> {\rtf1\ansi\ansicpg1252\cocoartf1187\cocoasubrtf370" error. Now, I have the scripting experience of a fruit fly...so if there is something that I need to change, please just point me in the right direction.
For the record, I don't really want the path shapes to be combined. I'm looking for multiple paths to become multiple layers. A "Door" path would become a "Door" layer...then a "Fascia" path would become a "Fascia" layer. The script would ideally just convert them all.
Thanks!
For the record, I don't really want the path shapes to be combined. I'm looking for multiple paths to become multiple layers. A "Door" path would become a "Door" layer...then a "Fascia" path would become a "Fascia" layer. The script would ideally just convert them all.
Thanks!
-
Mike Hale
Paths to Layers with Black Fill
You need to make sure whatever you paste the script into can save a file as plain text. You are getting that error because the file was saved as rich text which includes extra formatting codes.
If you are not sure what program will save plain text you can use ExtendScript Toolkit. It is already installed on your system and is an editor/debugger for scripting Abode apps.
If you are not sure what program will save plain text you can use ExtendScript Toolkit. It is already installed on your system and is an editor/debugger for scripting Abode apps.
-
Halcyon
Paths to Layers with Black Fill
Thanks for that, Mike.
On first pass, the script worked flawlessly. Thank you!
On first pass, the script worked flawlessly. Thank you!