4 Replies Latest reply on Mar 16, 2016 1:41 PM by JJMack

    Photoshop tool preset list, by current/active tool?

    anonymousasyou

      0down votefavorite

       

       

      Ok so I know that this has been asked before but In a more general way(recently). I'm trying to get the list of toolpresets but only those of the active tool selected. So If I have the Brush tool selected, It would only scan/output for just the brush tool. I know you can do the tool presets list as a whole(see script below), but I'm trying to run a make new tool preset option(not the default) that you input the tool preset name you want, It scans the current active tool presets to see if that name exists, if it does already exist it error messages and restarts the input process again, halting. I can get it to check the whole list and work fine, but I'd like ONLY to check by active tool selected, so it only checks those of that type vs the entire list. By default photoshop already does it, it only checks the list of the tool you are using, i'm trying to do the same. Other wise as it stands now if there is a name for example in the eraser tool presets, and i try inputting that name as a regular brush tool preset, it finds the name and says i cannot process because the name already exists(in erasers), that's why Im asking. I hope this makes sense. What i started with was this script on the forums:

       

       

      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); } r
      eturn
      presetNames;

      }

        • 1. Re: Photoshop tool preset list, by current/active tool?
          JJMack Most Valuable Participant

          Here are the problems I see.  The check box in the preset pull-down dialog window on the bottom left  "Current Tool Only" effect the which "Tools presets"  a script can select.  When its state in uncheck any current Photoshop preset can be selected by a script. If the "preset" was not for the current tool the preset's tool will also be selected and become the current active tool. However if the "check box" state is checked only presets for the current tool can be selected.  So if you try to select a preset by name and it fails you do not know if the "Named Preset" exists or not because you don't know the state of the "check box" or what the current active Photoshop tool is. 

           

          You can only select some Photoshop tools to activate the with a script the one that select tool name recorded in actions via action manager code.  Hpwever. when the state of the checkbox is not check you can select any tool preset to activate the tool and set the toop settings. If the prest fails to select you can load a preset for the tool and select it when the checkbox is not checked.  However, you do not know the state  of the "check box Current Tool Only"  nor can you set its state with a script.

           

          The best I have been able to do is to inform the user with an alert to uncheck the check box "Current Tool Only"

           

          Select Tool Preset script

          // Note:  This script only works if the correct tool for the preset is currently selected.

          //            Or "Current Tool Only" is not checked in Photoshop's  "Tool Options Bar" Presets pull-down list dialog at the bottom left. 

           

          var ToolPresetName = "JJMack soft oval red brush" ; // The Photoshop Tool preset name that you created and saved into a set  

          var ToolPresetSet  = "JJMackToolsPresetsSet";        // The SetName.tpl file need to be same folder as this Photoshop script.

           

          try {SelectToolPreset(ToolPresetName);}

          catch(e) {

            if (LoadToolPresetSet(ToolPresetSet)) {

            try {SelectToolPreset(ToolPresetName);}

            catch(e) {alert('Was unable to Select the Tools Preset "' + ToolPresetName + '".\nUncheck Preset pulld-down dialog "Current Tool Only" check box');}

            }

            else {alert("Was unable to load Tools Presets Set " + ToolPresetSet);}

          }

           

          // =================================================== Helper functions ===================================================== //

          function SelectToolPreset(PresetName) {

            // === Select Preset, tool must be selected or 'show current tool only' unchecked  ===

            var desc = new ActionDescriptor();

            var ref = new ActionReference();

            ref.putName( stringIDToTypeID( "toolPreset" ), PresetName );

            desc.putReference( charIDToTypeID( "null" ), ref );

            executeAction( charIDToTypeID( "slct" ), desc, DialogModes.NO );

          }

           

          function LoadToolPresetSet(SetName) {

            returncode = true;

            var scriptLocation = String(findScript());

            var path = scriptLocation.substr(0, scriptLocation.lastIndexOf("/") + 1 ) ;

            var SetFile = new File(path + SetName + ".tpl");   // Requited to be in the script's folder

            if (!SetFile.exists) { returncode = false; }

            else {

            try {LoadToolsSet(SetFile);}

            catch(e) { returncode = false; }

            }

            return returncode ;

          }

           

          function LoadToolsSet(tplFile) {

            // ========load a set of Tools Presets=========================

            var desc = new ActionDescriptor();

            var ref = new ActionReference();

            ref.putProperty( charIDToTypeID( "Prpr" ), stringIDToTypeID( "toolPreset"  ));

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

            desc.putReference( charIDToTypeID( "null" ), ref );

            desc.putPath( charIDToTypeID( "T   " ), new File( tplFile ) );

            desc.putBoolean( charIDToTypeID( "Appe" ), true );

            executeAction( charIDToTypeID( "setd" ), desc, DialogModes.NO );

          }

           

          // Find the location where this script resides

          function findScript() {

            var where = "";

            try { FORCEERROR = FORCERRROR;}

            catch(err) { where = File(err.fileName);}

            return where ;

          }

          • 2. Re: Photoshop tool preset list, by current/active tool?
            JJMack Most Valuable Participant

            You may want to look at X's script PresetLister it list presets by  tool name.  The script is in his xTools package. PresetLister.js  I do not know how to find out what Photoshop tool is currently selected in the tools palette or if the edit toolbar icon is highlighted.

            • 3. Re: Photoshop tool preset list, by current/active tool?
              anonymousasyou Level 1

              Thanks JJMack, from what you have posted and more research It seems like it is most likely impossible to list tool presets by tool type. Seems like these are the only possible choices(from X presetlistener seen below).  So can can get all the toolpresets currently loaded into the manager, but not differentiate what entry belongs to what tool e.g.: brush/eraser/smudge/etc. Hmm i figured there would be a way...

                self.brushes       = []; self.colors        = []; self.gradients     = []; self.styles        = []; self.patterns      = []; self.shapingCurves = []; self.customShapes  = []; self.toolPresets   = [];

              • 4. Re: Photoshop tool preset list, by current/active tool?
                JJMack Most Valuable Participant

                anonymousasyou wrote:

                 

                Thanks JJMack, from what you have posted and more research It seems like it is most likely impossible to list tool presets by tool type. Seems like these are the only possible choices(from X presetlistener seen below).  So can can get all the toolpresets currently loaded into the manager, but not differentiate what entry belongs to what tool e.g.: brush/eraser/smudge/etc. Hmm i figured there would be a way...

                The Preset Manager handles many presets beside "ToolPresets".  All can be listed. Some of the Presets you seem to be interested in are not "toolptesets" but are presets Photoshop tools can use like custom Brush, Shapes. Colors, Gradients  etc like you list above.  I posted  you may want to look at X's script PresetLister.js. in his xTools package. It seems to do what you want. 

                Capture.jpg