我是新来的photoshop脚本。我想要加载一个PSD文件,其中有2个垂直照片和3个水平照片,我选择该层。现在,我希望所有选定的层都用VFrame重命名为垂直层,用HFrame和HFrame进行水平存储,并以2v3h_My Name_0001的名称保存,如何做到这一点?有人能分享Photoshop的javascript吗?
发布于 2020-07-24 08:48:01
这是你的第一个问题,欢迎来到StackOverflow。有很多Photoshop脚本指南。这一个涵盖了基本知识。
您想要的脚本需要:
// Switch off any dialog boxes
displayDialogs = DialogModes.NO; // OFF
// call the source document
var srcDoc = app.activeDocument;
var numOfLayers = srcDoc.layers.length;
var vCount = 0;
var hCount = 0;
// main loop
for (var i = numOfLayers -1; i >= 0 ; i--)
{
// get a referenec to each layer as we loop over them
var thisLayer = srcDoc.layers[i];
// get the layer bounds of each layer as you go
srcDoc.activeLayer = thisLayer;
var lb = get_layer_bounds();
// set a variable to for portrait or landscape
var portrait = true;
// if layer is wider than it is long,
// it's landscape
if (lb[0] > lb[1]) portrait = false;
//alert(lb[0] + "," + lb[1] + "\n" + portrait + "\n" +thisLayer.name);
// ignore the background layer
// if there is one
if (thisLayer.isBackgroundLayer == false)
{
if (portrait)
{
srcDoc.artLayers[i].name = "HFrame";
// add one to the horizontal count
hCount +=1
}
else
{
srcDoc.artLayers[i].name = "VFrame";
// add one to the vertical count
vCount+=1
}
}
}
var docName = srcDoc.name.substring(0, srcDoc.name.length -4);
var imgName = vCount + "v" + hCount + "h_" + docName + "_0001.psd";
duplicateIt(imgName);
// Set Display Dialogs back to normal
displayDialogs = DialogModes.ALL; // NORMAL
// function GET LAYER BOUNDS ()
// ----------------------------------------------------------------
function get_layer_bounds()
{
var x = parseFloat(app.activeDocument.activeLayer.bounds[0]);
var y = parseFloat(app.activeDocument.activeLayer.bounds[1]);
var x1 = parseFloat(app.activeDocument.activeLayer.bounds[2]);
var y1 = parseFloat(app.activeDocument.activeLayer.bounds[3]);
var selW = parseFloat(x1-x);
var selH = parseFloat(y1-y);
// return the results as an array
return [selW, selH];
}
function duplicateIt(str)
{
// duplicate image into new document
if (arguments.length == 0) str = "temp";
var id428 = charIDToTypeID( "Dplc" );
var desc92 = new ActionDescriptor();
var id429 = charIDToTypeID( "null" );
var ref27 = new ActionReference();
var id430 = charIDToTypeID( "Dcmn" );
var id431 = charIDToTypeID( "Ordn" );
var id432 = charIDToTypeID( "Frst" );
ref27.putEnumerated( id430, id431, id432 );
desc92.putReference( id429, ref27 );
var id433 = charIDToTypeID( "Nm " );
desc92.putString( id433, str ); // name
executeAction( id428, desc92, DialogModes.NO );
}
https://stackoverflow.com/questions/62632015
复制相似问题