我从 https://forums.adobe.com/thread/1536677 获取了一些代码,这样可以得到图层的边界
function getLBounds(){
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Lyr ") , charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
desc1 = executeActionGet(ref);
desc1 = desc1.getObjectValue(stringIDToTypeID('bounds'));
desc1Top = desc1.getUnitDoubleValue(stringIDToTypeID('top'));
desc1Bottom = desc1.getUnitDoubleValue(stringIDToTypeID('bottom'));
desc1Left = desc1.getUnitDoubleValue(stringIDToTypeID('left'));
desc1Right = desc1.getUnitDoubleValue(stringIDToTypeID('right'));
rObj = {top:desc1Top, left:desc1Left, bottom:desc1Bottom, right:desc1Right};
return rObj;
}
我想知道如何编写或使用ScriptListener.8li来生成这个,我可以使用ScriptListener.8li进行一些转换等,但我不知道如何获取信息。非常感谢!
// =======================================================
var idTrnf = charIDToTypeID( "Trnf" );
var desc2 = new ActionDescriptor();
var idFTcs = charIDToTypeID( "FTcs" );
var idQCSt = charIDToTypeID( "QCSt" );
var idQcsa = charIDToTypeID( "Qcsa" );
desc2.putEnumerated( idFTcs, idQCSt, idQcsa );
var idOfst = charIDToTypeID( "Ofst" );
var desc3 = new ActionDescriptor();
var idHrzn = charIDToTypeID( "Hrzn" );
var idPxl = charIDToTypeID( "#Pxl" );
desc3.putUnitDouble( idHrzn, idPxl, 0.000000 );
var idVrtc = charIDToTypeID( "Vrtc" );
var idPxl = charIDToTypeID( "#Pxl" );
desc3.putUnitDouble( idVrtc, idPxl, 0.013677 );
var idOfst = charIDToTypeID( "Ofst" );
desc2.putObject( idOfst, idOfst, desc3 );
var idWdth = charIDToTypeID( "Wdth" );
var idPrc = charIDToTypeID( "#Prc" );
desc2.putUnitDouble( idWdth, idPrc, 86.486860 );
var idHght = charIDToTypeID( "Hght" );
var idPrc = charIDToTypeID( "#Prc" );
desc2.putUnitDouble( idHght, idPrc, -88.215838 );
var idSkew = charIDToTypeID( "Skew" );
var desc4 = new ActionDescriptor();
var idHrzn = charIDToTypeID( "Hrzn" );
var idAng = charIDToTypeID( "#Ang" );
desc4.putUnitDouble( idHrzn, idAng, 0.033079 );
var idVrtc = charIDToTypeID( "Vrtc" );
var idAng = charIDToTypeID( "#Ang" );
desc4.putUnitDouble( idVrtc, idAng, 0.000000 );
var idPnt = charIDToTypeID( "Pnt " );
desc2.putObject( idSkew, idPnt, desc4 );
var idAngl = charIDToTypeID( "Angl" );
var idAng = charIDToTypeID( "#Ang" );
desc2.putUnitDouble( idAngl, idAng, -170.957285 );
executeAction( idTrnf, desc2, DialogModes.NO );
PS:最后的代码是由ScriptListener.8li生成的,我想知道如何生成第一个函数getLBounds。
最佳答案
有一个四字母脚本监听器代码的列表。例如,“Trnf”是变换。 Google 是您的 friend 。
但有时检查每个命令并依次查看每个参数很容易。我可以看到你的代码不按比例旋转和缩小图像层,增加了一点倾斜和一点点偏移。
// =======================================================
var idTrnf = charIDToTypeID( "Trnf" );
var desc2 = new ActionDescriptor();
var idFTcs = charIDToTypeID( "FTcs" );
var idQCSt = charIDToTypeID( "QCSt" );
var idQcsa = charIDToTypeID( "Qcsa" );
desc2.putEnumerated( idFTcs, idQCSt, idQcsa );
var idOfst = charIDToTypeID( "Ofst" );
var desc3 = new ActionDescriptor();
var idHrzn = charIDToTypeID( "Hrzn" );
var idPxl = charIDToTypeID( "#Pxl" );
desc3.putUnitDouble( idHrzn, idPxl, 0.000000 ); // X transform offest amount in pixels
var idVrtc = charIDToTypeID( "Vrtc" );
var idPxl = charIDToTypeID( "#Pxl" );
desc3.putUnitDouble( idVrtc, idPxl, 0.013677 ); // Y transform offest amount in pixels
var idOfst = charIDToTypeID( "Ofst" );
desc2.putObject( idOfst, idOfst, desc3 );
var idWdth = charIDToTypeID( "Wdth" );
var idPrc = charIDToTypeID( "#Prc" );
desc2.putUnitDouble( idWdth, idPrc, 86.486860 ); // Width amount %
var idHght = charIDToTypeID( "Hght" );
var idPrc = charIDToTypeID( "#Prc" );
desc2.putUnitDouble( idHght, idPrc, -88.215838 ); // Height amount %
var idSkew = charIDToTypeID( "Skew" );
var desc4 = new ActionDescriptor();
var idHrzn = charIDToTypeID( "Hrzn" );
var idAng = charIDToTypeID( "#Ang" );
desc4.putUnitDouble( idHrzn, idAng, 0.033079 ); //skew horizontal amount
var idVrtc = charIDToTypeID( "Vrtc" );
var idAng = charIDToTypeID( "#Ang" );
desc4.putUnitDouble( idVrtc, idAng, 0.000000 ); // skew vertical amount
var idPnt = charIDToTypeID( "Pnt " );
desc2.putObject( idSkew, idPnt, desc4 );
var idAngl = charIDToTypeID( "Angl" );
var idAng = charIDToTypeID( "#Ang" );
desc2.putUnitDouble( idAngl, idAng, -170.957285 ); // rotational angle amount= 9.042715
executeAction( idTrnf, desc2, DialogModes.NO );
大多数参数的顺序与 Photoshop 菜单中显示的顺序相同。这是一个消除它们以弄清楚每个人的作用的过程。
关于javascript - 如何编写这样的 Photoshop Action 管理器代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45009039/