Skip to main content
Participant
August 5, 2009
Answered

Get information about layer styles with script

  • August 5, 2009
  • 2 replies
  • 1504 views

Is there a way for a script to get information about the currently existing layer styles on a layer?

For example, can I find out if a layer has a dropShadow, and if so, can I find that dropShadow's size, transparency, color, etc...?

This topic has been closed for replies.
Correct answer Michael_L_Hale

If you don't have CS4 you will need Xbytor's script. With CS4 you can the the descriptor from the layer

var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var desc = executeActionGet(ref).getObjectValue(stringIDToTypeID('layerEffects'));
if( desc.hasKey( stringIDToTypeID('dropShadow') ) ){
     desc = desc.getObjectValue(stringIDToTypeID('dropShadow'));
     alert('opacity = '+ desc.getDouble( stringIDToTypeID('opacity') ) );
     alert('distance = '+ desc.getDouble( stringIDToTypeID('distance') ) );
     alert('spread = '+ desc.getDouble( stringIDToTypeID('chokeMatte') ) );// spread
     alert('blur = '+ desc.getDouble( stringIDToTypeID('blur') ) );
     var desc = desc.getObjectValue(stringIDToTypeID('color'));
     var r = desc.getDouble( stringIDToTypeID('red') ) ;
     var g = desc.getDouble( stringIDToTypeID('green') ) ;
     var b = desc.getDouble( stringIDToTypeID('blue') ) ;
     alert( 'r = ' + r +'\rg = ' + g + '\rb = ' + b );
}

2 replies

Michael_L_HaleCorrect answer
Inspiring
August 5, 2009

If you don't have CS4 you will need Xbytor's script. With CS4 you can the the descriptor from the layer

var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var desc = executeActionGet(ref).getObjectValue(stringIDToTypeID('layerEffects'));
if( desc.hasKey( stringIDToTypeID('dropShadow') ) ){
     desc = desc.getObjectValue(stringIDToTypeID('dropShadow'));
     alert('opacity = '+ desc.getDouble( stringIDToTypeID('opacity') ) );
     alert('distance = '+ desc.getDouble( stringIDToTypeID('distance') ) );
     alert('spread = '+ desc.getDouble( stringIDToTypeID('chokeMatte') ) );// spread
     alert('blur = '+ desc.getDouble( stringIDToTypeID('blur') ) );
     var desc = desc.getObjectValue(stringIDToTypeID('color'));
     var r = desc.getDouble( stringIDToTypeID('red') ) ;
     var g = desc.getDouble( stringIDToTypeID('green') ) ;
     var b = desc.getDouble( stringIDToTypeID('blue') ) ;
     alert( 'r = ' + r +'\rg = ' + g + '\rb = ' + b );
}
dmccluerAuthor
Participant
August 5, 2009

Sweet.  That's even easier

Inspiring
August 5, 2009

There is no easy way to get this information, but you can get to it.

Get my xtools library (from ps-scripts.sourceforge.net) and in there you will find xtools/xlib/Styles.js.

In there, you will find Styles.getLayerStyleDescriptor(). The will get you the ActionDescriptor that

describes the styles applied to a layer.

-X

dmccluerAuthor
Participant
August 5, 2009

haven't tried it out yet, but from a quick glance at it that looks like a really useful collection of tools - thanks for sharing!