Copy link to clipboard
Copied
I have written a script to duplicate the currently selected layer and then move the drop shadow from the duplicate back to the original. Sometimes it works, sometimes it doesn't. I have not noticed any consistent reason WHY it runs into an error.
It is sometimes throwing an 8800 error, "Move" command not currently available. This is the line where it throws the error;
executeAction( idmove, desc55, DialogModes.NO );
Could someone tell me where I have gone wrong? As mentioned, sometimes the script works perfectly, sometimes it throws that error. All tested layers have the exact same style settings; a simple outer glow and a drop shadow.
I barely know what I am doing when it comes to Photoshop scripts so help would really be appreciated.
The purpose of this script is to get the shadow as a separate flat layer while keeping all other layer style settings.
Below is the full script.
#target photoshop
// Switch off any dialog boxes
displayDialogs = DialogModes.NO; // OFF
var srcDoc = app.activeDocument;
var theLayer = srcDoc.activeLayer;
var ref = new ActionReference();
ref.putEnumerated(charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt')); // reference is active layer
var layerDesc = executeActionGet(ref);
var myLayerID = layerDesc.getInteger(stringIDToTypeID('layerID'));
// select by layer ID
//alert("Layer ID: " + myLayerID + "\n" + srcDoc.activeLayer.name);
//select_layer_by_ID(myLayerID);
// Switch on any dialog boxes
displayDialogs = DialogModes.ALL; // ON
//Duplicate current layer
var idDplc = charIDToTypeID( "Dplc" );
var desc22 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref22 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref22.putEnumerated( idLyr, idOrdn, idTrgt );
desc22.putReference( idnull, ref22 );
var idNm = charIDToTypeID( "Nm " );
desc22.putString( idNm, ( theLayer.name + " copy" ) );
var idVrsn = charIDToTypeID( "Vrsn" );
desc22.putInteger( idVrsn, 5 );
executeAction( idDplc, desc22, DialogModes.NO );
// Move drop shadow from active layer to previous layer via ID
var idmove = charIDToTypeID( "move" );
var desc55 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref44 = new ActionReference();
var idDrSh = charIDToTypeID( "DrSh" );
ref44.putClass( idDrSh );
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref44.putEnumerated( idLyr, idOrdn, idTrgt );
desc55.putReference( idnull, ref44 );
var idT = charIDToTypeID( "T " );
var ref55 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
ref55.putIndex( idLyr, myLayerID );
desc55.putReference( idT, ref55 );
executeAction( idmove, desc55, DialogModes.NO );
// back to original layer via ID
select_layer_by_ID(myLayerID);
// rasterize smart objects and type
if (app.activeDocument.activeLayer.kind == "LayerKind.SMARTOBJECT") {
var idrasterizeLayer = stringIDToTypeID( "rasterizeLayer" );
var desc33 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref33 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref33.putEnumerated( idLyr, idOrdn, idTrgt );
desc33.putReference( idnull, ref33 );
executeAction( idrasterizeLayer, desc33, DialogModes.NO );
} else if (app.activeDocument.activeLayer.kind == "LayerKind.TEXT") {
var idrasterizeLayer = stringIDToTypeID( "rasterizeLayer" );
var desc99 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref99 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref99.putEnumerated( idLyr, idOrdn, idTrgt );
desc99.putReference( idnull, ref99 );
var idWhat = charIDToTypeID( "What" );
var idrasterizeItem = stringIDToTypeID( "rasterizeItem" );
var idType = charIDToTypeID( "Type" );
desc99.putEnumerated( idWhat, idrasterizeItem, idType );
executeAction( idrasterizeLayer, desc99, DialogModes.NO );
}
// run action to flatten & rasterize the dropshadow on active layer
playAction ("ScriptFunctions","FlatShadow");
function playAction(actionSet, actionName){
var idPly = charIDToTypeID( "Ply " );
var desc66 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref66 = new ActionReference();
var idActn = charIDToTypeID( "Actn" );
ref66.putName( idActn, actionName );
var idASet = charIDToTypeID( "ASet" );
ref66.putName( idASet, actionSet );
desc66.putReference( idnull, ref66 );
executeAction( idPly, desc66, DialogModes.NO );
}
// function SELECT LAYER BY ID(int, boolean)
// --------------------------------------------------------
function select_layer_by_ID(id, add)
{
if (add == undefined) add = false;
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putIdentifier(charIDToTypeID('Lyr '), id);
desc1.putReference(charIDToTypeID('null'), ref1);
if (add) desc1.putEnumerated(stringIDToTypeID("selectionModifier"), stringIDToTypeID("selectionModifierType"), stringIDToTypeID("addToSelection"));
executeAction(charIDToTypeID('slct'), desc1, DialogModes.NO);
}
Copy link to clipboard
Copied
You get this as an ID
var myLayerID = layerDesc.getInteger(stringIDToTypeID('layerID'));ref55.putIndex( idLyr, myLayerID );
Copy link to clipboard
Copied
I figured that might be my issue, but I wasn't sure. I also had no real idea how to fix it.
The error was occuring before I inserted the myLayerID variable. Previously it was just the number 11. I thought the unchanging number might be why it only worked sometimes. So I replaced the static number with the LayerID because I saw the ifLyr infront of it and though that was the number it was looking for.
Since I left this post, I did some additional testing with ScriptListener and I cannot figure out what where it is getting the number from. It clearly isn't the layerID as those to don't seem to match most of the time.
What value do I need to store and pass to ref55.putIndex( idLyr, ??? ); to make this work?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
That seems to have fixed it, thanks!
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more