-
Script to create solid above currently selected layer.
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<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 <= 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\”