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

Can I modify this "merge top level groups" script to hide layers if the original group was hidden?

Contributor ,
May 03, 2024 May 03, 2024

Copy link to clipboard

Copied

I found a script on this community that merges top level groups into individual layers. It's ALMOST perfect for what I need EXCEPT I need it to respect the original visibility of the top level Layer Group and apply that to the merged layer. Currently when run it turns the visibility of all layers to ON regardless of the original Layer Group visibility. How can this be modified? Thank you!

 

#target photoshop;

activeDocument.activeLayer = activeDocument.layerSets[0].layers[0];
activeDocument.activeLayer = activeDocument.activeLayer.parent;

while (app.activeDocument.layerSets.length) {
    activeDocument.activeLayer = app.activeDocument.layerSets[0];
    executeAction(stringIDToTypeID("newPlacedLayer"), new ActionDescriptor(), DialogModes.NO);
    activeDocument.activeLayer.rasterize(RasterizeType.ENTIRELAYER);
}

 

TOPICS
Actions and scripting

Views

152

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

People's Champ , May 04, 2024 May 04, 2024
while (app.activeDocument.layerSets.length) {

    var vis = app.activeDocument.layerSets[0].visible;        
    activeDocument.activeLayer = app.activeDocument.layerSets[0];

    executeAction(stringIDToTypeID("newPlacedLayer"), new ActionDescriptor(), DialogModes.NO);
    activeDocument.activeLayer.rasterize(RasterizeType.ENTIRELAYER);

    activeDocument.activeLayer.visible = vis;
}

Votes

Translate

Translate
Adobe
Community Expert ,
May 03, 2024 May 03, 2024

Copy link to clipboard

Copied

@Mark Paterson 

 

I believe that was an alteration for a different use case, here is the original from @SuperMerlin 

 

/*
https://community.adobe.com/t5/photoshop-ecosystem-discussions/script-to-merge-each-main-group-not-subgroup-in-to-a-layer/m-p/10400702#M237128
By SuperMerlin
*/

#target photoshop;

while (app.activeDocument.layerSets.length) {
    activeDocument.activeLayer = app.activeDocument.layerSets[0];
    executeAction(stringIDToTypeID("newPlacedLayer"), new ActionDescriptor(), DialogModes.NO);
    activeDocument.activeLayer.rasterize(RasterizeType.ENTIRELAYER);
}

 

Two alternative scripts here:

https://community.adobe.com/t5/photoshop-ecosystem-discussions/script-for-merging-each-main-groups-a...

 

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
Contributor ,
May 04, 2024 May 04, 2024

Copy link to clipboard

Copied

Ah ok, good to know the origin of the script. I tried that, and the two alternative scripts, but all of them have the same result: hidden layer groups get turned into visible layers. I need each merged layer to retain the visibility status of the original layer group. I don't know how to modify it to achieve this.

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
Community Expert ,
May 04, 2024 May 04, 2024

Copy link to clipboard

Copied

LATEST

I can see that @r-bin sorted this out. As you didn't provide screenshots to illustrate I obviously didn't understand.

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
People's Champ ,
May 04, 2024 May 04, 2024

Copy link to clipboard

Copied

while (app.activeDocument.layerSets.length) {

    var vis = app.activeDocument.layerSets[0].visible;        
    activeDocument.activeLayer = app.activeDocument.layerSets[0];

    executeAction(stringIDToTypeID("newPlacedLayer"), new ActionDescriptor(), DialogModes.NO);
    activeDocument.activeLayer.rasterize(RasterizeType.ENTIRELAYER);

    activeDocument.activeLayer.visible = vis;
}

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
Contributor ,
May 04, 2024 May 04, 2024

Copy link to clipboard

Copied

Works great, thank you!

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