Skip to main content
This topic has been closed for replies.
Correct answer CatoPbx

I should have replied much earlier ... (1) Saved a script to create a pattern from an image, giving the pattern name the same name as the document name.  (2) Created an action to run the pattern script on an image, and close the image. (3) Used Batch to run the action on a folder of image files. After this, the patterns were all available in my Photoshop Patterns tab, named as per the original file name.

2 replies

c.pfaffenbichler
Community Expert
Community Expert
June 6, 2017

Have you been able to amend/combine the Scripts according to your needs?

CatoPbx
CatoPbxAuthor
Inspiring
June 6, 2017

Hi, I needed to do something else, so will get back onto it when I can. Thanks for the advice, I am a beginner, so I might take a while to sort it out - but will let you know.

c.pfaffenbichler
Community Expert
Community Expert
June 7, 2017

You could give this a try:

// create patterns from layers;

// 2017, use it at your own risk;

#target photoshop

var theLayers = collectLayers(app.activeDocument, []);

// hide layers;

for (var n = 0; n < theLayers.length; n++) {theLayers.visible = false};

// create patterns;

for (var m = 0; m < theLayers.length; m++) {

theLayers.visible = true;

createPattern(theLayers.name)

theLayers.visible = false;

};

////// function collect all layers //////

function collectLayers (theParent, allLayers) {

if (!allLayers) {var allLayers = new Array}  

else {};

for (var m = theParent.layers.length - 1; m >= 0;m--) {

var theLayer = theParent.layers;

// apply the function to layersets;

if (theLayer.typename == "ArtLayer") {

allLayers.push(theLayer);

else { 

allLayers = (collectLayers(theLayer, allLayers))

// this line includes the layer groups;

//allLayers.push(theLayer);

}

};

return allLayers

};

////// pattern //////

function createPattern(theName) {

    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  '), theName );

    executeAction( charIDToTypeID('Mk  '), desc6, DialogModes.NO );

};

c.pfaffenbichler
Community Expert
Community Expert
June 6, 2017

The function given in this thread

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

should help you.

CatoPbx
CatoPbxAuthorCorrect answer
Inspiring
April 17, 2021

I should have replied much earlier ... (1) Saved a script to create a pattern from an image, giving the pattern name the same name as the document name.  (2) Created an action to run the pattern script on an image, and close the image. (3) Used Batch to run the action on a folder of image files. After this, the patterns were all available in my Photoshop Patterns tab, named as per the original file name.

CatoPbx
CatoPbxAuthor
Inspiring
April 17, 2021

Ps. To clarify the above answer, I gave up saving each layer as a pattern. Rather, I saved each layer as an individual image in a folder, then used that folder location in the batch for the pattern making script.