Quantcast
Channel: Adobe Community: Message List - Photoshop Scripting
Viewing all articles
Browse latest Browse all 27456

Re: How to set a group's children to visible with ActionManager?

$
0
0

Hi here is a AM function that will make all the selected groups children visible:

 

bcm_makeAllCHVisible(getSelectedLayersIdx());

 

 

function bcm_makeAllCHVisible( idx ){

     if( idx.constructor != Array ) idx = [ idx ];

     for( var a = 0; a < idx.length; a++ ){

          var x = 0;

          var y = 0;

          var r = 0;

          var i = idx[a];

          for(i; i > 0 ; i--){

               ref = new ActionReference();

               ref.putIndex( charIDToTypeID( 'Lyr ' ), i );

               var desc = executeActionGet(ref);

               var layerName = desc.getString(charIDToTypeID( 'Nm  ' ));

               var ls = desc.getEnumerationValue(stringIDToTypeID("layerSection"));

               ls = typeIDToStringID(ls);

               if(ls == "layerSectionStart"){makeVisibleByIDX( i ); x++};

               if(layerName.match(/^<\/Layer group/) )

               {

                 y ++;

                 r = x - y;

                 if(r == 0 && ls == "layerSectionEnd"){break};

                 continue;

               };

               if(ls == "layerSectionContent"){makeVisibleByIDX( i )};

          };

     }

}

function makeVisibleByIDX( idx ){

     var idShw = charIDToTypeID( "Shw " );

         var desc34 = new ActionDescriptor();

         var idnull = charIDToTypeID( "null" );

             var list7 = new ActionList();

                 var ref36 = new ActionReference();

                 var idLyr = charIDToTypeID( "Lyr " );

                 ref36.putIndex( idLyr, idx );

             list7.putReference( ref36 );

         desc34.putList( idnull, list7 );

     executeAction( idShw, desc34, DialogModes.NO );

}

function hasBackground(){// function to check if there is a background layer

    var res = undefined;

    try{

        var ref = new ActionReference();

        ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID("Nm  "));

        ref.putIndex( charIDToTypeID("Lyr "), 0 );

        executeActionGet(ref).getString(charIDToTypeID("Nm  ") );

        res = true;

    }catch(e){ res = false}

    return res;

}

 

 

function getSelectedLayersIdx(){// get the selected layers index( positon in layer editor)

     var selectedLayers = new Array;

     var ref = new ActionReference();

     ref.putEnumerated( charIDToTypeID('Dcmn'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );

     var desc = executeActionGet(ref);

     var add = 1;

     if(hasBackground()){add = 0}

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

          desc = desc.getList( stringIDToTypeID( 'targetLayers' ));

          var c = desc.count

          var selectedLayers = new Array();

          for(var i=0;i<c;i++){

               selectedLayers.push(  (desc.getReference( i ).getIndex()) + add);

          }

     }else{

          var ref = new ActionReference();

          ref.putProperty( charIDToTypeID('Prpr') , charIDToTypeID( 'ItmI' ));

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

          srs = hasBackground()?executeActionGet(ref).getInteger(charIDToTypeID( 'ItmI' ))-1:executeActionGet(ref).getInteger(charIDToTypeID( 'ItmI' ));

          selectedLayers.push( srs);

     }

     return selectedLayers;

}


Viewing all articles
Browse latest Browse all 27456

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>