Advertisement
Guest User

Untitled

a guest
Dec 31st, 2016
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. selectNestedLayers ();
  2.  
  3. function selectNestedLayers(){
  4.     // =======================================================
  5.     var idMk = charIDToTypeID( "Mk  " );
  6.         var desc2729 = new ActionDescriptor();
  7.         var idnull = charIDToTypeID( "null" );
  8.             var ref913 = new ActionReference();
  9.             var idlayerSection = stringIDToTypeID( "layerSection" );
  10.             ref913.putClass( idlayerSection );
  11.         desc2729.putReference( idnull, ref913 );
  12.         var idFrom = charIDToTypeID( "From" );
  13.             var ref914 = new ActionReference();
  14.             var idLyr = charIDToTypeID( "Lyr " );
  15.             var idOrdn = charIDToTypeID( "Ordn" );
  16.             var idTrgt = charIDToTypeID( "Trgt" );
  17.             ref914.putEnumerated( idLyr, idOrdn, idTrgt );
  18.         desc2729.putReference( idFrom, ref914 );
  19.         var idlayerSectionStart = stringIDToTypeID( "layerSectionStart" );
  20.         desc2729.putInteger( idlayerSectionStart, 93 );
  21.         var idlayerSectionEnd = stringIDToTypeID( "layerSectionEnd" );
  22.         desc2729.putInteger( idlayerSectionEnd, 94 );
  23.         var idNm = charIDToTypeID( "Nm  " );
  24.         desc2729.putString( idNm, """Group 1""" );
  25.     executeAction( idMk, desc2729, DialogModes.NO );
  26.  
  27.     // =======================================================
  28.     var idungroupLayersEvent = stringIDToTypeID( "ungroupLayersEvent" );
  29.         var desc2730 = new ActionDescriptor();
  30.         var idnull = charIDToTypeID( "null" );
  31.             var ref915 = new ActionReference();
  32.             var idLyr = charIDToTypeID( "Lyr " );
  33.             var idOrdn = charIDToTypeID( "Ordn" );
  34.             var idTrgt = charIDToTypeID( "Trgt" );
  35.             ref915.putEnumerated( idLyr, idOrdn, idTrgt );
  36.         desc2730.putReference( idnull, ref915 );
  37.     executeAction( idungroupLayersEvent, desc2730, DialogModes.NO );
  38.     //=============================================================
  39.  
  40.     function getSelectedLayers() { // indexes not ids
  41.         var selectedLayers = [];
  42.         try {
  43.             //var backGroundCounter = activeDocument.artLayers[activeDocument.artLayers.length-1].isBackgroundLayer ? 0 : 1; // didn't worked for artboards
  44.             var backGroundCounter = 1;
  45.             try {
  46.                 var dummy = app.activeDocument.backgroundLayer;
  47.                 backGroundCounter = 0;
  48.             }
  49.             catch(e){;} //do nothing
  50.            
  51.             var ref = new ActionReference();
  52.             var keyTargetLayers = app.stringIDToTypeID( 'targetLayers' );
  53.             ref.putProperty( app.charIDToTypeID( 'Prpr' ), keyTargetLayers );
  54.             ref.putEnumerated( app.charIDToTypeID( 'Dcmn' ), app.charIDToTypeID( 'Ordn' ), app.charIDToTypeID( 'Trgt' ) );
  55.             var desc = executeActionGet( ref );
  56.             if ( desc.hasKey( keyTargetLayers ) ) {
  57.                 var layersList = desc.getList( keyTargetLayers );
  58.                 for ( var j = 0; j < layersList.count; j++) {
  59.                     var listRef = layersList.getReference( j );
  60.                     selectedLayers.push( listRef.getIndex() + backGroundCounter );
  61.                 }
  62.                 //hasLayerMask = true;
  63.             }
  64.         }catch(e) {
  65.             ; // do nothing
  66.         }
  67.         return selectedLayers;
  68.     }
  69.  
  70.     var yourLayersIndexes = getSelectedLayers();
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement