我开始考虑为photoshop编写脚本。我不得不说整个动作脚本代码对我来说有点混乱。围绕整个动作管理器代码有办法吗?
I read that you can include other JS files
也许有人已经为动作功能构建了一个库?
例如,这个图书馆可以取代它:
var idMk = charIDToTypeID( "Mk " );
var desc21 = new ActionDescriptor();
var idNw = charIDToTypeID( "Nw " );
var desc22 = new ActionDescriptor();
var idNm = charIDToTypeID( "Nm " );
desc22.putString( idNm, """Set 1""" );
var idASet = charIDToTypeID( "ASet" );
desc21.putObject( idNw, idASet, desc22 );
executeAction( idMk, desc21, DialogModes.NO );
只有一行:
MakeNewActionSet("Set 1", DialogModes.NO, [optional parameter]);
我找到了one project,但它已经过时了。有人知道这样的事吗?
PS:我在这里的第一篇文章。我希望它不违反规则。
编辑:我实际上找到了一些东西:JSON Action Manager答案 0 :(得分:0)
是。答案是简短的。并参考您的示例:如果MakeNewActionSet是一个函数,您可以有效地将一个替换为另一个函数。
MakeNewActionSet("Set 1", DialogModes.NO);
function MakeNewActionSet(setnumber, dialogue)
{
var idMk = charIDToTypeID( "Mk " );
var desc21 = new ActionDescriptor();
var idNw = charIDToTypeID( "Nw " );
var desc22 = new ActionDescriptor();
var idNm = charIDToTypeID( "Nm " );
desc22.putString( idNm, setnumber ); // set
var idASet = charIDToTypeID( "ASet" );
desc21.putObject( idNw, idASet, desc22 );
executeAction( idMk, desc21, dialogue ); //dialogue
}
虽然动作脚本代码丑陋且难以理解但它完成了这项工作。有时,让脚本监听器更容易记录您想要的内容。其他时候返回并参数化事物是有意义的。例如,我在这里有一个动作脚本代码,它将进行转换(旋转,偏移和缩放)我只是把它作为一个函数包装起来 - 这使得它更容易阅读。
// function transform it
function transformIt(scaleX, scaleY, dx, dy, rot)
{
// =======================================================
var id3561 = charIDToTypeID( "Trnf" );
var desc725 = new ActionDescriptor();
var id3562 = charIDToTypeID( "null" );
var ref430 = new ActionReference();
var id3563 = charIDToTypeID( "Lyr " );
var id3564 = charIDToTypeID( "Ordn" );
var id3565 = charIDToTypeID( "Trgt" );
ref430.putEnumerated( id3563, id3564, id3565 );
desc725.putReference( id3562, ref430 );
var id3566 = charIDToTypeID( "FTcs" );
var id3567 = charIDToTypeID( "QCSt" );
var id3568 = charIDToTypeID( "Qcsa" );
desc725.putEnumerated( id3566, id3567, id3568 );
var id3569 = charIDToTypeID( "Ofst" );
var desc726 = new ActionDescriptor();
var id3570 = charIDToTypeID( "Hrzn" );
var id3571 = charIDToTypeID( "#Pxl" );
desc726.putUnitDouble( id3570, id3571, dx );
var id3572 = charIDToTypeID( "Vrtc" );
var id3573 = charIDToTypeID( "#Pxl" );
desc726.putUnitDouble( id3572, id3573, dy );
var id3574 = charIDToTypeID( "Ofst" );
desc725.putObject( id3569, id3574, desc726 );
var id3575 = charIDToTypeID( "Wdth" );
var id3576 = charIDToTypeID( "#Prc" );
desc725.putUnitDouble( id3575, id3576, scaleX );
var id3577 = charIDToTypeID( "Hght" );
var id3578 = charIDToTypeID( "#Prc" );
desc725.putUnitDouble( id3577, id3578, scaleY );
var id3579 = charIDToTypeID( "Angl" );
var id3580 = charIDToTypeID( "#Ang" );
desc725.putUnitDouble( id3579, id3580, rot );
var id3581 = charIDToTypeID( "Lnkd" );
desc725.putBoolean( id3581, true );
executeAction( id3561, desc725, DialogModes.NO );
}
我希望这会有所帮助。