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
CatoPbxAuthor
Inspiring
June 6, 2017

Hi, I tried that script, and while it's useful for saving a single image as a pattern, it does not save all the layers in the photoshop file as a pattern (only the top-most layer in view, or whatever is showing on the screen currently).

Is there any way to save each layer, as an individual pattern (for all layers that are in a single Photoshop document)? So if I have 8 layers in the Photoshop file (each taking up the entire canvas), I want to define 8 corresponding patterns.

c.pfaffenbichler
Community Expert
Community Expert
June 6, 2017

You have to customise the Script naturally, but there are Scripts available for assessing the Layers in a File that you can modify.

Re: Layer Sets (groups)