0 Replies Latest reply on Apr 5, 2017 3:54 AM by EnsilZah_

    Tool Presets list not updating properly

    EnsilZah_ Level 1


      So I've run into a problem while trying to rename multiple tool presets.

      It seems that when getting a list of tool presets, it does not get properly updated when using the method below.

      As I use the list-getting method to also get indexes of for the tool presets, it screws up renaming multiple presets.


      function cID (inVal) { return charIDToTypeID(inVal);}
      function sID (inVal) { return stringIDToTypeID(inVal);}
      renamePresetByIndex = function(index, name)
            var ref = new ActionReference();
            ref.putIndex(sID( "toolPreset" ), index);
            var desc = new ActionDescriptor();
            desc.putReference(cID('null'), ref);
            desc.putString(cID('T   '), name);
            executeAction(cID('Rnm '), desc, DialogModes.NO );
      getPresetList = function()
          var ref = new ActionReference();    
          ref.putEnumerated( cID("capp"), cID("Ordn"), cID("Trgt") );    
          var appDesc = executeActionGet(ref);    
          var List = appDesc.getList(stringIDToTypeID('presetManager'));   
          var presetNames=[];   
          var list = List.getObjectValue(7).getList(cID('Nm  '));
          for (var i = 0; i < list.count; i++)
                  var str = list.getString(i);
          return presetNames;    
      alert("01: " + getPresetList())
      alert("02: " + getPresetList())
      alert("03: " + getPresetList())



      Here is the output I get:


      As you can see, the first renamed preset apparently remains at the first index, but it actually occupies the third index when the rename function is executed (as the Tool Presets list seems to generally self sort by name).

      So my question is, am I doing something wrong?

      Is there a better method for getting a correct name list and corresponding indexes?

      Should I just get the list and sort it myself? (which adds the complexity of dealing with sorting by tool types... )