你只需要修改你的代码:
var doc = app.activeDocument;
doc.activeLayer = doc.artLayers.getByName("iPad");
这会将活动层设置为名为“ipad”的层。这是选择图层(按名称)然后进一步处理图像的标准方法,在您的情况下调整它的大小。显然,我不知道 PSD 中还有什么可以选择或忽略的层。另一种方法是遍历所有层并处理它们。
这里有两个有用的功能:一个会选择图层蒙版有一个,另一个会取消选择图层蒙版并返回位图图层
// FUNCTION DESELECT LAYER MASK AND SELECT IMAGE LAYER
// --------------------------------------------------------
function deselectLayerMaskAndSelectImageLayer()
{
// =======================================================
var id248 = charIDToTypeID( "slct" );
var desc48 = new ActionDescriptor();
var id249 = charIDToTypeID( "null" );
var ref36 = new ActionReference();
var id250 = charIDToTypeID( "Chnl" );
var id251 = charIDToTypeID( "Chnl" );
var id252 = charIDToTypeID( "RGB " );
ref36.putEnumerated( id250, id251, id252 );
desc48.putReference( id249, ref36 );
var id253 = charIDToTypeID( "MkVs" );
desc48.putBoolean( id253, false );
executeAction( id248, desc48, DialogModes.NO );
}
// FUNCTION SELECT MASK
// --------------------------------------------------------
function selectMask(LayerName)
{
try
{
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID('Chnl'), charIDToTypeID('Chnl'), charIDToTypeID('Msk ') );
ref.putName( charIDToTypeID('Lyr '), LayerName );
desc.putReference( charIDToTypeID('null'), ref );
desc.putBoolean( charIDToTypeID('MkVs'), true );
executeAction( charIDToTypeID('slct'), desc, DialogModes.NO );
// =======================================================
var id1083 = charIDToTypeID( "setd" );
var desc238 = new ActionDescriptor();
var id1084 = charIDToTypeID( "null" );
var ref161 = new ActionReference();
var id1085 = charIDToTypeID( "Chnl" );
var id1086 = charIDToTypeID( "fsel" );
ref161.putProperty( id1085, id1086 );
desc238.putReference( id1084, ref161 );
var id1087 = charIDToTypeID( "T " );
var ref162 = new ActionReference();
var id1088 = charIDToTypeID( "Chnl" );
var id1089 = charIDToTypeID( "Ordn" );
var id1090 = charIDToTypeID( "Trgt" );
ref162.putEnumerated( id1088, id1089, id1090 );
desc238.putReference( id1087, ref162 );
executeAction( id1083, desc238, DialogModes.NO );
}
catch(e)
{
//alert(e)
//alert( "This layer has NO layer mask!" );
activeDocument.selection.deselect();
}
} //end function