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

How to flatten a single layer in photosop using a script (js reference)?

New Here ,
Mar 25, 2015 Mar 25, 2015

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

TOPICS
Actions and scripting

Views

1.1K

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

Advocate , Apr 11, 2015 Apr 11, 2015

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

Votes

Translate

Translate
Adobe
Community Expert ,
Mar 25, 2015 Mar 25, 2015

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.

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 ,
Mar 25, 2015 Mar 25, 2015

Copy link to clipboard

Copied

yes, i just realize that thanks

there is a command to rasterize a single layer ?

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
Advocate ,
Apr 10, 2015 Apr 10, 2015

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

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
Enthusiast ,
Apr 11, 2015 Apr 11, 2015

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.

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
Advocate ,
Apr 11, 2015 Apr 11, 2015

Copy link to clipboard

Copied

LATEST

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

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