Skip to main content
Participating Frequently
December 20, 2011
Answered

Number of Layer effects + Array with effects names

  • December 20, 2011
  • 1 reply
  • 632 views

Hi,

1. I want to ask you, if you don't know function to get count of layer effects.

2. I need function which return array with names or identificators of effects fot each layer.

I have function which return T/F if layer has effect. But I don't know how

write this.

Thank you Domaneni

This topic has been closed for replies.
Correct answer Michael_L_Hale

This function will return an array of effect names for the active layer. You can get the effects count from the array's length property. The effect names are Action Manager names so if you want them to match the GUI you will need to translate. i.e. stroke in action manager is frameFX

function getEffects() {

    var ref = new ActionReference();

    ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

    var desc =   executeActionGet(ref);

    if ( desc.hasKey( stringIDToTypeID( 'layerEffects' ) ) ) {

        var effects = [];

        var effectDesc = desc.getObjectValue(  stringIDToTypeID( 'layerEffects' ) );

        // first key is scale so skip and start with 1

        for ( var effect = 1; effect < effectDesc.count; effect++ ) {

            effects.push( typeIDToStringID( effectDesc.getKey( effect ) ) );

        }

        return effects;

    }

}

1 reply

Michael_L_HaleCorrect answer
Inspiring
December 20, 2011

This function will return an array of effect names for the active layer. You can get the effects count from the array's length property. The effect names are Action Manager names so if you want them to match the GUI you will need to translate. i.e. stroke in action manager is frameFX

function getEffects() {

    var ref = new ActionReference();

    ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

    var desc =   executeActionGet(ref);

    if ( desc.hasKey( stringIDToTypeID( 'layerEffects' ) ) ) {

        var effects = [];

        var effectDesc = desc.getObjectValue(  stringIDToTypeID( 'layerEffects' ) );

        // first key is scale so skip and start with 1

        for ( var effect = 1; effect < effectDesc.count; effect++ ) {

            effects.push( typeIDToStringID( effectDesc.getKey( effect ) ) );

        }

        return effects;

    }

}