Skip to main content
Joachim Hiller
Known Participant
May 16, 2018
Answered

get toolpresets for certain tool

  • May 16, 2018
  • 2 replies
  • 3582 views

Hi everybody,

I have a question again. Is it possible to filter from the list of toolpresets only those for a certain tool (not the active tool)

In the code sample you get the name, but is there still a type that you can call to recognize what a toolpreset it is eg. for a stamp, or brush.

function getToolPresetNames() {

    var ref = new ActionReference();

    ref.putEnumerated(charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));

    var appDesc = executeActionGet(ref);

    var List = appDesc.getList(stringIDToTypeID('presetManager'));

    var presetNames = [];

    var list = List.getObjectValue(7).getList(charIDToTypeID('Nm  '));

    for (var i = 0; i < list.count; i++) {

        var str = list.getString(i);

        presetNames.push(str);

    }

    return presetNames;

};

Is there a solution?

Thanks in advance for the help

This topic has been closed for replies.
Correct answer r-bin

If you are using CC2018, you can slightly change the code suggested by SuperMerlin to accurately determine the tool class for the corresponding preset.

alert(getToolPresetNames().join("\n")); 

 

function getToolPresetNames() {   

    var ref = new ActionReference();   

    ref.putProperty(stringIDToTypeID("property"), stringIDToTypeID("presetManager")); 

    ref.putEnumerated(charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));   

    var appDesc = executeActionGet(ref);   

    var List = appDesc.getList(stringIDToTypeID("presetManager"));   

    var presetNames = [];   

    var list = List.getObjectValue(7).getList(charIDToTypeID("Nm  "));   

    var list2 = List.getObjectValue(7).getList(stringIDToTypeID("class"));    

    for (var i = 0; i < list.count; i++) {   

        var str = list.getString(i);   

        var str2 = typeIDToStringID(list2.getClass(i));   

        presetNames.push([str,str2]);   

    }   

    return presetNames;   

};  

2 replies

r-binCorrect answer
Legend
May 16, 2018

If you are using CC2018, you can slightly change the code suggested by SuperMerlin to accurately determine the tool class for the corresponding preset.

alert(getToolPresetNames().join("\n")); 

 

function getToolPresetNames() {   

    var ref = new ActionReference();   

    ref.putProperty(stringIDToTypeID("property"), stringIDToTypeID("presetManager")); 

    ref.putEnumerated(charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));   

    var appDesc = executeActionGet(ref);   

    var List = appDesc.getList(stringIDToTypeID("presetManager"));   

    var presetNames = [];   

    var list = List.getObjectValue(7).getList(charIDToTypeID("Nm  "));   

    var list2 = List.getObjectValue(7).getList(stringIDToTypeID("class"));    

    for (var i = 0; i < list.count; i++) {   

        var str = list.getString(i);   

        var str2 = typeIDToStringID(list2.getClass(i));   

        presetNames.push([str,str2]);   

    }   

    return presetNames;   

};  

Joachim Hiller
Known Participant
May 17, 2018

Thank you so much for your kind help.

r-bin, that looks exactly like what I am looking for, thanks a bunch!

Kukurykus
Legend
May 16, 2018

No time to do it but I think the easiest way is to make a loop over current ToolPresets activating each one at same time. This way each of them will be selected on Tools Bar as well. At the time of each selection during such loop you could then each of them add to existing array, so you had 2 informations at same time, Tool Preset name and a name of tool that represents.

Joachim Hiller
Known Participant
May 16, 2018

Thanks Kukurykus,


how can i get the current ToolPresets?

Do you have an code example for me

Kukurykus
Legend
May 16, 2018

function sTT(v) {return stringIDToTypeID(v)}

(ref = new ActionReference()).putEnumerated(sTT('application'), sTT('ordinal'), sTT('targetEnum'))

lst = executeActionGet(ref).getList(sTT('presetManager')).getObjectValue(7).getList(sTT('name'))

for (pN = [], i = 0; i < lst.count; i++) {

     (ref = new ActionReference()).putName(sTT('toolPreset'), str = lst.getString(i));

     (dsc = new ActionDescriptor()).putReference(sTT('null'), ref)

     executeAction(sTT('select'), dsc, DialogModes.NO);

     (ref = new ActionReference()).putProperty(sTT('property'), sTT('tool')), ref.putClass(sTT('application'))

     pN.push([[(!i ? '' : '\n') + str], [(typeIDToStringID(executeActionGet(ref).getEnumerationType(sTT('tool'))))]])

}

alert(pN)