• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

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

Community Beginner ,
May 13, 2012 May 13, 2012

Copy link to clipboard

Copied

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

TOPICS
Actions and scripting

Views

8.9K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Valorous Hero , May 14, 2012 May 14, 2012

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( char

...

Votes

Translate

Translate
Adobe
Community Expert ,
May 14, 2012 May 14, 2012

Copy link to clipboard

Copied

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 );

JJMack

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 14, 2012 May 14, 2012

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
May 14, 2012 May 14, 2012

Copy link to clipboard

Copied

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 );
};

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 14, 2012 May 14, 2012

Copy link to clipboard

Copied

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.

JJMack

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 14, 2012 May 14, 2012

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 09, 2014 Oct 09, 2014

Copy link to clipboard

Copied

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 to convert the .dds files to TIFs and then this script to complete the trip to PS .pat sets.  Awesome!

 

Many thanks!

 

--Rich Wagner

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 06, 2016 Sep 06, 2016

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 24, 2014 Jan 24, 2014

Copy link to clipboard

Copied

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
   

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 02, 2016 Nov 02, 2016

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 02, 2016 Nov 02, 2016

Copy link to clipboard

Copied

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.
JJMack

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 09, 2018 Nov 09, 2018

Copy link to clipboard

Copied

I'm getting error on line 12 also. PS CC 2019, Mac Sierra 10.12.6,

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Nov 10, 2018 Nov 10, 2018

Copy link to clipboard

Copied

What error?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 10, 2018 Nov 10, 2018

Copy link to clipboard

Copied

It says error 8550 - this operation may not be available in this version of photoshop. It says it's line 12.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Nov 10, 2018 Nov 10, 2018

Copy link to clipboard

Copied

And what text do you have in the script in line 12?
Could you show a screenshot of the error message?
Usually there, besides the line number, there is also the text of the code that caused it.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 11, 2018 Nov 11, 2018

Copy link to clipboard

Copied

I used the script by paul riggott in the correct answer. I didn't change anything. Most people say this get this error when the destination folder hasn't been created. Here is the screenshot. Thank youScreenImage 2018-11-11 at 2.02.16 PM.jpg

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Nov 11, 2018 Nov 11, 2018

Copy link to clipboard

Copied

Save the script in text format (.txt), and not as it is now in (.rtf).
It is advisable then to give the file extension (.jsx).

P.S. What destination folder are you talking about? Your script doesn't need this at all.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 11, 2018 Nov 11, 2018

Copy link to clipboard

Copied

I did. I have it as .jsx. I was showing you the original file before I saved it. When I open it in ExtendScript on mac it's all on one line so that's not very helpful when trying to find line 12. This is what I get when I clicked Debug.

ScreenImage 2018-11-11 at 4.49.09 PM (2).jpg

Here it is when I put each line where it's supposed to be

ScreenImage 2018-11-11 at 4.55.49 PM.jpg

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Nov 11, 2018 Nov 11, 2018

Copy link to clipboard

Copied

Ok

Download and run this script. xxx.jsx - Google Drive

Is there the same error?

Run the script from Photoshop or change the destination program

ScreenImage+2018-11-11+at+4.55.49+PM.jpg

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 11, 2018 Nov 11, 2018

Copy link to clipboard

Copied

OMG! It worked I am so grateful! Thank you so much. I wish I could give you a super big hug!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 08, 2020 Sep 08, 2020

Copy link to clipboard

Copied

LATEST

Hello,

Is there any way I could get the script you linked Tangie_Evans to? The link no longer works but I am in need of the exact same script.

Thanks,
Trey

 

Nevermind, I put it into brackets and cleaned it up so that everything was on its own line and it seems to work fine now.

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 );};

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 15, 2018 Jul 15, 2018

Copy link to clipboard

Copied

If you want also to export the last pattern defined (as I needed), then this is how it should be done:

var patternName = 'PatternName';

var patternPath = 'somePath/' + patternName + '.pat';

definePattern(patternName);

var lastPatternIndex = getPatternIndexByName(patternName);

exportPattern(lastPatternIndex, patternPath);

function definePattern(patternName) {

   var dialogMode = DialogModes.NO;

   var desc1 = new ActionDescriptor();

   var ref1 = new ActionReference();

   ref1.putClass(cTID('Ptrn'));

   desc1.putReference(cTID('null'), ref1);

   var ref2 = new ActionReference();

   ref2.putProperty(cTID('Prpr'), sTID("selection"));

   ref2.putEnumerated(cTID('Dcmn'), cTID('Ordn'), cTID('Trgt'));

   desc1.putReference(cTID('Usng'), ref2);

   desc1.putString(cTID('Nm '), patternName);

   executeAction(cTID('Mk '), desc1, dialogMode);

}

function exportPattern(patternIndex, patternPath) {

   var idsetd = charIDToTypeID( "setd" );

   var desc74 = new ActionDescriptor();

   var idnull = charIDToTypeID( "null" );

   desc74.putPath( idnull, new File( patternPath ) );

   var idT = charIDToTypeID( "T " );

   var list10 = new ActionList();

   var ref31 = new ActionReference();

   var idPtrn = charIDToTypeID( "Ptrn" );

   ref31.putIndex( idPtrn, patternIndex );

   list10.putReference( ref31 );

   desc74.putList( idT, list10 );

   executeAction( idsetd, desc74, DialogModes.NO );

}    

function getPatternIndexByName(match) {

    try {

        var r = new ActionReference();

        r.putProperty(charIDToTypeID("Prpr"), stringIDToTypeID("presetManager"));

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

        var list = executeActionGet(r).getList(stringIDToTypeID("presetManager"));

        for (var i = 0; i < list.count; i++) {

            if (list.getObjectType(i) == charIDToTypeID("PttR")) {

                var list2 = list.getObjectValue(i).getList(stringIDToTypeID("name"));

                for (var x = 0; x < list2.count; x++) {

                    var name = list2.getString(x);

                    if (name.indexOf(match) >= 0) return x + 1;

                }

                break;

            }

        }

        return -1;

    }

    catch (e) {

        alert(e);

        return -1;

    }

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 15, 2018 Jul 15, 2018

Copy link to clipboard

Copied

You probably will find one more theard to post it 😉

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines