我正在寻找可以在 Photoshop 中运行的 javascript。理想情况下,该脚本会将一系列剪切路径转换为图层 - 然后用黑色填充图层(由剪切路径定义)。如果可能的话,我希望图层保留剪切路径的名称,并且图层的显示顺序与剪切路径相同。例如,如果第一个剪切路径名为“门”,那么我希望图层 1 为门部分...并将其命名为“门”。此外,最好将选择内容填充为黑色。因此,“门”图层将用黑色填充门选择内容,其他所有内容都将是透明的。
有人可以帮忙吗?
// 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[i].name);
createFill(color);
var fill = app.activeDocument.activeLayer;
fill.name = paths[i].name;
newLayers.push(app.activeDocument.activeLayer);
}
/*
// combine shapes
for(var i = 0; i < newLayers.length; i++)
{
app.activeDocument.activeLayer = newLayers[i];
selectPath(newLayers[i].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 );
};
答案1
颜色选择。
var 颜色 = app.foregroundColor.rgb.hexValue;