10 Replies Latest reply on Nov 2, 2016 7:43 PM by JJMack

    Creating a photoshop action to save a batch of images as patterns

    munsonbh

      I am trying to use Photoshop actions to script about a thousand image files into PAT files. I am running into a problem with actions when it comes to defining a pattern. The program naturally selects the filename as the name of the pattern when doing it manually, but when I do this while recording an action Photoshop logs the filename used in creating the action and then uses that filename for all sripted patterns. Is there a way to alter that setting to select the current file's name instead?

       

      http://i.imgur.com/VVfo9.png

        • 1. Re: Creating a photoshop action to save a batch of images as patterns
          JJMack Most Valuable Participant

          You might want to move this thread to the general photoshop forum if tou want an action.  However your not going to be able to do create the action you want for when you record menu Edit>Define Pattern the "Pattern Name Dialog" will pop up and whatever is used in it will be recorded into the action.

           

          Also Photoshop Scripting DOM does not have a interface for creating and nameing patterns.  However you should bne ale to write a script to do what you want using code generated with Photoshop Scriptlistner Plug-in and modifying the hard coded name to a variable you set with somthing like the active document name.

           

          Before defining the patern you may be able to see if the name is all ready use for a pattern name so you can add something to the name to avoid duplicateing name.

           

          ScriptListner Code difine pattern

           

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

          var idMk = charIDToTypeID( "Mk  " );

              var desc14 = new ActionDescriptor();

              var idnull = charIDToTypeID( "null" );

                  var ref12 = new ActionReference();

                  var idPtrn = charIDToTypeID( "Ptrn" );

                  ref12.putClass( idPtrn );

              desc14.putReference( idnull, ref12 );

              var idUsng = charIDToTypeID( "Usng" );

                  var ref13 = new ActionReference();

                  var idPrpr = charIDToTypeID( "Prpr" );

                  var idfsel = charIDToTypeID( "fsel" );

                  ref13.putProperty( idPrpr, idfsel );

                  var idDcmn = charIDToTypeID( "Dcmn" );

                  var idOrdn = charIDToTypeID( "Ordn" );

                  var idTrgt = charIDToTypeID( "Trgt" );

                  ref13.putEnumerated( idDcmn, idOrdn, idTrgt );

              desc14.putReference( idUsng, ref13 );

              var idNm = charIDToTypeID( "Nm  " );

              desc14.putString( idNm, "Pattern 5" );      <------ change "Pattern 5" to be a variable

          executeAction( idMk, desc14, DialogModes.NO );

          1 person found this helpful
          • 2. Re: Creating a photoshop action to save a batch of images as patterns
            munsonbh Level 1

            Thanks JJ for the forewarning on the action capabilities.

             

            I'm now officially in over my head if we are getting into this kind of scripting. Is there a good marketplace to hire script specialists?

            • 3. Re: Creating a photoshop action to save a batch of images as patterns
              Paul Riggott Level 6

              This should be all you need...

               

               

              createPattern();

              function createPattern() {
                  var desc6 = new ActionDescriptor();
                      var ref3 = new ActionReference();
                      ref3.putClass( charIDToTypeID('Ptrn') );
                  desc6.putReference( charIDToTypeID('null'), ref3 );
                      var ref4 = new ActionReference();
                      ref4.putProperty( charIDToTypeID('Prpr'), charIDToTypeID('fsel') );
                      ref4.putEnumerated( charIDToTypeID('Dcmn'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
                  desc6.putReference( charIDToTypeID('Usng'), ref4 );
                  desc6.putString( charIDToTypeID('Nm  '), app.activeDocument.name.replace(/\.[^\.]+$/, '') );
                  executeAction( charIDToTypeID('Mk  '), desc6, DialogModes.NO );
              };

              • 4. Re: Creating a photoshop action to save a batch of images as patterns
                JJMack Most Valuable Participant

                What Paul is saying is that script is all you need to define a pattern that has the name of the current active document.  The way you woul use it is a little complex when you know nothing about scripting.  It not hard use a text editor and open a new document paste Paul's code into and save it in Photoshop Scripts folder with the name  createPattern.jsx.   Each Photoshop version has its own Scripts folder on a windows its like

                "C:\Program Files\Adobe\Adobe Photoshop (version)\Presets\Scripts" where (version) is the version your running like "CS6"

                One you have done that the next time you start Photoshop it will be seen in Photoshop Scripts List use menu File>Scripts>List of scripts installed in photoshop. You can even use the script in actions.  So in one of Action Sets you would record a new action and name it something like "Make Pattern From File"

                you would record two steps

                Step 1.) Select All  (Selection for Patterm)

                Step 2.) Menu File>Scripts>createPattern

                stop recording and save your Action set.

                You would then use the Batch Processor from the Bridge or Photoshop to create batches of patterns.  The Batch Processor in this case need not save an output file use desternation none.

                 

                Once you create your patterns you will need to use Photoshop Preset Manager to save a set of patterns (name.pat). If you want to share or distribute your patterns.

                2 people found this helpful
                • 5. Re: Creating a photoshop action to save a batch of images as patterns
                  munsonbh Level 1

                  Thanks to both of you. You made my day! Running through 2200 files manually was going to be a nightmare. And then inevitably I will need to make more PAT groups in the future.

                   

                  And now I have another reason to learn JavaScript.

                  • 6. Re: Creating a photoshop action to save a batch of images as patterns
                    chet_60

                    Hi,

                    I tried this....but the debug in adobe extend script and photoshop gives me the error message:

                    "no such element"


                        desc6.putString( charIDToTypeID('Nm  '), app.activeDocument.name.replace(/\.[^\.]+$/, '') );

                     

                    I pasted the entire script including the

                    header (?) create pattern();

                     

                    because my patterns are extremely similar- i need the names to identify each one.

                    I have many.

                    thank you
                       

                    • 7. Re: Creating a photoshop action to save a batch of images as patterns
                      Richard Wagner Level 1

                      Thanks to both of you - this is fantastic. It runs fine on Photoshop CC 2014, and I've converted thousands of .dds files from Windows to Mac using XNView (http://www.xnview.com/en/xnviewmp/) to convert the .dds files to TIFs and then this script to complete the trip to PS .pat sets.  Awesome!

                       

                      Many thanks!

                       

                      --Rich Wagner

                      • 8. Re: Creating a photoshop action to save a batch of images as patterns
                        Lionel Drew

                        Hi, I'm new here and very much a javascript novice.  I realize this is an old thread, but it just helped me to solve a problem, so a big thanks to JJMack and Paul Riggot for the code and the comments.

                         

                        Just so you know, I installed the script listener and captured some similar code, but the more I looked at what I captured the more I came to realize that it was not quite what I needed because it referred to a step in an action I wrote, so would have become an invisibly dependent on that action.  That effort enabled me to recognize that the code here was what I really needed.  Thanks again, hope you guys get this after all this time!

                         

                        Regards

                        Lionel

                        • 9. Re: Creating a photoshop action to save a batch of images as patterns
                          Tangie Evans

                          Does anyone have the script for CC 2015.5. I am getting an error for Line 12

                          • 10. Re: Creating a photoshop action to save a batch of images as patterns
                            JJMack Most Valuable Participant

                            Supply pertinent information for quicker answers

                            • The more information you supply about your situation, the better equipped other community members will be to answer. Consider including the following in your question:
                            • Adobe product and version number
                            • Operating system and version number
                            • The full text of any error message(s)
                            • What you were doing when the problem occurred
                            • Screenshots of the problem
                            • Computer hardware, such as CPU; GPU; amount of RAM; etc.