Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Script – Reference Comp by name instead of by index

  • Script – Reference Comp by name instead of by index

    Posted by Tiago Cav on June 25, 2015 at 8:31 am

    I have this Script:

    var myComp = app.project.activeItem;
    var myLayer = app.project.item(4).layer(1);
    myComp.duration = (myLayer.outPoint - myLayer.inPoint);

    This script changes the duration of the main composition, based on the way I made reference by index.

    Instead of use: app.project.item(4).layer(1); The path is: (4) Fourth Comp inside Main composition and within, the (1) first layer.

    I made several unsuccessful attempts. It’s not like in expressions.

    I need to use names. Which are independent of the numerical order of layers within the composition.

  • With these names:
  • (4) = “Footage”
  • (1) = “Video”
  • Thanks.

Tiago Cav replied 10 years, 10 months ago 2 Members · 8 Replies
  • 8 Replies
    • Walter Soyka

      June 25, 2015 at 12:21 pm

      You could iterate through all the layers in the comp, looking at their names to see if they’re the one you want.

      Also,

      [Tiago Cav] “app.project.item(4).layer(1);
      The path is: (4) Fourth Comp inside Main composition and within, the (1) first layer.”

      app.project.item(4) refers to the fourth item in the project panel, not the fourth layer in your active item.

      Walter Soyka
      Designer & Mad Scientist at Keen Live [link]
      Motion Graphics, Widescreen Events, Presentation Design, and Consulting
      @keenlive   |   RenderBreak [blog]   |   Profile [LinkedIn]

    • Tiago Cav

      June 25, 2015 at 7:25 pm

      How to refers to the fourth layer in my active item?

      And upon the indexing, can not be made references by name?

      Thanks.

    • Walter Soyka

      June 27, 2015 at 11:02 am

      Layers within a comp can be identified by name. Items within a project cannot.

      Starting with your code above:

      footageLayer = myComp.layer("Footage");

      Walter Soyka
      Designer & Mad Scientist at Keen Live [link]
      Motion Graphics, Widescreen Events, Presentation Design, and Consulting
      @keenlive   |   RenderBreak [blog]   |   Profile [LinkedIn]

    • Tiago Cav

      June 27, 2015 at 11:08 am

      I understand. How to access layers in Composition selected or specific Comp instead of the composition on project panel?

    • Walter Soyka

      June 27, 2015 at 11:21 am

      myComp = app.project.activeItem;
      footageLayer = myComp.layer("Footage");
      footageComp = footageLayer.source;

      Note that I’m not doing any error checking in the above. This will fail if you have no layer named “Footage” or if there is a footage layer which does not have a source. Note too that this script does not guarantee that footageComp is actually a comp; if you have a layer named “Footage” whose source is a file, footageComp will actually be an instance of FootageItem, not CompItem.

      Your code should fail gracefully if these conditions are not met, so you need to check what’s returned at each step to make sure it meets your assumptions.

      Walter Soyka
      Designer & Mad Scientist at Keen Live [link]
      Motion Graphics, Widescreen Events, Presentation Design, and Consulting
      @keenlive   |   RenderBreak [blog]   |   Profile [LinkedIn]

    • Tiago Cav

      June 27, 2015 at 11:27 am

      Very good!
      Thank you very much! 🙂

    • Tiago Cav

      June 28, 2015 at 1:36 am

      Just a more thing, please.

      I want to to access a layer (Footage) which is inside of Comp (A) and Comp (A) is within Main Comp (app.project.activeItem;)

      That is, use a layer which is inside of a Comp, that is into other Comp, in Script.

      I only got it, through Project Panel with: app.project.item;
      And cannot by Comp Selected: app.project.activeItem;

      Thanks.

    • Tiago Cav

      June 28, 2015 at 2:40 am

      Example:
      var myComp = app.project.activeItem;
      var myLayer = myComp.layer("Footage").source.layer("Video");
      myComp.duration = (myLayer.outPoint - myLayer.inPoint);

    • I said:
    • Is there any way to use names instead of index in Script?
      Oh yeah! I got use names in Script using: “.source”.

    • I said too:
    • How to access layers in composition selected instead of the composition on project panel?

      Also I got through “activeItem”.

      Thanks. 🙂

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