Copy layers to another group

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

kostyanet

Copy layers to another group

Post by kostyanet »

Hi there. With ScriptListener I wrote a simple function for duplicate selected layers to a group:

Code: Select allfunction dupLayers(index) {

var id450 = cTID( "move" );
    var desc87 = new ActionDescriptor();
    var ref74 = new ActionReference();
    ref74.putEnumerated( cTID( "Lyr " ), cTID( "Ordn" ), cTID( "Trgt" ) );
    desc87.putReference( cTID( "null" ), ref74 );
    var ref75 = new ActionReference();
    ref75.putIndex( cTID( "Lyr " ), --index );
    desc87.putReference( cTID( "T   " ), ref75 );
    desc87.putBoolean( cTID( "Dplc" ), true );
    desc87.putBoolean( cTID( "Adjs" ), false );
executeAction( id450, desc87, DialogModes.NO );
}

It works fine but how to get index of the group without making it active? When a group becomes active I lost selected layers.

PS CS2

Professional AI Audio Generation within Adobe Premiere Pro - Download Free Plugin here

Mike Hale

Copy layers to another group

Post by Mike Hale »

You can get the AM index of a layer or layerSet by name if the names in the document are unique.

Code: Select allfunction getLayerIndexByName(name) {
    var ref = new ActionReference();
    ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "ItmI" ));
    ref.putName( charIDToTypeID( "Lyr " ), name );
    return executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ));;
};

Note that if the name are not unique this will return the top most layer/layerSet AM index in the layer stack.
kostyanet

Copy layers to another group

Post by kostyanet »

A lot of thanks.

BTW, there is the line:

desc87.putBoolean( cTID( "Adjs" ), false );

In SDK I have read: classAdjustment ('Adjs') but what is it mean in current context?