15 Replies Latest reply on May 17, 2018 12:05 AM by Joachim Hiller

    get toolpresets for certain tool

    Joachim Hiller Level 1

      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

        • 1. Re: get toolpresets for certain tool
          Kukurykus Adobe Community Professional

          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.

          1 person found this helpful
          • 2. Re: get toolpresets for certain tool
            Joachim Hiller Level 1

            Thanks Kukurykus,


            how can i get the current ToolPresets?

            Do you have an code example for me

            • 3. Re: get toolpresets for certain tool
              Kukurykus Adobe Community Professional
              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)
              
              • 4. Re: get toolpresets for certain tool
                Joachim Hiller Level 1

                Thanks Kukurykus,

                 

                does that only work if, the checkbox for "Current Tool only" unchecked?

                Otherwise I have an error in line 9.

                 

                German Version

                2018-05-16_11-34-11.png2018-05-16_11-38-03.png

                • 5. Re: get toolpresets for certain tool
                  SuperMerlin Level 5
                  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("title"));   
                      for (var i = 0; i < list.count; i++) {  
                          var str = list.getString(i);  
                          var str2 = list2.getString(i);  
                          presetNames.push([str,str2]);  
                      }  
                      return presetNames;  
                  }; 
                  
                  
                  
                  • 6. Re: get toolpresets for certain tool
                    SuperMerlin Level 5

                    Here is an example script to select tool presets.

                    N.B. It is noot perfect as the Type tools have non standard names compared with the rest of the tools, so you would have to add extra checks.

                     

                    #target photoshop;
                    app.bringToFront();
                    
                    var toolPresets = getToolPresetNames();
                    var tools =[];
                    for(var x in toolPresets){tools.push(toolPresets[x][1].toString());};
                    tools = ReturnUniqueSortedList(tools);
                    var win = new Window("dialog","Preset Tools",undefined,{closeButton: true}); 
                    win.p1= win.add("panel", undefined, undefined, {borderStyle:"black"}); 
                    win.g1 = win.p1.add("group");
                    win.g1.orientation = "row";
                    win.title = win.g1.add("statictext",undefined,"Tool Presets");
                    var g = win.title.graphics;
                    g.font = ScriptUI.newFont("Georgia","BOLDITALIC",22);
                    win.g10 = win.p1.add("group");
                    win.g10.orientation = "row";
                    win.g10.dd1 = win.g10.add("dropdownlist");
                    win.g10.dd1.preferredSize=[200,20];
                    for(var p in tools){win.g10.dd1.add("item",tools[p].toString());}
                    win.g10.dd2 = win.g10.add("dropdownlist");
                    win.g10.dd2.preferredSize=[200,20];
                    var tmp=[];
                    for(var z in toolPresets){
                        if(toolPresets[z][1].toString() == tools[0].toString()) tmp.push(toolPresets[z][0]);
                        }
                    tmp=tmp.sort();
                    for(var y in tmp){win.g10.dd2.add("item",tmp[y].toString());}
                    win.g10.dd1.selection=0;
                    win.g10.dd2.selection=0;
                    win.g10.dd1.onChange = function() {
                    tmp=[];
                    win.g10.dd2.removeAll();
                    for(var z in toolPresets){
                        if(toolPresets[z][1].toString() == tools[win.g10.dd1.selection.index].toString()) tmp.push(toolPresets[z][0]);
                        }
                    tmp=tmp.sort();
                    for(var y in tmp){win.g10.dd2.add("item",tmp[y].toString());}
                    win.g10.dd2.selection=0;
                    }
                    win.g100 = win.p1.add("group");
                    win.g100.orientation = "row";
                    win.g100.bu1 = win.g100.add("button",undefined,"Use Preset");
                    win.g100.bu2 = win.g100.add("button",undefined,"Cancel");
                    win.g100.bu1.preferredSize=[150,40];
                    win.g100.bu2.preferredSize=[150,40];
                    win.g100.bu1.onClick=function(){
                    win.close(0);
                    var selTool = win.g10.dd1.selection.text.toString().replace(/\s+/g,"");
                    selTool = selTool.charAt(0).toLowerCase() + selTool.substr(1);
                    if(selTool == "verticalTypeTool") selTool ="typeVerticalCreateOrEditTool";
                    selectTool(selTool);
                    selectToolPreset(win.g10.dd2.selection.text.toString());
                    }
                    win.show();
                    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("title"));   
                        for (var i = 0; i < list.count; i++) {  
                            var str = list.getString(i);  
                            var str2 = list2.getString(i);  
                            presetNames.push([str,str2]);  
                        }  
                        return presetNames;  
                    }; 
                    
                    function ReturnUniqueSortedList(ArrayName){
                    var unduped = new Object;
                    for (var i = 0; i < ArrayName.length; i++) {   
                    unduped[ArrayName[i]] = ArrayName[i];
                    }
                    var uniques = new Array;for (var k in unduped) {
                       uniques.push(unduped[k]);
                       }
                    uniques.sort();
                    return uniques;
                    }
                    function selectToolPreset(TOOL) { 
                        var desc = new ActionDescriptor();
                            var ref = new ActionReference();
                            ref.putName( stringIDToTypeID('toolPreset'),TOOL );
                        desc.putReference( charIDToTypeID('null'), ref );
                        try{
                        executeAction( charIDToTypeID('slct'), desc, DialogModes.NO );
                        }catch(e){/*$.writeln("tool = " + TOOL + "\n" + e);*/}
                    };
                    function selectTool(tool) { 
                        var desc = new ActionDescriptor(); 
                            var ref = new ActionReference(); 
                            ref.putClass( app.stringIDToTypeID(tool) ); 
                        desc.putReference( app.charIDToTypeID('null'), ref ); 
                        try{
                        executeAction( app.charIDToTypeID('slct'), desc, DialogModes.NO ); 
                        }catch(e){/*$.writeln("tool = " + tool + "\n" + e);*/}
                    };
                    
                    
                    
                    
                    
                    1 person found this helpful
                    • 7. Re: get toolpresets for certain tool
                      Joachim Hiller Level 1

                      Thanks SuperMelrin,

                       

                      looks great. Is it right its works only if "Current Tool only" unchecked?

                      2018-05-16_13-36-49.png

                      • 8. Re: get toolpresets for certain tool
                        SuperMerlin Level 5

                        It should work if the checkbox is ticked or not ticked as it tries to select the tool first.

                        • 9. Re: get toolpresets for certain tool
                          Joachim Hiller Level 1

                          For me, this only works if the checkbox is not activated. Can that be due to the language.

                          • 10. Re: get toolpresets for certain tool
                            SuperMerlin Level 5

                            It could well be, I can't test any other language, sorry.

                            • 11. Re: get toolpresets for certain tool
                              Joachim Hiller Level 1

                              No problem, thanks for help .

                              I will test it again tomorrow.

                              • 12. Re: get toolpresets for certain tool
                                SuperMerlin Level 5

                                The problem will be with these lines of code :-

                                var selTool = win.g10.dd1.selection.text.toString().replace(/\s+/g,"");
                                selTool = selTool.charAt(0).toLowerCase() + selTool.substr(1);
                                if(selTool == "verticalTypeTool") selTool ="typeVerticalCreateOrEditTool";
                                selectTool(selTool);
                                
                                

                                 

                                What happens is it gets second value from getToolPresetNames();

                                I.E.

                                Magnetic Lasso 24 pixels,Magnetic Lasso Tool

                                Crop 4 inch x 6 inch 300 ppi,Crop Tool

                                Crop 5 inch x 3 inch 300 ppi,Crop Tool

                                Crop 5 inch x 4 inch 300 ppi,Crop Tool

                                Crop 5 inch x 7 inch 300 ppi,Crop Tool

                                Crop 8 inch x 10 inch 300 ppi,Crop Tool

                                Fill with Bubbles Pattern,Paint Bucket Tool

                                 

                                The second value is the tool but to select the tool Magnetic Lasso Tool needs to be changed to magneticLassoTool

                                Crop Tool changed to cropTool etc.

                                that is what the above lines of code is doing then calling the selectTool function with the modified name.

                                 

                                This is where things might be going wrong?

                                • 13. Re: get toolpresets for certain tool
                                  Kukurykus Adobe Community Professional

                                  Yes it has to be unchecked, at least in CS6 EXTENDED I guess you have to do it manually,

                                  while in CC2018 I'm not sure, there may be some way, but I didn't try yet. Later I will see...

                                   

                                  So it seems to be not possible or r-bin will show nothing is impossible for him in PS

                                  As to my script it can work properly only when 'Only Current Tool' option is unchecked.

                                   

                                  replace:

                                   

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

                                   

                                  to this one:

                                   

                                  try{executeAction(sTT('select'), dsc, DialogModes.NO)} catch(err){break}
                                  

                                   

                                   

                                  also replace:

                                   

                                  alert(pN)
                                  

                                   

                                  to:

                                   

                                  alert(pN.length ? pN : 'Make sure "Only Current Tool" option is unchecked!')
                                  

                                   

                                   

                                  Do not forget to put $.level = 0; in front of first function if you'd like to run it from ESTK!

                                  • 14. Re: get toolpresets for certain tool
                                    r-bin Level 4

                                    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;    
                                    };   
                                    
                                    • 15. Re: get toolpresets for certain tool
                                      Joachim Hiller Level 1

                                      Thank you so much for your kind help.

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