Quantcast
Channel: Adobe Community: Message List
Viewing all articles
Browse latest Browse all 87055

Re: Looping through layers is slow.

$
0
0

I don't think that AM will help to much, the time eating operation is the resize and you can't do anything with AM to make it faster,

the only think in where the AM could help is the going through layers, other than that I don't see how you can make it faster...

 

Here is a code with AM that will do what your function is doing, I've compared the time for both of them and there is a small improvement with AM in terms of time but it's not that much noticeable.

 

function BCM_saveAsFolders( pathname ){

  refDoc1 = app.activeDocument;

  var sizes = {w:500, h:500};

    var tempDoc1 = app.documents.add(500,500, 72, "BCM_rrrre_tempDoc1", NewDocumentMode.RGB, DocumentFill.TRANSPARENT); 

  app.activeDocument = refDoc1;

  var ref = new ActionReference();

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

    var aa = 0;

    try{app.activeDocument.backgroundLayer}catch(err){aa = 1};

  var count = executeActionGet(ref).getInteger(charIDToTypeID('Cnt ')) - aa;// the number of layers in the document

  var x, y, r = 0;

  var currentFolder = new Folder(pathname);

  if(!currentFolder.exists){currentFolder.create()};

  for(i = count; i >= 0 ; i--){// the recursive loop

  ref = new ActionReference();

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

     try{

      var desc = executeActionGet(ref);

     }catch(err){ break; }

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

        var Id = desc.getInteger(stringIDToTypeID( 'layerID' ));

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

        ls = typeIDToStringID(ls);

        var vis = desc.getInteger(stringIDToTypeID( 'visible' ));r

            if(ls == 'layerSectionContent'){

            duplicateTotempDoc1umentAndSaveByIDX(i, (currentFolder.fullName +"/"+layerName), sizes, tempDoc1);

            app.activeDocument = refDoc1;

            }

            if(ls == 'layerSectionStart'){// if it's the start of a layer set

            currentFolder = new Folder(currentFolder.fullName +"/"+layerName);

            if( !currentFolder.exists ){

            currentFolder.create();

            }

            }

            if(ls == 'layerSectionEnd'){// if it's the end of a layerSet

            var cPthStr = currentFolder.fullName.toString();

            currentFolder = new Folder(cPthStr.substring(0,cPthStr.lastIndexOf("/")));

            }

  }

    tempDoc1.close (SaveOptions.DONOTSAVECHANGES);

}

function duplicateTotempDoc1umentAndSaveByIDX(idx, pathname, size, tempDoc1){

  // =======================================================duplicate layer to a new document

  var idDplc = charIDToTypeID( "Dplc" );

     var desc57 = new ActionDescriptor();

     var idnull = charIDToTypeID( "null" );

         var ref47 = new ActionReference();

         ref47.putIndex( charIDToTypeID( "Lyr " ), idx );

     desc57.putReference( idnull, ref47 );

     var idT = charIDToTypeID( "T   " );

         var ref48 = new ActionReference();

         var idDcmn = charIDToTypeID( "Dcmn" );

         ref48.putName( idDcmn, "BCM_rrrre_tempDoc1" );

     desc57.putReference( idT, ref48 );

     var idVrsn = charIDToTypeID( "Vrsn" );

     desc57.putInteger( idVrsn, 5 );

  executeAction( idDplc, desc57, DialogModes.NO );

 

 

 

  app.activeDocument = tempDoc1;

    tempDoc1.activeLayer.resize(500, 500);

  var options = new ExportOptionsSaveForWeb(); 

  options.format = SaveDocumentType.PNG; 

  options.PNG8 = false; 

  options.transparency = true; 

  options.optimized = true; 

  //Export Save for Web in the current folder 

  tempDoc1.exportDocument(new File(pathname +'.png'), ExportType.SAVEFORWEB, options);

  tempDoc1.activeLayer.remove(); 

}

// var startTime = new Date().getTime();

BCM_saveAsFolders(Folder.desktop +"/test");

// var endTime = new Date().getTime();

// alert(endTime - startTime);

 


Viewing all articles
Browse latest Browse all 87055

Trending Articles



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