Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Script to reference a specific comp (not selected comp)

  • Script to reference a specific comp (not selected comp)

    Posted by Colin Love on October 14, 2013 at 10:53 pm

    I know this is a noob question, but I want to select a specific comp and layer using its name.
    I don’t need the script to be universal/portable in any way.

    All the examples of scripts I can find are based on selected comps.

    I need to add key frames to one comp based on values of other key frames in another comp.

    Dan Ebberts replied 11 years, 5 months ago 3 Members · 5 Replies
  • 5 Replies
  • Dan Ebberts

    October 15, 2013 at 2:46 pm

    There’s no way to do it by name directly. You have to loop through the items in the project bin looking for a CompItem with a name that matches the name you’re looking for (not tested, but should be close):


    var myComp = null; // assume the worst
    for (var i = 1; i <= app.project.numItems; i++){
    if ((app.project.item(i).name == "your comp name") && (app.project.item(i) instanceof CompItem)){
    myComp = app.project.item(i);
    break;
    }
    }
    if (myComp != null){

    etc.

  • Andy Mason

    March 23, 2015 at 8:56 pm

    Hey Dan, is there a way to do this but to only compare against the suffix of the comp’s name? I know that in string methods you can use -4 to look at only the last four characters of the string, but is it possible to do something similar with an item’s name?

  • Dan Ebberts

    March 23, 2015 at 10:54 pm

    yourComp.name.substr(-4) should work.

    Dan

  • Andy Mason

    March 24, 2015 at 5:51 am

    Ah, thanks, of course… it’s so obvious, ha ha.

    Can you use most of the same methods on names as you would use on strings, like slice, concat, to upper case… all those goodies?

    Also another string related but not very related question here. If you create a UI for after effects that has an edit text field, is the data returned a string? I tried to use one and was having weird troubles when I tried to split the string.

  • Dan Ebberts

    March 24, 2015 at 6:01 am

    >is the data returned a string?

    The .text attribute of the editText object is a string.

    Dan

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