Michael_L_Hale@adobeforums.com wrote:
> I do not know of any direct way of using a JS layer object with scriptlistner code.
There are four ways of specifying which layer to use in scriptlistener code:
1) By name
2) By index
3) By ID
4) By making the layer the activeLayer.
1) and 4) are easiest. 2) and 3) are a bit more difficult. I have APIs in
stdlib.js and other scripts that use all four mechanism, but, by and larger, I
use 4).
For instance, here is a function that clears layer styles/effects:
Stdlib.clearEffects = function(doc, layer) {
// _ftn contains the actual scriptingListener code
function _ftn() {
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated( cTID('Lyr '), cTID('Ordn'), cTID('Trgt') );
desc.putReference( cTID('null'), ref );
executeAction( sTID('disableLayerStyle'), desc, DialogModes.NO );
}
// this block of code switches to the desired doc and layer
// (if specified)
var ad = app.activeDocument;
var al = app.activeLayer;
if (doc) {
app.activeDocument= doc;
}
if (layer) {
app.activelayer = layer;
}
try {
_ftn(); // call the actual code
} finally {
// reset back to the original doc and layer
if (doc) {
app.activeDocument = ad;
}
if (layer) {
app.activelayer = al;
}
}
};
This way it doesn't matter what the active document and layer are when the
function is called.
-X
--
for photoshop scripting solutions of all sorts
contact: xbytor@gmail.com