Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Bulk convert expressions (source text & scale) into keyframes

  • Bulk convert expressions (source text & scale) into keyframes

    Posted by Joerg Brueggemann on November 5, 2014 at 4:11 pm

    Hi there,

    I generate 100+ Comps from a spreadsheet (https://aescripts.com/compsfromspreadsheet/ – great script, works like a charm) and need to convert an rather heavy expression afterwards to save time while rendering.

    I have already found a solution to a very similar problem here in this forum –> https://forums.creativecow.net/thread/227/13039#13041

    I tried do edit the script to my needs, but I doesn’t convert the expressions in the selected comps.


    var items = app.project.items;
    var selectedComps = new Array();

    function convertToKeyframes(theProperty){
    if (theProperty.canSetExpression && theProperty.expressionEnabled){
    theProperty.selected = true;
    app.executeCommand(app.findMenuCommandId("Convert Expression to Keyframes"));
    theProperty.selected = false;
    }
    }

    for (var i = 1; i <= items.length; i++) {
    if ((items[i] instanceof CompItem) && items[i].selected) {
    selectedComps[i] = items[i];
    }
    }

    for (var i = 1; i <= selectedComps.length; i++) {
    var comp = selectedComps[i];
    if (!comp) continue;

    var layer = comp.layer(2);
    var prop = layer.property("scale");
    convertToKeyframes(prop);

    layer = comp.layer(1);
    prop = layer.property("sourceText");
    convertToKeyframes(prop);

    }

    What am I doing?
    As said, I have 100+ Comps I select in the project panel. Inside each are two text-layers. One with an expression for source code and one with an expression in the scale property.

    I use this approach (https://motionboutique.com/text-bounds-expresssion-580/) to get the bounding box of the text in layer 2. This is the first expression to be converted. (the script is inside the source text)
    The second layer is also a text layer, it got its text from the spreadsheet. It uses the result from layer 1 in the scale expression to make sure, the size of the textbox doesn’t exceed the “maxwidth” I defined.

    I’m rather useless with code and had help from our programmer, but he doesn’t know anything about AE. He used the ExtendedToolKit to debug and everything we checked had the expected value/outcome. Only there were no expressions converted to keyframes.

    Now I am hoping one of you guys could help me find out why, and maybe even fix it.

    regards,
    Joerg

    Joerg Brueggemann replied 11 years, 6 months ago 2 Members · 4 Replies
  • 4 Replies
  • Joerg Brueggemann

    November 5, 2014 at 11:59 pm

    I maybe should have mentioned, that I’m using CS6 (on Win7x64). Doesn’t know, if thats important.

    I kept on trying, but the script just doesn’t work…without prompting any errors. But there must be an error, I just can’t find it…

  • Dan Ebberts

    November 6, 2014 at 1:48 am

    After this line:

    if (!comp) continue;

    try adding this one:

    comp.openInViewer();

    Dan

  • Joerg Brueggemann

    November 6, 2014 at 9:00 am

    Hi Dan,
    Thank you for your reply. I’ve seen your anwers in many posts here and were hoping you would find time to read through my post. Thanks for that.

    I paste the current state of the script again. I filled in an commandId since I have english AE at work in the german version in my home office.

    Your additional line brings me at least one step closer. After running the script, now the comps are all opened and in every comp the two layers are highlighted. But the “convert expression to keyframes” is still not happening.

    Without your line, sometimes (most of the times, but not always – i’m working in a test project now, with only one two layer comp, duplicated four times.) the conversion will work only for the active comp in the viewer. So I have seen, that the function in general does its job. The error must be in the orders I give to work through my selection.

    I am still not able to see why its not running. Further testing didn’t help either.

    Why is the conversion not executed?

    var items = app.project.items;
    var selectedComps = new Array();

    function convertToKeyframes(theProperty){
    if (theProperty.canSetExpression && theProperty.expressionEnabled){
    theProperty.selected = true;
    app.executeCommand(2639);
    theProperty.selected = false;
    }
    }

    for (var i = 1; i <= items.length; i++) { if ((items[i] instanceof CompItem) && items[i].selected) { selectedComps[i] = items[i]; } } for (var i = 1; i <= selectedComps.length; i++) { var comp = selectedComps[i]; if (!comp) continue; comp.openInViewer(); var layer = comp.layer(2); var prop = layer.property("scale"); convertToKeyframes(prop); layer = comp.layer(1); prop = layer.property("sourceText"); convertToKeyframes(prop); }

  • Joerg Brueggemann

    November 6, 2014 at 10:28 am

    pff…

    just tried again, with no changes. Now its working. Dunno if I’m stupid…

    Since it seems to be fine now, for everyone finding this with a similar task. You can change, which layer number and wich property is converted with the three-line-blocks at the end of the script. (But before the final closing bracket)

    var layer = comp.layer(2);
    var prop = layer.property("scale");
    convertToKeyframes(prop);

    You need one of these for every layer and property you want to convert. Just fill in the layer number (counted from top top bottom) and the property you want to have converted. If the 3rd Layer has a position expression you want to convert, it would look like this.

    var layer = comp.layer(3);
    var prop = layer.property("position");
    convertToKeyframes(prop);

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy