Skip to main content
Participant
October 21, 2024
Answered

How to rasterize all layer groups, instead of all layers ? (Script)

  • October 21, 2024
  • 1 reply
  • 782 views

Hello,

 

Within my Photoshop script, I have a function to rasterize all layers. It's working well, but I noticed that processing this way ignores blend modes of layer groups...

 

function rasterizeAllLayers(){

    runMenuItem(stringIDToTypeID("selectAllLayers"));

    var d = new ActionDescriptor();
    var r = new ActionReference();

    r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
    d.putReference(stringIDToTypeID("null"), r);
    d.putEnumerated(stringIDToTypeID("what"), stringIDToTypeID("rasterizeItem"), stringIDToTypeID("layerStyle"));
    executeAction(stringIDToTypeID("rasterizeLayer"), d, DialogModes.NO);
    runMenuItem(stringIDToTypeID("selectNoLayers"));
}

 

So I was wondering how to edit this function to rasterize each group instead of each layer. I'm guessing the new code should also includes some way to rasterize layers that don't belong to any group...

 

Thank you so much in advance for your time and help !

This topic has been closed for replies.
Correct answer Bota_

Oh ! I actually tried with the following :

var idrasterizeAll = stringIDToTypeID( "rasterizeAll" );
executeAction( idrasterizeAll, undefined, DialogModes.NO );

And it works perfectly ! I guess I should have tried something easier from the beginning...

Thank you again @Stephen Marsh for your time !

1 reply

Stephen Marsh
Community Expert
Community Expert
October 21, 2024

@Bota_ 


Can you post a before/after screenshot of the layers panel with a group selected before/after?

 

Do you have groups nested inside groups? Or is it just all top-level layers or groups that need to be rasterised?

If groups needs to be handled differently than layers, then how so?

Bota_Author
Participant
October 21, 2024

Hello ! Thank you for your answer !

Nested groups can exist, but just taking care of top-level layers should be enough. I just don't want to lose some blend mode info.

Groups and isolated layers don't have to be treated differently.

 

I have done some tests and it seems like the blend mode of layer groups are applied, but it is actually blend mode of smart objects that are being ignored...
Also, when I use Layer > Rasterize > All Layers it actually does work the way I expect (blend modes are conserved), maybe there is a simpler way in the script code ?

Bota_AuthorCorrect answer
Participant
October 21, 2024

Oh ! I actually tried with the following :

var idrasterizeAll = stringIDToTypeID( "rasterizeAll" );
executeAction( idrasterizeAll, undefined, DialogModes.NO );

And it works perfectly ! I guess I should have tried something easier from the beginning...

Thank you again @Stephen Marsh for your time !