-
Bake expressions of a specific property for all layers inside selected comps
Hi,
I have been trying to modify a script made by Dan, which I found here on the forum. The original would check a defined number of properties and bake expressions, if any were found. It would cycle through all layers of an active comp. What I am trying to do is to have a script do the same thing, but for multiple comps. The property I am interested in is the Source Text property.
I’ll paste the edited code below: I had to do some reverse engineering and I added a lot of comments. It is my first try with a script and I had to wrap my head around the code. As of now, it works with only the active comp, but it targets the proper property.
I was thinking of storing the selection, begin a for loop through such selection (which should be an array) and use the exact same code for each item of the array.
Any suggestion on how to store such selection? I tried to do:
var selection = app.project.selection
but I can’t seem to make it work.Here is the code:
// Define function
function convertToKeyframes(theProperty){
if (theProperty.canSetExpression && theProperty.expressionEnabled){
theProperty.selected = true;
app.executeCommand(app.findMenuCommandId("Convert Expression to Keyframes"));
theProperty.selected = false;
}
}// Store the selected comp:
// It can either be selected in the "Project" tab or in the timeline
// If a layer is selected, the method returns the comp to which the layer belongs
var myComp = app.project.activeItem;// ----- debug print
//$.write();
//$.write(myComp instanceof CompItem);// Check if something is selected and if selection it is a Composition
if (myComp && myComp instanceof CompItem){
var myLayer;
var myProperty;// Wraps everything that follows in a single Undo step
app.beginUndoGroup("convert expressions");// The for loop is used to access every layer in the comp using its index
for (var i = 1; i <= myComp.numLayers; i++){
myLayer = myComp.layer(i);// If the layer has the property, invoke the function with the property as input
try{
myProperty = myLayer.property("sourceText");
convertToKeyframes(myProperty);
}catch(err){
}}
app.endUndoGroup();
}Thanks!