-
Script for Precomping Text
I’m trying to write a script to precomp text layers, with the precomp being the size of the text bounding box, just as you can do with source layers (“Leave all attributes”). I found -this script binary- but it was written 13 years ago and doesn’t quite work right now. Its problems are the same as the problems I’m running into as I try to recreate the script, which is that the text transforms within the new comp should be default and centered, and the new precomp’s transforms should match the text’s, but are default. I can’t seem to get a grasp of transforms in scripting, can only get the return [object global]. Here’s what I have currently, which makes a new comp from the text later and copies the text into it:
// Check if there is a project open
if (app.project) {
// Get the active composition
var comp = app.project.activeItem;
// Check if the active item is a composition
if (comp && comp instanceof CompItem) {
// Get the selected layer
var selectedLayer = comp.selectedLayers[0];
// Check if there is a selected layer
if (selectedLayer) {
// Create a new composition with the dimensions of the selected layer
var layerTransf = selectedLayer.property("ADBE Transform Group");
var layerPos = selectedLayer.property("ADBE Transform Group").property("ADBE Position");
var newComp = app.project.items.addComp(selectedLayer.name, Math.round(selectedLayer.sourceRectAtTime(0, true).width), Math.round(selectedLayer.sourceRectAtTime(0, true).height), comp.pixelAspect, comp.duration, comp.frameRate);
// Copy the selected layer to the new composition
var newLayer = comp.layer(selectedLayer.name).copyToComp(newComp);
// Reset transforms of layer in new composition
// newLayer.position.setValue([newComp.width / 2, newComp.height / 2]);
// newLayer.scale.setValue([100, 100]);
// newLayer.rotation.setValue([0]);
// newLayer.Transform.setValue(layerTransf);
} else {
alert("Please select a layer.");
}
} else {
alert("Please open a composition.");
}
} else {
alert("Please open a project.");
}
I’m still trying to figure out how to set the transforms of the new text layer and new precomp, so any help would be greatly appreciated by this newbie 🙏
aescripts.com
Smart Precomposer allows you to do a "precompose and leave all attributes" on text and shape layers, which After Effects otherwise doesn't allow. What's more, Smart Precomposer allows you to precompose any type of layer and selectively move some attributes … Continue reading
