-
“for” cycle not working
Hi everybody,
I’m trying to make a script which reads each layer in a comp and verifies if it has Hue/Saturation effect applied; if hsl effect is applied, the script should replace the layer with a new one, which has an rgb color correspondant to the hsl.
The function looks like this:clr.onClick = function(){
for (i=1; i<=cursorComp.numLayers; ++i) { alert("i"); tempLayer = cursorComp.layer(i); layerColor = tempLayer.effect("ADBE HUE SATURATION"); if(layerColor!= null){ currentHSV = new Array(); currentHSV[0] = layerColor.property(7).value; currentHSV[1] = layerColor.property(8).value; currentHSV[2] = layerColor.property(9).value; HSVtoRGB(currentHSV); // returns an rgb array n = i+": "+rgb[0]+" "+rgb[1]+" "+rgb[2]; w = cursorComp.width; h = cursorComp.height; tempSolid = cursorComp.layers.addSolid(rgb, n, w, h, 1); getItemIndex(n); tempSolidItem = app.project.item(value); tempLayer.replaceSource(tempSolidItem,true); cursorComp.layer(tempSolid.index).remove(); alert("o"); } alert("e"); } } apparently the scripts works fine until the first layer with hue/saturation is encountered. For that layer, every action within the "if" condition is applyed. But immediately after that, the script interrupts, I can't understand why. As you can see, I put a couple of alerts to verify where the script exactly stops. As the script is exectuted what happens is: 1. "i" and "e" are shown for every layer without the hsl effect 2. "o" is shown as the first layer with effects is encountered (and solid replacement actually takes place within the project) 3. "e" appears again, meaning that the "if" condition ends correctly 4. "i" doesn't appear again, meaning (I guess) that the "for" cycle is interrupted Can anybody tell me why this happens? Thank you very much (hope I was clear enough), s itgoesgreen.org
me.itgoesgreen.org