How check if photoshop brush exist programmatically

╄→гoц情女王★ 提交于 2021-01-29 05:11:21

问题


I'm trying to create a Photoshop Panel for some actions, but I want to know how can I check if the brush already exist in photoshop and if not exist to call a function to install it before the action can be used, I already know how install it, and how run the actions, but I still got some issues detecting if the brush exist on Mac/Windows environment.

Any tips about how do this using Javascript? (JSX)


回答1:


You can get lists of brush or tool presets using this AM snippet. Note that several Brush Presets could have the same name.

var brushesList = getPresetList(0);
var brushName = 'Preset_55890'

for (var i = 0; i < brushesList.length; i++)
{
  if (brushesList[i] == brushName)
  {
    alert('found');
    break;
  }
}

// presetIndex: 0 to 7
// 0: Brush Presets
// 7: Tool presets

function getPresetList(presetIndex)
{
  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++)
  {
    presetNames.push(nameList.getString(nameIndex));
  }
  return presetNames;
};


来源:https://stackoverflow.com/questions/64094460/how-check-if-photoshop-brush-exist-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!