skip to Main Content

I’m trying to detect if a pattern name exist on Photoshop but right now I’m not able to do it, anyone have any clue of how to do it?
Right now I have this:

function selectPattern(ptrn) {
  var desc = new ActionDescriptor();
  var ref = new ActionReference();
  ref.putName(charIDToTypeID('Ptrn'), ptrn );
  desc.putReference( charIDToTypeID( "null" ), ref );
  executeAction( charIDToTypeID( "slct" ), desc, DialogModes.NO );
}

but every time I use it the pattern name can’t be found, it’s used something like this:

selectPattern('Gauze');

Thanks in advance

2

Answers


  1. It’s the same script as in this question. You can get the list of different presets from Application action reference:

    var patternsNames = getPresetList(4);
    
    function getPresetList(presetIndex)
    {
      // presetIndex: 0 to 7
      // 0: Brushes
      // 1: Swatches
      // 2: Gradients
      // 3: Styles
      // 4: Patterns
      // 5: Contours
      // 6: Custom Shapes
      // 7: Tools
    
      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++)
      {
        var n = nameList.getString(nameIndex);
        presetNames.push(n);
      }
      return presetNames;
    };
    
    Login or Signup to reply.
  2. Whilst this doesn’t directly answer your question it may be useful to you:

    You can find out a pattern’s ID with the scriptListener.

    // call the source document
    var srcDoc = app.activeDocument;
    
    fillWithPattern("456e6678-5dd6-5046-9e0c-12871fb51bb0");
    
    function fillWithPattern (patternid)
    {
    // =======================================================
    var idFl = charIDToTypeID( "Fl  " );
    var desc126 = new ActionDescriptor();
    var idFrom = charIDToTypeID( "From" );
    var desc127 = new ActionDescriptor();
    var idHrzn = charIDToTypeID( "Hrzn" );
    var idPxl = charIDToTypeID( "#Pxl" );
    desc127.putUnitDouble( idHrzn, idPxl, 100.0 ); // x fill point
    var idVrtc = charIDToTypeID( "Vrtc" );
    var idPxl = charIDToTypeID( "#Pxl" );
    desc127.putUnitDouble( idVrtc, idPxl, 100.0 ); //y fill point
    var idPnt = charIDToTypeID( "Pnt " );
    desc126.putObject( idFrom, idPnt, desc127 );
    var idTlrn = charIDToTypeID( "Tlrn" );
    desc126.putInteger( idTlrn, 0 );
    var idUsng = charIDToTypeID( "Usng" );
    var idFlCn = charIDToTypeID( "FlCn" );
    var idPtrn = charIDToTypeID( "Ptrn" );
    desc126.putEnumerated( idUsng, idFlCn, idPtrn );
    var idPtrn = charIDToTypeID( "Ptrn" );
    var desc128 = new ActionDescriptor();
    var idNm = charIDToTypeID( "Nm  " );
    desc128.putString( idNm, "" ); // pattern name (ignored)
    var idIdnt = charIDToTypeID( "Idnt" );
    desc128.putString( idIdnt, patternid ); //pattern ID
    var idPtrn = charIDToTypeID( "Ptrn" );
    desc126.putObject( idPtrn, idPtrn, desc128 );
    executeAction( idFl, desc126, DialogModes.NO );
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search