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

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

Community Beginner ,
Oct 21, 2024 Oct 21, 2024

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 !

TOPICS
Actions and scripting , Windows
544
Translate
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

Community Beginner , Oct 21, 2024 Oct 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 !

Translate
Adobe
Community Expert ,
Oct 21, 2024 Oct 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?

Translate
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
Community Beginner ,
Oct 21, 2024 Oct 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 ?

Translate
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
Community Beginner ,
Oct 21, 2024 Oct 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 !

Translate
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
Community Expert ,
Oct 21, 2024 Oct 21, 2024
LATEST

Glad you got the result that you wanted!

Translate
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