In Photoshop you can turn all layer styles off on a non-active layer by clicking on the eyeball next to the text "Effects"... doing so generates the following action-manager code:
Code: Select allvar idHd = charIDToTypeID( "Hd " );
var desc1 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var list1 = new ActionList();
var ref1 = new ActionReference();
var idLefx = charIDToTypeID( "Lefx" );
ref1.putClass( idLefx );
var idLyr = charIDToTypeID( "Lyr " );
ref1.putName( idLyr, "Layer 1 copy" );
list1.putReference( ref1 );
desc1.putList( idnull, list1 );
executeAction( idHd, desc1, DialogModes.NO );
However, turning the effects back on and then trying to execute this code results in an exception - 'The object “layer styles” is not currently available.'
If the layer in question is made the active layer ("Layer 1 copy" in the above case) the code executes properly and without errors.
Any ideas on how to accomplish this?
Thanks.
Turning off layer styles on non-active layer
-
Paul MR
Turning off layer styles on non-active layer
To turn toggle the effects on a layer that isn't selected you need to use either the layers index or the layers ID.
This example uses the layers ID..
Code: Select allfunction showHideFX(ID,toggle) {
if(ID == undefined) return;
var desc = new ActionDescriptor();
var list1 = new ActionList();
var ref = new ActionReference();
ref.putClass( charIDToTypeID('Lefx') );
ref.putIdentifier(charIDToTypeID('Lyr '), ID);
list1.putReference( ref );
desc.putList( charIDToTypeID('null'), list1 );
if(toggle){
executeAction( charIDToTypeID('Shw '), desc, DialogModes.NO );
}else{
executeAction( charIDToTypeID('Hd '), desc, DialogModes.NO );
}
};
This function will get an active layers ID...
Code: Select allfunction getLayerID(){
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID('Lyr '),charIDToTypeID('Ordn'),charIDToTypeID('Trgt') );
var desc = executeActionGet(ref);
return desc.getInteger(stringIDToTypeID( 'layerID' ));
}
This example uses the layers ID..
Code: Select allfunction showHideFX(ID,toggle) {
if(ID == undefined) return;
var desc = new ActionDescriptor();
var list1 = new ActionList();
var ref = new ActionReference();
ref.putClass( charIDToTypeID('Lefx') );
ref.putIdentifier(charIDToTypeID('Lyr '), ID);
list1.putReference( ref );
desc.putList( charIDToTypeID('null'), list1 );
if(toggle){
executeAction( charIDToTypeID('Shw '), desc, DialogModes.NO );
}else{
executeAction( charIDToTypeID('Hd '), desc, DialogModes.NO );
}
};
This function will get an active layers ID...
Code: Select allfunction getLayerID(){
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID('Lyr '),charIDToTypeID('Ordn'),charIDToTypeID('Trgt') );
var desc = executeActionGet(ref);
return desc.getInteger(stringIDToTypeID( 'layerID' ));
}
-
bdeshazer
Turning off layer styles on non-active layer
Appreciate the reply Paul, but that function doesn't work, I get the same error regardless of whether I use the ID, index or name... the only time it works if the specified layer is the active layer.
I'm using Photoshop CS6 13.0.4/Mac but have CS4 & CS5 loaded, may try testing on those to see if this is just a CS6-specific bug.
I'm using Photoshop CS6 13.0.4/Mac but have CS4 & CS5 loaded, may try testing on those to see if this is just a CS6-specific bug.
-
Paul MR
Turning off layer styles on non-active layer
It was tested and written with Photoshop CS6 & Windows 7.
-
Mike Hale
Turning off layer styles on non-active layer
Paul, I have the same problem setting by index, ID, or name using CS6 on Windows 7. Unless the layer also happens to be the activeLayer, then it works.
This isn't ideal but it is the best I could come up with without spending a lot of time.
Code: Select allfunction showLayerFX( layername, effectID, bool ) {
if(bool){
var state = 'Shw ';
}else{
var state = 'Hd ';
}
try {
var desc = new ActionDescriptor();
var list = new ActionList();
var ref = new ActionReference();
ref.putClass( effectID );
ref.putName( charIDToTypeID('Lyr '), layername );
list.putReference( ref );
var ref = new ActionReference();
ref.putClass( charIDToTypeID('Lefx') );
ref.putName( charIDToTypeID('Lyr '), layername );
list.putReference( ref );
desc.putList( charIDToTypeID('null'), list );
executeAction( charIDToTypeID( state ), desc, DialogModes.NO );
} catch (e) {}
};
function getEffectsDescriptorByName( layername ){
var ref = new ActionReference();
ref.putName( charIDToTypeID('Lyr '), layername );
var desc = executeActionGet(ref);
if(desc.hasKey(stringIDToTypeID('layerEffects'))) return desc.getObjectValue(stringIDToTypeID('layerEffects'));
};
var firstEffectID = getEffectsDescriptorByName( 'Layer 2' ).getKey(1);
showLayerFX( 'Layer 2', firstEffectID,true );
This isn't ideal but it is the best I could come up with without spending a lot of time.
Code: Select allfunction showLayerFX( layername, effectID, bool ) {
if(bool){
var state = 'Shw ';
}else{
var state = 'Hd ';
}
try {
var desc = new ActionDescriptor();
var list = new ActionList();
var ref = new ActionReference();
ref.putClass( effectID );
ref.putName( charIDToTypeID('Lyr '), layername );
list.putReference( ref );
var ref = new ActionReference();
ref.putClass( charIDToTypeID('Lefx') );
ref.putName( charIDToTypeID('Lyr '), layername );
list.putReference( ref );
desc.putList( charIDToTypeID('null'), list );
executeAction( charIDToTypeID( state ), desc, DialogModes.NO );
} catch (e) {}
};
function getEffectsDescriptorByName( layername ){
var ref = new ActionReference();
ref.putName( charIDToTypeID('Lyr '), layername );
var desc = executeActionGet(ref);
if(desc.hasKey(stringIDToTypeID('layerEffects'))) return desc.getObjectValue(stringIDToTypeID('layerEffects'));
};
var firstEffectID = getEffectsDescriptorByName( 'Layer 2' ).getKey(1);
showLayerFX( 'Layer 2', firstEffectID,true );
-
Paul MR
Turning off layer styles on non-active layer
More interesting info,did another test and the function works fine but only if the active layer has effects, it will then change the status of the referenced layer. How strange is that?
-
bdeshazer
Turning off layer styles on non-active layer
Confirmed the problem in CS4 & CS5 on the Mac platform.
Strangely, one time I could get the desired behavior in CS4 IF I ran Paul's function (using putIndex instead of putIdentifier) while the active layer was ABOVE the target layer index in the layer stack. Activating a layer below the target layer in the layer stack would cause the exception again.
I shut down CS4 and tried this in CS5 and CS6 but was unable to reproduce the semi-desired behavior. I then re-opened CS4 and tried it again and could not repeat the previous results, even with the same file I had been using previously... very strange.
Mike, thanks for your possible solution, I'll deconstruct it and test it shortly.
Strangely, one time I could get the desired behavior in CS4 IF I ran Paul's function (using putIndex instead of putIdentifier) while the active layer was ABOVE the target layer index in the layer stack. Activating a layer below the target layer in the layer stack would cause the exception again.
I shut down CS4 and tried this in CS5 and CS6 but was unable to reproduce the semi-desired behavior. I then re-opened CS4 and tried it again and could not repeat the previous results, even with the same file I had been using previously... very strange.
Mike, thanks for your possible solution, I'll deconstruct it and test it shortly.
-
bdeshazer
Turning off layer styles on non-active layer
Paul MR wrote:More interesting info,did another test and the function works fine but only if the active layer has effects, it will then change the status of the referenced layer. How strange is that?
Ok, confirmed that on CS4, CS5 & CS6 on the Mac platform... this also probably explains my previous message as well as my test image is just a single-layer image that I have been recreating the additional layers with effects on each open/test. In my "semi-working" test I must have created the layer above my target layer by CMD-J /after/ I had already applied the effects to the target layer, thus duplicating the effects as well as the layer's pixel data...
Ok, confirmed that on CS4, CS5 & CS6 on the Mac platform... this also probably explains my previous message as well as my test image is just a single-layer image that I have been recreating the additional layers with effects on each open/test. In my "semi-working" test I must have created the layer above my target layer by CMD-J /after/ I had already applied the effects to the target layer, thus duplicating the effects as well as the layer's pixel data...
-
Paul MR
Turning off layer styles on non-active layer
Thanks Mike that does work fine, here is the same code modified for the Layer ID...
Code: Select allfunction showLayerFX( ID, bool ) {
if(bool){var state = 'Shw ';}else{var state = 'Hd ';}
var ref = new ActionReference();
ref.putIdentifier(charIDToTypeID('Lyr '), ID);
var desc = executeActionGet(ref);
if(desc.hasKey(stringIDToTypeID('layerEffects'))) {
class1 = desc.getObjectValue(stringIDToTypeID('layerEffects')).getKey(1);
}else{return;}
try {
var desc = new ActionDescriptor();
var list = new ActionList();
var ref = new ActionReference();
ref.putClass( class1 );
ref.putIdentifier(charIDToTypeID('Lyr '), ID);
list.putReference( ref );
var ref = new ActionReference();
ref.putClass( charIDToTypeID('Lefx') );
ref.putIdentifier(charIDToTypeID('Lyr '), ID);
list.putReference( ref );
desc.putList( charIDToTypeID('null'), list );
executeAction( charIDToTypeID( state ), desc, DialogModes.NO );
} catch (e) {}
};
showLayerFX( 3,true);
Code: Select allfunction showLayerFX( ID, bool ) {
if(bool){var state = 'Shw ';}else{var state = 'Hd ';}
var ref = new ActionReference();
ref.putIdentifier(charIDToTypeID('Lyr '), ID);
var desc = executeActionGet(ref);
if(desc.hasKey(stringIDToTypeID('layerEffects'))) {
class1 = desc.getObjectValue(stringIDToTypeID('layerEffects')).getKey(1);
}else{return;}
try {
var desc = new ActionDescriptor();
var list = new ActionList();
var ref = new ActionReference();
ref.putClass( class1 );
ref.putIdentifier(charIDToTypeID('Lyr '), ID);
list.putReference( ref );
var ref = new ActionReference();
ref.putClass( charIDToTypeID('Lefx') );
ref.putIdentifier(charIDToTypeID('Lyr '), ID);
list.putReference( ref );
desc.putList( charIDToTypeID('null'), list );
executeAction( charIDToTypeID( state ), desc, DialogModes.NO );
} catch (e) {}
};
showLayerFX( 3,true);