Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Trying to pass sampleImage to variable

  • Trying to pass sampleImage to variable

    Posted by Bryan Woods on December 17, 2012 at 7:00 pm

    What am I doing wrong here? I’m trying to take Dan’s advice from a previous project and apply sampleImage to anchor point, gather the result and then remove the expression and reapply the result. Kind of like baking, but without generating keyframes.

    This script technically “Works”, but doesn’t do as I wanted. The expression remains after running.

    {

    //Set Undo Group
    app.beginUndoGroup("test");

    //Define project and and active items
    var proj = app.project;
    var theComp = proj.activeItem;
    var selectedLayers = theComp.selectedLayers;

    //For every layer selected...
    for (var i = 0; i < selectedLayers.length; i++) {
    var myLayer = selectedLayers[i];
    myLayer.property("Anchor Point").expression = "topEdge = 0; for (i = 0; i <= height; i++){ temp = sampleImage([width/2,i],[width/2,0.5],true,time); if (temp[3] > 0){ topEdge = i; break; } } bottomEdge = height-1; for (i = height-1; i >= 0; i--){ temp = sampleImage([width/2,i],[width/2,0.5],true,time); if (temp[3] > 0){ bottomEdge = i; break; } } value + [0,(topEdge+bottomEdge-height)/2]";
    var newAnchorX = myLayer.property("Anchor Point").value[0];
    var newAnchorY = myLayer.property("Anchor Point").value[1];
    myLayer.property("Anchor Point").setValue([newAnchorX,newAnchorY]);
    }

    app.endUndoGroup();

    }

    Bryan Woods replied 13 years, 7 months ago 2 Members · 4 Replies
  • 4 Replies
  • Dan Ebberts

    December 17, 2012 at 7:25 pm

    Try adding this as the last statement in your loop:

    myLayer.property(“Anchor Point”).expression = “”;

    Dan

  • Bryan Woods

    December 17, 2012 at 7:33 pm

    Man, I was so close. So simple I completely over look just overwriting the expression with a blank. hahaha.

    Thank you once again for your help.

    Could I get your opinion? The way I went about it… does that seem the most efficient? I’m trying to learn how to optimize my code instead of brute-forcing it. If you can think of a simpler way to accomplish what I have, by all means please let me know!

  • Dan Ebberts

    December 17, 2012 at 8:05 pm

    It looks pretty good to me. You could replace this:

    var newAnchorX = myLayer.property(“Anchor Point”).value[0];
    var newAnchorY = myLayer.property(“Anchor Point”).value[1];
    myLayer.property(“Anchor Point”).setValue([newAnchorX,newAnchorY]);

    with this:

    var newAnchor = myLayer.property(“Anchor Point”).value;
    myLayer.property(“Anchor Point”).setValue(newAnchor);

    Dan

  • Bryan Woods

    December 17, 2012 at 9:29 pm

    Ah so .value can contain an array without indicating what it should be. I was under the impression you had to separate it out. Thanks for the suggestion!

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