微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

检测图案是否存在Photoshop脚本

如何解决检测图案是否存在Photoshop脚本

我正在尝试检测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 );
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。