如何使用带有photoshop脚本的预定义模式填充选区

时间:2017-06-17 09:20:08

标签: scripting photoshop

如何使用带有photoshop脚本的预定义模式填充选区

var docRef = app.documents.add()

var layerRef =docRef.layerSets.add();

layerRef.kind = LayerKind.PATTERNFILL;

docRef.selection.selectAll();

docRef.selection.fill(pattern?);

1 个答案:

答案 0 :(得分:0)

您需要一个模式ID - 最简单的方法是使用scriptListener并找出快速测试填充并检查侦听器代码。这是一个例子:

var myPattern = "d5706459-5277-11e7-aad4-ff82069d78d5";
fill_with_pattern(myPattern)

function fill_with_pattern(patternID)
{
    var idFl = charIDToTypeID( "Fl  " );
    var desc1283 = new ActionDescriptor();
    var idUsng = charIDToTypeID( "Usng" );
    var idFlCn = charIDToTypeID( "FlCn" );
    var idPtrn = charIDToTypeID( "Ptrn" );
    desc1283.putEnumerated( idUsng, idFlCn, idPtrn );
    var idPtrn = charIDToTypeID( "Ptrn" );
    var desc1284 = new ActionDescriptor();
    var idNm = charIDToTypeID( "Nm  " );
    desc1284.putString( idNm, """40x40""" ); // id name
    var idIdnt = charIDToTypeID( "Idnt" );
    desc1284.putString( idIdnt, patternID );
    var idPtrn = charIDToTypeID( "Ptrn" );
    desc1283.putObject( idPtrn, idPtrn, desc1284 );
    var idOpct = charIDToTypeID( "Opct" );
    var idPrc = charIDToTypeID( "#Prc" );
    desc1283.putUnitDouble( idOpct, idPrc, 100.000000 ); //opacity
    var idMd = charIDToTypeID( "Md  " );
    var idBlnM = charIDToTypeID( "BlnM" );
    var idNrml = charIDToTypeID( "Nrml" );
    desc1283.putEnumerated( idMd, idBlnM, idNrml );
    executeAction( idFl, desc1283, DialogModes.NO );
}

我认为您可以通过名称而不是ID来调用模式 - 但我没有成功管理它。如果您尝试使用预先存在的模式,比如Bubbles,您将获得如下代码:

desc1297.putString( idNm, """$$$/Presets/Patterns/Patterns_pat/Bubbles=Bubbles""" );
var idIdnt = charIDToTypeID( "Idnt" );
desc1297.putString( idIdnt, """b7334da0-122f-11d4-8bb5-e27e45023b5f""" );