I ran into an issue that I was not aware of and have not seen any post about so I thought I would pass it along.
If you use scriptlistener to record the Merge Down command you get the following codeCode: Select allexecuteAction( charIDToTypeID('Mrg2'), undefined, DialogModes.NO );Which merges the activeLayer down into the one below. The issue I ran into is that if the activeLayer is the base of a clipping group that same code does the Merge Clipping Mask command instead. That command merges the layer above the activeLayer ( and all the layers in the clipping group ). So we have the same code doing two different things depending on the activeLayer.
I also could not find a direct way to tell if the activeLayer is the base of a clipping group. ArtLayer.grouped returns false. The layer's ActionDescriptor isn't any direct help either. The is a key for grouped by it returns the same as the DOM. So how do you tell which merge command will be used? I can up the the following.
Code: Select allfunction isClippingBase(){
if(app.activeDocument.activeLayer.grouped) return false;
if(app.activeDocument.activeLayer != app.activeDocument.layers[0]){
return isGroupByIndex( getActiveLayerIndex()+1);
}
function getActiveLayerIndex() {
var ref = new ActionReference();
ref.putProperty( 1349677170 , 1232366921 );
ref.putEnumerated( 1283027488, 1332896878, 1416783732 );
var res = executeActionGet(ref).getInteger( 1232366921 )
- Number( hasBackground() );
return res;
};
function hasBackground() {
var doc = app.activeDocument;
return doc.layers[doc.layers.length-1].isBackgroundLayer;
};
function isGroupByIndex( idx ) {
var ref = new ActionReference();
ref.putProperty( 1349677170 , 1198683504);
ref.putIndex( 1283027488, idx );
return executeActionGet( ref ).getBoolean( 1198683504 );
};
};
Merge Down or not
Merge Down or not
I've been stuffing the layers that return true as grouped into an array, stopping when it hits something that doesn't match the grouped criteria, then making the last layer in the array active and selecting the layer below it.
edit: I should add, there's probably a better way....
Code: Select allfunction collectClippingLayers(array, layer){
var thisLayer= isClippingLayer(layer);
if (thisLayer == true){
//alert ("true");
array.push(layer);
}else{
//alert ("false");
}//if/else
return array;
}//collect
function isClippingLayer(layer){
return (layer.grouped == true && layer.kind == LayerKind.NORMAL) || (layer.grouped == true && layer.kind == LayerKind.TEXT)
}//clipping check
function selectLayerBelow(lastLayerInArray){//pass in the last layer in your array
app.activeDocument.activeLayer = lastLayerInArray;//make it active
//scriptListener code for select layer below
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID( "Lyr " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Bckw" ) );
desc.putReference( charIDToTypeID( "null" ), ref );
desc.putBoolean( charIDToTypeID( "MkVs" ), false );
executeAction( charIDToTypeID( "slct" ), desc, DialogModes.NO );
}//select layer below
edit: I should add, there's probably a better way....
Code: Select allfunction collectClippingLayers(array, layer){
var thisLayer= isClippingLayer(layer);
if (thisLayer == true){
//alert ("true");
array.push(layer);
}else{
//alert ("false");
}//if/else
return array;
}//collect
function isClippingLayer(layer){
return (layer.grouped == true && layer.kind == LayerKind.NORMAL) || (layer.grouped == true && layer.kind == LayerKind.TEXT)
}//clipping check
function selectLayerBelow(lastLayerInArray){//pass in the last layer in your array
app.activeDocument.activeLayer = lastLayerInArray;//make it active
//scriptListener code for select layer below
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID( "Lyr " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Bckw" ) );
desc.putReference( charIDToTypeID( "null" ), ref );
desc.putBoolean( charIDToTypeID( "MkVs" ), false );
executeAction( charIDToTypeID( "slct" ), desc, DialogModes.NO );
}//select layer below
Merge Down or not
I should've asked....
What are you trying to do exactly?
Do you want it to merge the clipping groups?
Are you trying to only merge the grouped layers?
What are you trying to do exactly?
Do you want it to merge the clipping groups?
Are you trying to only merge the grouped layers?
Merge Down or not
H.N.Orange wrote:What are you trying to do exactly?
Sorry I just noticed your post.
What I was trying to do was bring to attention the fact that both the action manager command and the Photoshop Object Model method artLayer.merge() behave differently depending on if the layer being merged is the base of a clipping group( the clipping mask ).
The JavaScript Reference Guide only says 'Merges the layer down, removing the layer from the document; returns a reference to the art layer that this layer is merged into.' It doesn't say that it may merge the clipping group( thereby removing as many layers as where in the clipping group ) into the current layer and not merge down.
I also wanted to point out that there is no direct way to tell if a layer is the base of a clipping group and post my way of determining if it is.
This may not be news to everyone. But it was new to me when I ran into the issue.
Sorry I just noticed your post.
What I was trying to do was bring to attention the fact that both the action manager command and the Photoshop Object Model method artLayer.merge() behave differently depending on if the layer being merged is the base of a clipping group( the clipping mask ).
The JavaScript Reference Guide only says 'Merges the layer down, removing the layer from the document; returns a reference to the art layer that this layer is merged into.' It doesn't say that it may merge the clipping group( thereby removing as many layers as where in the clipping group ) into the current layer and not merge down.
I also wanted to point out that there is no direct way to tell if a layer is the base of a clipping group and post my way of determining if it is.
This may not be news to everyone. But it was new to me when I ran into the issue.