Dynamic Layer Effects

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

xbytor

Dynamic Layer Effects

Post by xbytor »

Creating a new descriptor from scratch won't work. The problem appears to be that something is getting cached outside of the JS interpreter but associated with the layer.
Duping the layer should get around the problem. Maybe.
Mike Hale

Dynamic Layer Effects

Post by Mike Hale »

Well here is what I was thinking. It's not finished but it lets me turn on and off the outerGlow effect as many times as I care to run the script.
Code: Select allfunction getFxDesc(){
   var ref = new ActionReference();
   ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
   var desc = executeActionGet(ref);
   if(desc.hasKey(stringIDToTypeID('layerEffects'))){
      var fxDesc = desc.getObjectValue(stringIDToTypeID('layerEffects'));
   }
   if(undefined != fxDesc) return fxDesc;
};
function getOuterGlowOptions( desc ){
   var opts = {};
   opts.enabled = desc.getBoolean(charIDToTypeID('enab'));
   opts.blendMode = desc.getEnumerationValue(charIDToTypeID('Md  '));
   opts.opacity = desc.getUnitDoubleValue(charIDToTypeID('Opct'));
   return opts;
};
function ftn1(fxOptions) {
    var desc302 = new ActionDescriptor();
        var ref38 = new ActionReference();
        ref38.putProperty( charIDToTypeID('Prpr'), charIDToTypeID('Lefx') );
        ref38.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
    desc302.putReference( charIDToTypeID('null'), ref38 );
   if(undefined != fxOptions.outerGlow ){
        var desc303 = new ActionDescriptor();
        desc303.putUnitDouble( charIDToTypeID('Scl '), fxOptions.scaleUnit, fxOptions.scaleValue );
            var desc304 = new ActionDescriptor();
            desc304.putBoolean( charIDToTypeID('enab'), fxOptions.outerGlow.enabled );
            desc304.putEnumerated( charIDToTypeID('Md  '), charIDToTypeID('BlnM'), fxOptions.outerGlow.blendMode );
                var desc305 = new ActionDescriptor();
                desc305.putDouble( charIDToTypeID('Rd  '), 255.000000 );
                desc305.putDouble( charIDToTypeID('Grn '), 255.000000 );
                desc305.putDouble( charIDToTypeID('Bl  '), 255.000000 );
            desc304.putObject( charIDToTypeID('Clr '), charIDToTypeID('RGBC'), desc305 );
            desc304.putUnitDouble( charIDToTypeID('Opct'), charIDToTypeID('#Prc'), fxOptions.outerGlow.opacity );
            desc304.putEnumerated( charIDToTypeID('GlwT'), charIDToTypeID('BETE'), charIDToTypeID('SfBL') );
            desc304.putUnitDouble( charIDToTypeID('Ckmt'), charIDToTypeID('#Pxl'), 3.000000 );
            desc304.putUnitDouble( charIDToTypeID('blur'), charIDToTypeID('#Pxl'), 11.000000 );
            desc304.putUnitDouble( charIDToTypeID('Nose'), charIDToTypeID('#Prc'), 2.000000 );
            desc304.putUnitDouble( charIDToTypeID('ShdN'), charIDToTypeID('#Prc'), 2.000000 );
            desc304.putBoolean( charIDToTypeID('AntA'), true );
                var desc306 = new ActionDescriptor();
                desc306.putString( charIDToTypeID('Nm  '), "Default" );
            desc304.putObject( charIDToTypeID('TrnS'), charIDToTypeID('ShpC'), desc306 );
            desc304.putUnitDouble( charIDToTypeID('Inpr'), charIDToTypeID('#Prc'), 53.000000 );
        desc303.putObject( charIDToTypeID('OrGl'), charIDToTypeID('OrGl'), desc304 );
   }
    desc302.putObject( charIDToTypeID('T   '), charIDToTypeID('Lefx'), desc303 );
    executeAction( charIDToTypeID('setd'), desc302, DialogModes.NO );
};

var fxOptions = {};
var fxDesc = getFxDesc();
fxOptions.scaleValue = fxDesc.getUnitDoubleValue(charIDToTypeID('Scl '));
fxOptions.scaleUnit = fxDesc.getUnitDoubleType(charIDToTypeID('Scl '));
if(fxDesc.hasKey(charIDToTypeID('OrGl'))) {
   fxOptions.outerGlow = getOuterGlowOptions( fxDesc.getObjectValue(charIDToTypeID('OrGl')));
}
fxOptions.outerGlow.enabled = true;
ftn1(fxOptions);
Note as I said it's not a working script. If the layer has other effects they will be lost. It's more just a test of the concept.