我一直在做一些关于如何做到这一点的研究,但我还没有找到任何关于这个主题的东西。我的问题是,我想添加一个颜色覆盖到一个给定颜色的图层,但我没有设法做到这一点。我知道有一种使用ActionDescriptors的方法,但我不知道怎么做。我还发现你可以在图层中添加样式,但是我不想使用预设样式。因此,这可能是另一种方式,创建自定义图层样式,然后添加该样式。我想到的另一种方法是简单地填充选择,但为此我必须得到一个精确到我的层的选择(不只是一个正方形,而是层的实际形状),我还试图用javascript编写它。
提前感谢,任何帮助都将不胜感激!
发布于 2020-09-01 16:00:46
您可以从ScriptingListener插件中获取操作管理器代码。
以下是为Add Stroke生成的代码示例
var idsetd = charIDToTypeID( "setd" );
var desc4 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref1 = new ActionReference();
var idPrpr = charIDToTypeID( "Prpr" );
var idLefx = charIDToTypeID( "Lefx" );
ref1.putProperty( idPrpr, idLefx );
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref1.putEnumerated( idLyr, idOrdn, idTrgt );
desc4.putReference( idnull, ref1 );
var idT = charIDToTypeID( "T " );
var desc5 = new ActionDescriptor();
var idScl = charIDToTypeID( "Scl " );
var idPrc = charIDToTypeID( "#Prc" );
desc5.putUnitDouble( idScl, idPrc, 100.000000 );
var idFrFX = charIDToTypeID( "FrFX" );
var desc6 = new ActionDescriptor();
var idenab = charIDToTypeID( "enab" );
desc6.putBoolean( idenab, true );
var idpresent = stringIDToTypeID( "present" );
desc6.putBoolean( idpresent, true );
var idshowInDialog = stringIDToTypeID( "showInDialog" );
desc6.putBoolean( idshowInDialog, true );
var idStyl = charIDToTypeID( "Styl" );
var idFStl = charIDToTypeID( "FStl" );
var idOutF = charIDToTypeID( "OutF" );
desc6.putEnumerated( idStyl, idFStl, idOutF );
var idPntT = charIDToTypeID( "PntT" );
var idFrFl = charIDToTypeID( "FrFl" );
var idSClr = charIDToTypeID( "SClr" );
desc6.putEnumerated( idPntT, idFrFl, idSClr );
var idMd = charIDToTypeID( "Md " );
var idBlnM = charIDToTypeID( "BlnM" );
var idNrml = charIDToTypeID( "Nrml" );
desc6.putEnumerated( idMd, idBlnM, idNrml );
var idOpct = charIDToTypeID( "Opct" );
var idPrc = charIDToTypeID( "#Prc" );
desc6.putUnitDouble( idOpct, idPrc, 100.000000 );
var idSz = charIDToTypeID( "Sz " );
var idPxl = charIDToTypeID( "#Pxl" );
desc6.putUnitDouble( idSz, idPxl, 18.000000 );
var idClr = charIDToTypeID( "Clr " );
var desc7 = new ActionDescriptor();
var idRd = charIDToTypeID( "Rd " );
desc7.putDouble( idRd, 255.000000 );
var idGrn = charIDToTypeID( "Grn " );
desc7.putDouble( idGrn, 0.000000 );
var idBl = charIDToTypeID( "Bl " );
desc7.putDouble( idBl, 0.000000 );
var idRGBC = charIDToTypeID( "RGBC" );
desc6.putObject( idClr, idRGBC, desc7 );
var idoverprint = stringIDToTypeID( "overprint" );
desc6.putBoolean( idoverprint, false );
var idFrFX = charIDToTypeID( "FrFX" );
desc5.putObject( idFrFX, idFrFX, desc6 );
var idLefx = charIDToTypeID( "Lefx" );
desc4.putObject( idT, idLefx, desc5 );
executeAction( idsetd, desc4, DialogModes.NO );很难读懂..。xbytor's xtools包含了一个SLCFix.jsx脚本,可以让它更简洁一些:
function ftn4() {
function cTID(s) { return app.charIDToTypeID(s); };
function sTID(s) { return app.stringIDToTypeID(s); };
var desc4 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putProperty( cTID('Prpr'), cTID('Lefx') );
ref1.putEnumerated( cTID('Lyr '), cTID('Ordn'), cTID('Trgt') );
desc4.putReference( cTID('null'), ref1 );
var desc5 = new ActionDescriptor();
desc5.putUnitDouble( cTID('Scl '), cTID('#Prc'), 100.000000 );
var desc6 = new ActionDescriptor();
desc6.putBoolean( cTID('enab'), true );
desc6.putBoolean( sTID('present'), true );
desc6.putBoolean( sTID('showInDialog'), true );
desc6.putEnumerated( cTID('Styl'), cTID('FStl'), cTID('OutF') );
desc6.putEnumerated( cTID('PntT'), cTID('FrFl'), cTID('SClr') );
desc6.putEnumerated( cTID('Md '), cTID('BlnM'), cTID('Nrml') );
desc6.putUnitDouble( cTID('Opct'), cTID('#Prc'), 100.000000 );
desc6.putUnitDouble( cTID('Sz '), cTID('#Pxl'), 18.000000 );
var desc7 = new ActionDescriptor();
desc7.putDouble( cTID('Rd '), 255.000000 );
desc7.putDouble( cTID('Grn '), 0.000000 );
desc7.putDouble( cTID('Bl '), 0.000000 );
desc6.putObject( cTID('Clr '), cTID('RGBC'), desc7 );
desc6.putBoolean( sTID('overprint'), false );
desc5.putObject( cTID('FrFX'), cTID('FrFX'), desc6 );
desc4.putObject( cTID('T '), cTID('Lefx'), desc5 );
executeAction( cTID('setd'), desc4, DialogModes.NO );
};剩下要做的就是理解哪些值在哪里,并添加参数:
addStroke({
size: 5,
opacity: 50,
color: [255,0,128]
})
function addStroke(data) {
function cTID(s) { return app.charIDToTypeID(s); };
function sTID(s) { return app.stringIDToTypeID(s); };
if (data == undefined) data = {};
if (data.opacity == undefined) data.opacity = 100;
if (data.size == undefined) data.size = 10;
if (data.color == undefined) data.color = [0,0,0];
var desc4 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putProperty( cTID('Prpr'), cTID('Lefx') );
ref1.putEnumerated( cTID('Lyr '), cTID('Ordn'), cTID('Trgt') );
desc4.putReference( cTID('null'), ref1 );
var desc5 = new ActionDescriptor();
desc5.putUnitDouble( cTID('Scl '), cTID('#Prc'), 100);
var desc6 = new ActionDescriptor();
desc6.putBoolean( cTID('enab'), true );
desc6.putBoolean( sTID('present'), true );
desc6.putBoolean( sTID('showInDialog'), true );
desc6.putEnumerated( cTID('Styl'), cTID('FStl'), cTID('OutF') );
desc6.putEnumerated( cTID('PntT'), cTID('FrFl'), cTID('SClr') );
desc6.putEnumerated( cTID('Md '), cTID('BlnM'), cTID('Nrml') );
desc6.putUnitDouble( cTID('Opct'), cTID('#Prc'), data.opacity );
desc6.putUnitDouble( cTID('Sz '), cTID('#Pxl'), data.size );
var desc7 = new ActionDescriptor();
desc7.putDouble( cTID('Rd '), data.color[0] );
desc7.putDouble( cTID('Grn '), data.color[1] );
desc7.putDouble( cTID('Bl '), data.color[2] );
desc6.putObject( cTID('Clr '), cTID('RGBC'), desc7 );
desc6.putBoolean( sTID('overprint'), false );
desc5.putObject( cTID('FrFX'), cTID('FrFX'), desc6 );
desc4.putObject( cTID('T '), cTID('Lefx'), desc5 );
executeAction( cTID('setd'), desc4, DialogModes.NO );
};

https://stackoverflow.com/questions/63669840
复制相似问题