-
Trying to pass sampleImage to variable
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();
}