No announcement yet.

Looping script with new parameters

  • Filter
  • Time
  • Show
Clear All
new posts

  • Looping script with new parameters

    I'm trying to make this script working in a loop and change parameters in each new loop:

    var layerRef = app.activeDocument.artLayers.getByName("1");
    layerRef.visible = true;

    function saveJPEG( doc, saveFile, qty ) {
    var saveOptions = new JPEGSaveOptions( );
    saveOptions.embedColorProfile = true;
    saveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
    saveOptions.matte = MatteType.NONE;
    saveOptions.quality = qty;
    doc.saveAs( saveFile, saveOptions, true );
    saveJPEG( app.activeDocument, new File('~/Desktop/1.jpg'), 10 );

    The script is making later "1" visible and than save it in to jpeg as "1.jpg". In second loop I need it to make layer 2 visible (layer 1 is still visible - layers are blending) and save it as 2.jpeg. In third loop: layer 3 and save file 3.jpeg, ect...

    Thank you.

  • #2
    Re: Looping script with new parameters

    I need to check what it returns if no layer exists with that name. I'm assuming you use a variable number of layers. Assuming you follow that naming convention, this should work. It's not robust. There are many many things that could fail silently.

    I can tell you how to get that working if you tell me how you want the loop to terminate. Are you going through the same number of layers using that same naming convention each time? I don't know a way to iterate through all layers top to bottom or bottom to top. I just looked at photoshop's api reference to see if it has any direct way to traverse the layer stack. It would be sensible, but I don't see it.


    Related Topics