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

merge all layersSets

Explorer ,
Nov 25, 2020 Nov 25, 2020

Copy link to clipboard

Copied

Hi, 

Iv' got script that merge or flatten, all layer in layerSet (Group), but sometimes i've got "merge layer is not available". There is another way, to do a "merge group" ?

 

function mergeAllGroups(){
  shotlayerssets = app.activeDocument.layerSets;
  for (i=shotlayerssets.length; i>0; i-- )
    {
      shotlayerssets[i-1].merge();
    }
}

 thank you

TOPICS
Actions and scripting , Windows

Views

276

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

Explorer , Nov 26, 2020 Nov 26, 2020

I only open photoshop, batch process with .atn file.

Finally, i've found another way :

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

Votes

Translate

Translate
Adobe
Community Expert ,
Nov 25, 2020 Nov 25, 2020

Copy link to clipboard

Copied

Could you please post a screenshot taken at failing time with the pertinent Panels (Toolbar, Layers, History, Options Bar, …) visible? 

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
Explorer ,
Nov 25, 2020 Nov 25, 2020

Copy link to clipboard

Copied

Hi, 

During photoshop batch processing script, i load this script, an then on some psd file i'v got this error:

kkCaptur7e.JPG

 

I will check again if there is not a difference between psd file, because it is strange

Maybe this help,

In this script i've pasted code of http://bereza.cz/ps/ (Delete empty layers faster), then the paste cade above.

 

 

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
Explorer ,
Nov 25, 2020 Nov 25, 2020

Copy link to clipboard

Copied

ok, after trying with lot of psd file. I'v finally found.

When i call script from bereza, i'v got this pop up. When i don't call it it work...

So, there is no another way to delete empty folder ?

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 ,
Nov 25, 2020 Nov 25, 2020

Copy link to clipboard

Copied

Could you please post a screenshot taken at failing time with the pertinent Panels (Toolbar, Layers, History, Options Bar, …) visible

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
Explorer ,
Nov 26, 2020 Nov 26, 2020

Copy link to clipboard

Copied

hum, what you mean by :

with the pertinent Panels (Toolbar, Layers, History, Options Bar, …) visible

 

i don't know what it is

 

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 ,
Nov 26, 2020 Nov 26, 2020

Copy link to clipboard

Copied

What do you use to select a Tool on screen with the cursor? What do you use to organise and move Layers? etc.

 

Anyway, please try this: 

// 2020, use it your own risk; 
if (app.documents.length > 0) {
var thedoc = app.activeDocument;
var docName = thedoc.name;
var basename = docName.match(/(.*)\.[^\.]+$/)[1];
var docPath = thedoc.path;	
//
deleteHidden ();
mergeGroups (thedoc, []);
//
psdOpts = new PhotoshopSaveOptions();
psdOpts.embedColorProfile = true;
psdOpts.alphaChannels = false;
psdOpts.layers = true;
psdOpts.spotColors = true;
thedoc.saveAs((new File(docPath+"/"+basename+"_merged"+".psd")),psdOpts,false);
};
// delete hidden layer;
function deleteHidden () {
try {
var id26 = charIDToTypeID( "Dlt " ); 
var desc6 = new ActionDescriptor(); 
var id27 = charIDToTypeID( "null" ); 
var ref6 = new ActionReference(); 
var id28 = charIDToTypeID( "Lyr " ); 
var id29 = charIDToTypeID( "Ordn" ); 
var id30 = stringIDToTypeID( "hidden" ); 
ref6.putEnumerated( id28, id29, id30 ); 
desc6.putReference( id27, ref6 ); 
executeAction( id26, desc6, DialogModes.NO );
}
catch (e) {}
};
// apply layermask;
function applyLayerMask (a) {
try {
app.activeDocument.activeLayer = a;
// =======================================================
var id500 = charIDToTypeID( "Dlt " ); 
var desc96 = new ActionDescriptor(); 
var id501 = charIDToTypeID( "null" ); 
var ref67 = new ActionReference(); 
var id502 = charIDToTypeID( "Chnl" ); 
var id503 = charIDToTypeID( "Chnl" ); 
var id504 = charIDToTypeID( "Msk " ); 
ref67.putEnumerated( id502, id503, id504 ); 
desc96.putReference( id501, ref67 ); 
var id505 = charIDToTypeID( "Aply" ); 
desc96.putBoolean( id505, true ); 
executeAction( id500, desc96, DialogModes.NO );
}
catch (e) {}
};
////// function collect all layers //////
function mergeGroups (theParent, allLayers) {
	if (!allLayers) {var allLayers = new Array} 
	else {};
	for (var m = theParent.layers.length - 1; m >= 0;m--) {
		var theLayer = theParent.layers[m];
// apply the function to layersets;
		if (theLayer.typename == "ArtLayer") {
	//		allLayers.push(theLayer)
			}
		else {
    //		allLayers = (collectLayers(theLayer, allLayers))
            var theB = theLayer.bounds;
            if (theB[0] == theB[2] || theB[1] == theB[3]) {theLayer.remove()}
            else {var theLayer = theLayer.merge()};
            applyLayerMask (theLayer);
// this line includes the layer groups;
			allLayers.push(theLayer);
			}
		};
	return allLayers
	};

 

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
Explorer ,
Nov 26, 2020 Nov 26, 2020

Copy link to clipboard

Copied

LATEST

I only open photoshop, batch process with .atn file.

Finally, i've found another way :

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

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