问题描述
我正在尝试检测Photoshop中是否存在图案名称,但是现在我无法执行该操作,任何人都知道如何执行此操作? 现在我有这个:
function selectPattern(ptrn) {
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putName(charIDToTypeID('Ptrn'),ptrn );
desc.putReference( charIDToTypeID( "null" ),ref );
executeAction( charIDToTypeID( "slct" ),desc,DialogModes.NO );
}
selectPattern('Gauze');
预先感谢
解决方法
它与this问题中的脚本相同。您可以从Application
动作参考中获取不同预设的列表:
var patternsNames = getPresetList(4);
function getPresetList(presetIndex)
{
// presetIndex: 0 to 7
// 0: Brushes
// 1: Swatches
// 2: Gradients
// 3: Styles
// 4: Patterns
// 5: Contours
// 6: Custom Shapes
// 7: Tools
var presetNames = [];
var ref = new ActionReference();
ref.putProperty(stringIDToTypeID("property"),stringIDToTypeID("presetManager"));
ref.putEnumerated(stringIDToTypeID("application"),stringIDToTypeID("ordinal"),stringIDToTypeID("targetEnum"));
var desc = executeActionGet(ref);
var list = desc.getList(stringIDToTypeID("presetManager"));
var nameList = list.getObjectValue(presetIndex).getList(stringIDToTypeID("name"));
for (var nameIndex = 0; nameIndex < nameList.count; nameIndex++)
{
var n = nameList.getString(nameIndex);
presetNames.push(n);
}
return presetNames;
};
,
虽然这不能直接回答您的问题,但这可能对您有用:
您可以使用scriptListener找出模式的ID。
// call the source document
var srcDoc = app.activeDocument;
fillWithPattern("456e6678-5dd6-5046-9e0c-12871fb51bb0");
function fillWithPattern (patternid)
{
// =======================================================
var idFl = charIDToTypeID( "Fl " );
var desc126 = new ActionDescriptor();
var idFrom = charIDToTypeID( "From" );
var desc127 = new ActionDescriptor();
var idHrzn = charIDToTypeID( "Hrzn" );
var idPxl = charIDToTypeID( "#Pxl" );
desc127.putUnitDouble( idHrzn,idPxl,100.0 ); // x fill point
var idVrtc = charIDToTypeID( "Vrtc" );
var idPxl = charIDToTypeID( "#Pxl" );
desc127.putUnitDouble( idVrtc,100.0 ); //y fill point
var idPnt = charIDToTypeID( "Pnt " );
desc126.putObject( idFrom,idPnt,desc127 );
var idTlrn = charIDToTypeID( "Tlrn" );
desc126.putInteger( idTlrn,0 );
var idUsng = charIDToTypeID( "Usng" );
var idFlCn = charIDToTypeID( "FlCn" );
var idPtrn = charIDToTypeID( "Ptrn" );
desc126.putEnumerated( idUsng,idFlCn,idPtrn );
var idPtrn = charIDToTypeID( "Ptrn" );
var desc128 = new ActionDescriptor();
var idNm = charIDToTypeID( "Nm " );
desc128.putString( idNm,"" ); // pattern name (ignored)
var idIdnt = charIDToTypeID( "Idnt" );
desc128.putString( idIdnt,patternid ); //pattern ID
var idPtrn = charIDToTypeID( "Ptrn" );
desc126.putObject( idPtrn,idPtrn,desc128 );
executeAction( idFl,desc126,DialogModes.NO );
}