ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Script to create solid above currently selected layer.

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Daniel Hashimoto
Script to create solid above currently selected layer.
on Apr 13, 2018 at 8:09:45 pm
Last Edited By Daniel Hashimoto on Apr 13, 2018 at 9:36:08 pm

I have a layer selected in my project, I want to create a solid directly above it in the layer stack. That's the specific help I need.

Some more detailed context (if your'e curious): I work with motioned-track data with a lot of 3-D Nulls, and sometimes I'd like to extrapolate a plane from a given 3 points.

I'm using some info from Dan Ebberts and Walter Soyka, to cobble a script together to create a 3D solid that's aligned to 3 3-D nulls. The script creates a 3D solid, uses Walter's code to align it to the 3 nulls, and then uses some of Dan's methods to bake the expression and just keep the result.

This totally works if I have 3 3-D nulls at the top of my layer stack, and run it - but I'd love to be able to just run it with by highlighting the top-most null and running the script.

In my ideal world, I'd shift-select the three nulls and then run this script - but I believe you can't pull data from multiple selections into a script?

{
app.beginUndoGroup("Create Aligned Solid");

myComp = app.project.item(1);
mySolid = myComp.layers.addSolid([1.0,1.0,1.0], "Solid", 2000, 2000, 1);
mySolid.threeDLayer = true;
myPosition = mySolid.property("position");
myOrientation = mySolid.property("orientation");
myPosition.expression="I=index; p1 = thisComp.layer(I+1).transform.position; p2 = thisComp.layer(I+2).transform.position; p3 = thisComp.layer(I+3).transform.position; centroid = div(p1+p2+p3,3);";
myOrientation.expression="I=index; p1 = thisComp.layer(I+1).transform.position; p2 = thisComp.layer(I+2).transform.position; p3 = thisComp.layer(I+3).transform.position; centroid = div(p1+p2+p3,3);n = normalize(cross(p2-p1,p3-p1)); lookAt(centroid,centroid+n)";

function convertExpressionToValue(prop, evalTime)
{
if (prop.expressionEnabled && prop.numKeys&lt;1)
{
prop.setValue(prop.valueAtTime(evalTime,false));
prop.expressionEnabled = false; } return;
}
}
var myComp = app.project.activeItem;
if (myComp instanceof CompItem)
{
var i, numLayers=myComp.numLayers;
var myLayer, evalTime;
for (i = 1; i &lt;= numLayers; i++)
{
myLayer = myComp.layer(i);
evalTime = myLayer.inPoint;
try{ convertExpressionToValue(myLayer.property("position"), evalTime);} catch(err){ };
try{ convertExpressionToValue(myLayer.property("orientation"), evalTime);} catch(err){ };
}
}
app.endUndoGroup();



- Daniel Hashimoto
"Action Movie Dad"


Return to posts index

James Ronan
Re: Script to create solid above currently selected layer.
on Apr 14, 2018 at 8:10:55 am

Try using the .moveBefore() method.

var myLayers, myComp;
myComp = app.project.activeItem;
myLayers = myComp.selectedLayers; // array of selected layers

var newSolid = app.project.activeItem.layers.addSolid([0, 1, 0], myLayers[0].name + " - Solid", myComp.width, myComp.height, myComp.pixelAspect, myComp.duration);
newSolid.label = 9;

newSolid.moveBefore(myLayers[0]); // moves new Solid before first selected Layer


Return to posts index

Daniel Hashimoto
Re: Script to create solid above currently selected layer.
on Apr 16, 2018 at 5:36:21 pm

Thank you so much! I integrated it and it's doing just what I'd hoped.

- Daniel Hashimoto
"Action Movie Dad"


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]