1 Reply Latest reply on Jun 17, 2017 8:02 AM by JJMack

    How do I fill a selection using a pre defined pattern with photoshop scripting

    aj2460 Level 1

      var docRef = app.documents.add()

      var layerRef =docRef.layerSets.add();

      layerRef.kind = LayerKind.PATTERNFILL;





      and also how do I create a pattern using the script

        • 1. Re: How do I fill a selection using a pre defined pattern with photoshop scripting
          JJMack Most Valuable Participant

          I think you will need to use Action Manager code create function using scriptlister generated code. Fill selection in DOM seems to be for solid color.  However looking at Action manager code for pattern fill it look like there my be some UUID. It may be because I use Adobe Pattern bubbles not a pattern I defined.  In the Define Pattern step I recorded all I see in the name I created that may be a problem for it look like I can create patterns with duplicate names which could mat selection a pattern by name a problem. I had a problem like that creating Custom shape I need to make the name I created unique so I added a time suffix to the Custom shape name.



          // =======================================================

          var idFl = charIDToTypeID( "Fl  " );

              var desc16 = new ActionDescriptor();

              var idUsng = charIDToTypeID( "Usng" );

              var idFlCn = charIDToTypeID( "FlCn" );

              var idPtrn = charIDToTypeID( "Ptrn" );

              desc16.putEnumerated( idUsng, idFlCn, idPtrn );

              var idPtrn = charIDToTypeID( "Ptrn" );

                  var desc17 = new ActionDescriptor();

                  var idNm = charIDToTypeID( "Nm  " );

                  desc17.putString( idNm, """$$$/Presets/Patterns/Patterns_pat/Bubbles=Bubbles""" );

                  var idIdnt = charIDToTypeID( "Idnt" );

                  desc17.putString( idIdnt, """b7334da0-122f-11d4-8bb5-e27e45023b5f""" );

              var idPtrn = charIDToTypeID( "Ptrn" );

              desc16.putObject( idPtrn, idPtrn, desc17 );

              var idOpct = charIDToTypeID( "Opct" );

              var idPrc = charIDToTypeID( "#Prc" );

              desc16.putUnitDouble( idOpct, idPrc, 100.000000 );

              var idMd = charIDToTypeID( "Md  " );

              var idBlnM = charIDToTypeID( "BlnM" );

              var idNrml = charIDToTypeID( "Nrml" );

              desc16.putEnumerated( idMd, idBlnM, idNrml );

          executeAction( idFl, desc16, DialogModes.NO );





          // =======================================================

          var idMk = charIDToTypeID( "Mk  " );

              var desc21 = new ActionDescriptor();

              var idnull = charIDToTypeID( "null" );

                  var ref4 = new ActionReference();

                  var idPtrn = charIDToTypeID( "Ptrn" );

                  ref4.putClass( idPtrn );

              desc21.putReference( idnull, ref4 );

              var idUsng = charIDToTypeID( "Usng" );

                  var ref5 = new ActionReference();

                  var idPrpr = charIDToTypeID( "Prpr" );

                  var idfsel = charIDToTypeID( "fsel" );

                  ref5.putProperty( idPrpr, idfsel );

                  var idDcmn = charIDToTypeID( "Dcmn" );

                  var idOrdn = charIDToTypeID( "Ordn" );

                  var idTrgt = charIDToTypeID( "Trgt" );

                  ref5.putEnumerated( idDcmn, idOrdn, idTrgt );

              desc21.putReference( idUsng, ref5 );

              var idNm = charIDToTypeID( "Nm  " );

              desc21.putString( idNm, """Pattern O""" );

          executeAction( idMk, desc21, DialogModes.NO );