lundi 23 juillet 2018

Problems with for loop not stopping

I have an image on a layer called original, which I will be comparing histograms against 3 other images (one of them being an exact copy of the original image). This copy is the third layer from the top, i = 2. For debugging purposes, when i = 2 I color the layer in the layer palette red and turn visibility off. The problem that I am having is that the loop seems to be stuck on i = 2. My loop won't continue to the next layers.

    #target photoshop

//  call the source document
var srcDoc = app.activeDocument;
var original = srcDoc.artLayers.getByName("original");
var layers = srcDoc.layers;

startRulerUnits = app.preferences.rulerUnits;
startTypeUnits = app.preferences.typeUnits;

var original_units = app.preferences.rulerUnits;

//app.preferences.rulerUnits = Units.PERCENT;

var layNum = srcDoc.artLayers.length;

srcDoc.activeLayer = original;
original.blendMode = BlendMode.DIFFERENCE;


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

    if (i = 2){
        srcDoc.activeLayer = layers[i];
        layercolor("red");
        layers[i].visible = false;
       }
}

 function layercolor(colour) {
         switch (colour.toLocaleLowerCase()){  
        case 'red': colour = 'Rd  '; break;  
        case 'orange' : colour = 'Orng'; break;  
        case 'yellow' : colour = 'Ylw '; break;  
        case 'yellow' : colour = 'Ylw '; break;  
        case 'green' : colour = 'Grn '; break;  
        case 'blue' : colour = 'Bl  '; break;  
        case 'violet' : colour = 'Vlt '; break;  
        case 'gray' : colour = 'Gry '; break;  
        case 'none' : colour = 'None'; break;  
        default : colour = 'None'; break;  
        } 

    var desc = new ActionDescriptor();  
        var ref = new ActionReference();  
        ref.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );  
    desc.putReference( charIDToTypeID('null'), ref );  
        var desc2 = new ActionDescriptor();  
        desc2.putEnumerated( charIDToTypeID('Clr '), charIDToTypeID('Clr '), charIDToTypeID(colour) );  
    desc.putObject( charIDToTypeID('T   '), charIDToTypeID('Lyr '), desc2 );  
    executeAction( charIDToTypeID('setd'), desc, DialogModes.NO ); 
 }; 

Aucun commentaire:

Enregistrer un commentaire