Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- selectNestedLayers ();
- function selectNestedLayers(){
- // =======================================================
- var idMk = charIDToTypeID( "Mk " );
- var desc2729 = new ActionDescriptor();
- var idnull = charIDToTypeID( "null" );
- var ref913 = new ActionReference();
- var idlayerSection = stringIDToTypeID( "layerSection" );
- ref913.putClass( idlayerSection );
- desc2729.putReference( idnull, ref913 );
- var idFrom = charIDToTypeID( "From" );
- var ref914 = new ActionReference();
- var idLyr = charIDToTypeID( "Lyr " );
- var idOrdn = charIDToTypeID( "Ordn" );
- var idTrgt = charIDToTypeID( "Trgt" );
- ref914.putEnumerated( idLyr, idOrdn, idTrgt );
- desc2729.putReference( idFrom, ref914 );
- var idlayerSectionStart = stringIDToTypeID( "layerSectionStart" );
- desc2729.putInteger( idlayerSectionStart, 93 );
- var idlayerSectionEnd = stringIDToTypeID( "layerSectionEnd" );
- desc2729.putInteger( idlayerSectionEnd, 94 );
- var idNm = charIDToTypeID( "Nm " );
- desc2729.putString( idNm, """Group 1""" );
- executeAction( idMk, desc2729, DialogModes.NO );
- // =======================================================
- var idungroupLayersEvent = stringIDToTypeID( "ungroupLayersEvent" );
- var desc2730 = new ActionDescriptor();
- var idnull = charIDToTypeID( "null" );
- var ref915 = new ActionReference();
- var idLyr = charIDToTypeID( "Lyr " );
- var idOrdn = charIDToTypeID( "Ordn" );
- var idTrgt = charIDToTypeID( "Trgt" );
- ref915.putEnumerated( idLyr, idOrdn, idTrgt );
- desc2730.putReference( idnull, ref915 );
- executeAction( idungroupLayersEvent, desc2730, DialogModes.NO );
- //=============================================================
- function getSelectedLayers() { // indexes not ids
- var selectedLayers = [];
- try {
- //var backGroundCounter = activeDocument.artLayers[activeDocument.artLayers.length-1].isBackgroundLayer ? 0 : 1; // didn't worked for artboards
- var backGroundCounter = 1;
- try {
- var dummy = app.activeDocument.backgroundLayer;
- backGroundCounter = 0;
- }
- catch(e){;} //do nothing
- var ref = new ActionReference();
- var keyTargetLayers = app.stringIDToTypeID( 'targetLayers' );
- ref.putProperty( app.charIDToTypeID( 'Prpr' ), keyTargetLayers );
- ref.putEnumerated( app.charIDToTypeID( 'Dcmn' ), app.charIDToTypeID( 'Ordn' ), app.charIDToTypeID( 'Trgt' ) );
- var desc = executeActionGet( ref );
- if ( desc.hasKey( keyTargetLayers ) ) {
- var layersList = desc.getList( keyTargetLayers );
- for ( var j = 0; j < layersList.count; j++) {
- var listRef = layersList.getReference( j );
- selectedLayers.push( listRef.getIndex() + backGroundCounter );
- }
- //hasLayerMask = true;
- }
- }catch(e) {
- ; // do nothing
- }
- return selectedLayers;
- }
- var yourLayersIndexes = getSelectedLayers();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement