ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Re: How to Bezier Path with no keyframes ?

COW Forums : Adobe After Effects

FAQ   •   VIEW ALL   •   ADD A NEW POST   •   PRINT
Respond to this post   •   Return to posts index   •   Read entire thread


Oleg Pirogov
Re: How to Bezier Path with no keyframes ?
on Feb 2, 2019 at 3:30:30 pm

I've written a script which does the thing for every selected property of shape type (i.e. select the shape path and run the script):



//the script smooths (sets interpolation to Auto Bezier) selected shape properties

//smooths a shape path
function shapeSmoother(shape){
//create dummy composition and a text layer in it
var comp = app.project.items.addComp("Dummy", 100, 100, 1, 1, 1);
var pos = comp.layers.addText().transform.position;

//create key frames in null position for every shape vertex
var newKey;
for (var i=0; i<shape.value.vertices.length; i++){
newKey = pos.addKey(i);
pos.setValueAtKey(newKey, shape.value.vertices[i]);
}

//smooth text's motion path by setting spatial interpolation to Auto Bezier for every key frame
for (var i=1; i<=pos.numKeys; i++){
pos.setSpatialAutoBezierAtKey(i, true);
}

//create new shape add copy to it all text 's motion path properties
s = new Shape();

s.closed = shape.value.closed;

var vert = [];
var inTang = [];
var outTang = [];
for (var i=1; i<=pos.numKeys; i++){
vert.push([pos.keyValue(i)[0], pos.keyValue(i)[1]]);
inTang.push([pos.keyInSpatialTangent(i)[0], pos.keyInSpatialTangent(i)[1]]);
outTang.push([pos.keyOutSpatialTangent(i)[0], pos.keyOutSpatialTangent(i)[1]]);
}

s.vertices = vert;
s.inTangents = inTang;
s.outTangents = outTang;

//assign shape to the original shape property
shape.setValue(s);
//delete Dummy comp
comp.remove();
}

//recursive function to look for selected shape properties;
function selectedShapeSearch(thePropertyGroup){
for (var i=1; i<=thePropertyGroup.numProperties; i++){
currentProperty = thePropertyGroup.property(i);

//checking, if it's a property and not a property group
if (currentProperty.propertyType == PropertyType.PROPERTY){
//checking, if it's a shape property
if (currentProperty.propertyValueType == PropertyValueType.SHAPE){
//checking, if it is selected
if (currentProperty.selected){
shapeSmoother(currentProperty);
}
}
}
else{
selectedShapeSearch(currentProperty);
}
}
}

function main(){
var prj = app.project;

//searching in every comp...
for (i=1; i<=prj.numItems; i++){
if (prj.item(i).typeName == "Composition"){
currentComp = prj.item(i);

//...and in every layer
for (j=1; j<=currentComp.layers.length; j++){
selectedShapeSearch(currentComp.layer(j));
}
}
}

}

main();


Posts IndexRead Thread 


Current Message Thread:





© 2020 CreativeCOW.net All Rights Reserved
[TOP]