ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Script - Reference Comp by name instead of by index

COW Forums : Adobe After Effects

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Tiago Cav
Script - Reference Comp by name instead of by index
on Jun 25, 2015 at 8:31:32 am
Last Edited By Tiago Cav on Jun 25, 2015 at 8:32:19 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.


    Return to posts index


    Walter Soyka
    Re: Script - Reference Comp by name instead of by index
    on Jun 25, 2015 at 12:21:35 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 [twitter]   |   RenderBreak [blog]   |   Profile [LinkedIn]


    Return to posts index

    Tiago Cav
    Re: Script - Reference Comp by name instead of by index
    on Jun 25, 2015 at 7:25:31 pm

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

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

    Thanks.


    Return to posts index



    Walter Soyka
    Re: Script - Reference Comp by name instead of by index
    on Jun 27, 2015 at 11:02:57 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 [twitter]   |   RenderBreak [blog]   |   Profile [LinkedIn]


    Return to posts index

    Tiago Cav
    Re: Script - Reference Comp by name instead of by index
    on Jun 27, 2015 at 11:08:53 am

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


    Return to posts index

    Walter Soyka
    Re: Script - Reference Comp by name instead of by index
    on Jun 27, 2015 at 11:21:50 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 [twitter]   |   RenderBreak [blog]   |   Profile [LinkedIn]


    Return to posts index


    Tiago Cav
    Re: Script - Reference Comp by name instead of by index
    on Jun 27, 2015 at 11:27:01 am
    Last Edited By Tiago Cav on Jun 27, 2015 at 11:27:39 am

    Very good!
    Thank you very much! :)


    Return to posts index

    Tiago Cav
    Re: Script - Reference Comp by name instead of by index
    on Jun 28, 2015 at 1:36:14 am
    Last Edited By Tiago Cav on Jun 28, 2015 at 1:37:00 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.


    Return to posts index

    Tiago Cav
    Re: Script - Reference Comp by name instead of by index
    on Jun 28, 2015 at 2:40:15 am
    Last Edited By Tiago Cav on Jun 29, 2015 at 3:50:46 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. :)


    Return to posts index

    << PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
    © 2017 CreativeCOW.net All Rights Reserved
    [TOP]