Copy link to clipboard
Copied
How do I create a script that saves each layer in my Photoshop file as a pattern (ie. define pattern for each layer, keeping the layer name for the pattern name)?
1 Correct answer
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.
Explore related tutorials & articles
Copy link to clipboard
Copied
The function given in this thread
Re: Creating a photoshop action to save a batch of images as patterns
should help you.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
You have to customise the Script naturally, but there are Scripts available for assessing the Layers in a File that you can modify.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Thanks for the functioning link, @Kukurykus .
Strangely I hadn’t been notified of the recent action on this thread.
Copy link to clipboard
Copied
I'm glad you used name of that thread otherwise we couldn't find it anymore on forum.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Was not that what you needed: Jun 6, 2017
Copy link to clipboard
Copied
I(...)will get back onto it when I can.(...)I am a beginner, so I might take a while to sort it out
By CatoPbx almost 4 years ago
Copy link to clipboard
Copied
I somehow missed that script. I will try it out when I next want to make patterns fron layers.
Copy link to clipboard
Copied
It's better seen to first try someone's attempt, than later leave own solution to mark is as correct.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Have you been able to amend/combine the Scripts according to your needs?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
// create patterns;
for (var m = 0; m < theLayers.length; m++) {
theLayers
createPattern(theLayers
theLayers
};
////// 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 );
};

