Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects “for” cycle not working

  • “for” cycle not working

    Posted by Stefano Cieri on December 30, 2008 at 5:54 am

    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

    Dan Ebberts replied 17 years, 8 months ago 2 Members · 3 Replies
  • 3 Replies
  • Dan Ebberts

    December 30, 2008 at 4:40 pm

    What does getItemIndex() do? Is it possible that it is changing the value of i, which you haven’t delcared as a local variable?

    Dan

  • Stefano Cieri

    December 30, 2008 at 5:33 pm

    Hi Dan,
    thanks for replying that soon (and thanks for your MotionScript.com, which is my favourite resource to learn expressions and scripting). I’m not at home and I can’t check this right now, but you’re probably right.
    getItemIndex(name) is a function which reads all the items in the project and returns the index of the item called as the “name” variable. I used another “for” cycle within the function and probably I called “i” the variable there, too.
    I’ll check and let you know as soon as possible. In the meantime I would ask a couple of things more:
    1. is there any other way to retrieve a certain comp’s or item’s index, knowing its name, than cycling within the entire items’ collection?
    2. you said: “the value of i, which you haven’t delcared as a local variable”. How can I declare a variable as a local one?

    Sorry for being that noob.
    Tanks again,
    s t e

    itgoesgreen.org

    me.itgoesgreen.org

  • Dan Ebberts

    December 30, 2008 at 5:48 pm

    Unfortunately, you have to loop through the items in the project bin to find a comp by name.

    To declare i local to the for loop:

    for (var i=1; i<=cursorComp.numLayers; ++i) { Dan

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy