Copy link to clipboard
Copied
I've see lot of script using activeDocument.flatten() but i need to know hot to flatten a single layer
activeDocument.layers[3] for example.
thanks in advance
i'm usign ps cc2014 by the way
Hi Matias,
you're correct - layer names aren't unique. Here's a version using layer ID:
function rasterizeLayerByID (id) {
var s = function(str) { return app.stringIDToTypeID(str) }
var d = new ActionDescriptor();
var r = new ActionReference();
r.putIdentifier(s('layer'), id);
d.putReference(s('target'), r);
executeAction(s('rasterizeLayer'), d, DialogModes.NO);
}
Both (id and name functions) should work with Smart Objects and the like.
Best,
Davide
Copy link to clipboard
Copied
Are you talking about rasterizing a layer? You need at least two layers to flatten. Use scriptlistener to record what you want to script.
Copy link to clipboard
Copied
yes, i just realize that thanks
there is a command to rasterize a single layer ?
Copy link to clipboard
Copied
Hi,
you can rasterize a single layer (e.g. a Solid Color layer, etc) with the following one, which takes the layer name (string) as a parameter:
function rasterizeLayerByName (layerName) {
var s = function(str) { return app.stringIDToTypeID(str) }
var d = new ActionDescriptor();
var r = new ActionReference();
r.putName(s('layer'), layerName);
d.putReference(s('target'), r);
executeAction(s('rasterizeLayer'), d, DialogModes.NO);
}
// Example:
// rasterizeLayerByName('Gradient Fill 1');
Hope this helps,
Davide Barranca
---
www.davidebarranca.com
www.cs-extensions.com
Copy link to clipboard
Copied
Btw, Davide how does that work with layer name as param? It's not a unique id across whole doc or even group.
A rather simple alternative is to create an empty layer below and use artLayer.merge(). There is also artLayer.rasterize(RasterizeType), but I think it had the issue that even with param RasterizeType.ENTIRELAYER it does not rasterize layer style & smart filter. This limitation might (or might not) apply to Davide's solution also since it uses similar attribute.
Copy link to clipboard
Copied
Hi Matias,
you're correct - layer names aren't unique. Here's a version using layer ID:
function rasterizeLayerByID (id) {
var s = function(str) { return app.stringIDToTypeID(str) }
var d = new ActionDescriptor();
var r = new ActionReference();
r.putIdentifier(s('layer'), id);
d.putReference(s('target'), r);
executeAction(s('rasterizeLayer'), d, DialogModes.NO);
}
Both (id and name functions) should work with Smart Objects and the like.
Best,
Davide