Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects [ExtendScript] Get the index of a new item

  • [ExtendScript] Get the index of a new item

    Posted by Charlie Leroy on October 23, 2014 at 7:47 pm

    Hello guys,

    I have been looking for some time a way to get the index of an item if I know its name.

    In my scene I have one main comp and several subcomp
    What I want to do is:

    Duplcate all the comp and once that is done, replace the old subcomp by the new one.

    But I did not find a way to retrieve the index for the created subcomps.
    I have to use :
    items.[x].layer(“name”).replace()
    but dont know how to find x for the created comps.

    Maybe there is another way of doing, using ID or Name insted of the item index but I can not find it.

    any idea of how to do that?

    thanks!

    Ryan Mcadam replied 10 years, 2 months ago 2 Members · 1 Reply
  • 1 Reply
  • Ryan Mcadam

    March 15, 2016 at 3:38 pm

    I realize this answer is a bit late but here is a function written to find the index of an item among the items collection by name. In other words it will find and return the index of an item from among all the other items in your project panel. Not sure if this is what you were looking for. Hope it helps.

    // Find the index of an item in the items collection by name
    function findItemIndexByName(searchName)
    {
    var projLength = app.project.items.length;
    var index = null;

    for (var i = 1; i <= projLength; i++)
    {
    var nameProperty = app.project.item(i).name;
    if ( nameProperty == searchName)
    {
    index = i;
    break;
    }
    }
    return index;
    }

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