问题
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